chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑

This commit is contained in:
hugo committed 2026-08-17 19:56:51 +08:00
1 parent 5ef8329bd8
commit 4ec4e57005
183 files changed
+14653 -3936

No files matched your search

@@ -18,6 +18,8 @@ const i18n = createI18n({
line: '第 {index} 行',
buildEligibility: {
overallResult: '整单结果', canBuildYes: '可建单', canBuildNo: '待处理',
manualBuildLabel: '人工建单', autoBuildLabel: '自动建单',
autoBuildYes: '可自动建单', autoBuildNo: '暂不可自动建单',
manualConfirmOnly: '需人工确认', blockReasons: { unknown: '未知阻断' },
routingStatus: { unknown: '未知' },
},
@@ -40,6 +42,49 @@ const eligibility = {
};
describe('ReviewBuildEligibilityDetailsDrawer', () => {
it('separates manual buildability from automatic creation eligibility', () => {
const wrapper = mount(ReviewBuildEligibilityDetailsDrawer, {
props: {
open: true,
eligibility: {
can_build: true,
can_auto_create: false,
status: 'ready',
failed_gates: ['field_conflicts_resolved'],
issues: [],
line_projections: [],
},
},
global: { plugins: [i18n] },
});
// 关键断言:抽屉不能只写“可建单”而让自动门禁失败看似矛盾。
expect(wrapper.find('[data-testid="review-eligibility-manual-status"]').text()).toContain('可建单');
expect(wrapper.find('[data-testid="review-eligibility-auto-status"]').text()).toContain('暂不可自动建单');
});
it('does not render an empty diagnostic section when there are no diagnostic facts', () => {
const wrapper = mount(ReviewBuildEligibilityDetailsDrawer, {
props: {
open: true,
eligibility: {
can_build: true,
can_auto_create: false,
status: 'ready',
issues: [],
failed_gates: [],
assessment: { missing_required_fields: [] },
line_projections: [{ line_key: 'L1', line_index: 0, can_build: true }],
},
fieldConflicts: [],
},
global: { plugins: [i18n] },
});
// 关键断言:没有问题明细时不能留下无内容的边框占位区。
expect(wrapper.findAll('section')).toHaveLength(1);
});
it('lists the exact conflicting field, line, sources and values', () => {
const wrapper = mount(ReviewBuildEligibilityDetailsDrawer, {
props: {
@@ -134,6 +134,15 @@ const unexplainedBlocked = computed(() => Boolean(
&& !props.eligibility.assessment?.missing_required_fields?.length
&& !(props.eligibility.line_projections || []).some((line) => line.can_build === false),
));
/** 有可解释的诊断事实时才渲染中段,避免通过订单留下空白占位框。 */
const hasDiagnosticDetails = computed(() => Boolean(
props.eligibility?.assessment?.missing_required_fields?.length
|| nonConflictIssues.value.length
|| unexplainedBlocked.value
|| props.fieldConflicts?.length
|| hasFieldConflictIssue.value
));
</script>
<template>
@@ -163,12 +172,27 @@ const unexplainedBlocked = computed(() => Boolean(
: 'border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-100'"
data-testid="review-eligibility-details-overall"
>
<div class="flex items-center justify-between gap-2">
<div class="flex flex-wrap items-center justify-between gap-2">
<span class="font-semibold">{{ t('chat.shippingOrderReview.buildEligibility.overallResult') }}</span>
<span class="text-slate-600 dark:text-slate-300">{{ t('chat.shippingOrderReview.buildEligibility.manualBuildLabel') }}</span>
<span class="rounded-full px-2 py-0.5 font-medium" :class="eligibility.can_build ? 'bg-emerald-100 text-emerald-800 dark:bg-emerald-900/60 dark:text-emerald-100' : 'bg-amber-100 text-amber-900 dark:bg-amber-900/60 dark:text-amber-100'">
{{ eligibility.can_build
<span data-testid="review-eligibility-manual-status">{{ eligibility.can_build
? t('chat.shippingOrderReview.buildEligibility.canBuildYes')
: t('chat.shippingOrderReview.buildEligibility.canBuildNo') }}
: t('chat.shippingOrderReview.buildEligibility.canBuildNo') }}</span>
</span>
</div>
<div class="mt-2 flex flex-wrap items-center justify-between gap-2">
<span class="text-slate-600 dark:text-slate-300">{{ t('chat.shippingOrderReview.buildEligibility.autoBuildLabel') }}</span>
<span
class="rounded-full px-2 py-0.5 font-medium"
:class="eligibility.can_auto_create
? 'bg-emerald-100 text-emerald-800 dark:bg-emerald-900/60 dark:text-emerald-100'
: 'bg-amber-100 text-amber-900 dark:bg-amber-900/60 dark:text-amber-100'"
data-testid="review-eligibility-auto-status"
>
{{ eligibility.can_auto_create
? t('chat.shippingOrderReview.buildEligibility.autoBuildYes')
: t('chat.shippingOrderReview.buildEligibility.autoBuildNo') }}
</span>
</div>
<p v-if="eligibility.can_build && eligibility.can_auto_create === false" class="mt-1">
@@ -183,7 +207,10 @@ const unexplainedBlocked = computed(() => Boolean(
</ul>
</div>
</section>
<section class="rounded-lg border border-slate-200 bg-slate-50 p-3 text-xs dark:border-slate-700 dark:bg-slate-950/40">
<section
v-if="hasDiagnosticDetails"
class="rounded-lg border border-slate-200 bg-slate-50 p-3 text-xs dark:border-slate-700 dark:bg-slate-950/40"
>
<div v-if="eligibility.assessment?.missing_required_fields?.length" class="mt-2">
<div class="font-medium">{{ t('chat.shippingOrderReview.workbench.requiredFields') }}</div>
<div class="mt-1 text-rose-700 dark:text-rose-300">
@@ -165,8 +165,8 @@ describe('ReviewBuildEligibilitySummary', () => {
expect(wrapper.text()).not.toContain('can_auto_create');
});
it('hides primary-block under focusBuildability for inventory combo (UI-03)', () => {
// 关键断言:库存阻断由 Gate 卡表达时,资格摘要不得再输出首要阻断标题。
it('keeps primary-block under focusBuildability for inventory combo (UI-03)', () => {
// 关键断言:当前任务卡只承载动作,资格摘要仍保留库存门禁的具体解释。
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
@@ -218,13 +218,14 @@ describe('ReviewBuildEligibilitySummary', () => {
global: { plugins: [i18n] },
});
expect(wrapper.find('[data-testid="review-build-eligibility-summary"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="review-eligibility-primary-block"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="review-eligibility-gate-checklist"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="review-eligibility-primary-block"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="review-eligibility-gate-checklist"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="review-exception-nav"]').exists()).toBe(true);
});
it('hides primary-block under focusBuildability for field completeness combo (UI-03)', () => {
// 关键断言:字段阻断组合态下资格卡只保留摘要与异常导航,不输出第二份首要阻断。
it('keeps concrete missing-field diagnostics visible under focusBuildability (UI-03)', () => {
// 关键断言:当前任务卡只承载动作;建单资格卡仍必须给出缺失字段和首要阻断,
// 否则用户无法从泛化 Gate 文案定位订单明细问题。
const wrapper = mount(ReviewBuildEligibilitySummary, {
props: {
eligibility: {
@@ -280,11 +281,13 @@ describe('ReviewBuildEligibilitySummary', () => {
})],
},
});
expect(wrapper.find('[data-testid="review-eligibility-primary-block"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="review-eligibility-primary-block"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="review-eligibility-gate-checklist"]').exists()).toBe(true);
expect(wrapper.text()).toContain('缺失必填:PO');
});
it('hides primary-block when technical_auto_only leaves business gate inactive (UI-03)', () => {
// 关键断言:仅技术 Gate pending 时 focusBuildability=false,资格卡可展示阻断;本测验证开启 focus 时仍唯一。
it('keeps passing eligibility concise when focusBuildability is enabled (UI-03)', () => {
// 关键断言:无阻断时不额外渲染首要阻断;focusBuildability 不影响资格事实展示。
const wrapper = mount(ReviewBuildEligibilitySummary, {
props: {
eligibility: {
@@ -21,8 +21,8 @@ const props = defineProps<{
/** 当前定位异常序号;未定位时为 0。 */
exceptionOrdinal?: number;
/**
* 为 true 时只展示能否建单/自动建单与异常导航,隐藏门禁清单与首要阻断文案,
* 避免与 ProcessGateRecoveryCard 重复表达同一业务阻断。
* 兼容旧调用方的展示偏好。当前任务卡只承载动作,建单门禁仍须完整展示,
* 因此该参数不再隐藏字段级诊断,避免用户只能看到泛化阻断原因。
*/
focusBuildability?: boolean;
}>();
@@ -233,7 +233,7 @@ const gateChecklist = computed(() => {
{{ t('chat.shippingOrderReview.buildEligibility.manualConfirmOnly') }}
</p>
<ul
v-if="!focusBuildability && gateChecklist.length"
v-if="gateChecklist.length"
class="mt-2 space-y-1 text-xs"
data-testid="review-eligibility-gate-checklist"
>
@@ -285,7 +285,7 @@ const gateChecklist = computed(() => {
<p v-if="conflictFields.length"><span class="font-semibold">{{ t('chat.shippingOrderReview.workbench.conflictFields') }}:</span>{{ [...new Set(conflictFields)].join('、') }}</p>
</div>
<div
v-if="!focusBuildability && lowConfidenceFields.length"
v-if="lowConfidenceFields.length"
class="mt-2 rounded-lg border border-amber-200 bg-amber-50 px-2.5 py-2 text-xs text-amber-950 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-100"
data-testid="review-low-confidence-fields"
>
@@ -298,7 +298,7 @@ const gateChecklist = computed(() => {
</div>
<div
v-if="!focusBuildability && !eligibility.can_build && primaryBlockMessage"
v-if="!eligibility.can_build && primaryBlockMessage"
class="mt-2 rounded-lg border border-amber-200 bg-amber-50 px-2.5 py-2 text-xs text-amber-950 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-100"
data-testid="review-eligibility-primary-block"
>
@@ -15,6 +15,32 @@ const i18n = createI18n({
messages: {
'zh-CN': {
'chat.shippingOrderReview.processGate.actionCodes.retry_inventory_matching': '重新库存匹配',
workspace: {
shippingNotice: {
processGate: {
reasons: {
inventory_shortage_review_required: '存在库存缺口,需要人工处理',
},
},
},
},
chat: {
shippingOrderReview: {
saveOrderAndValidate: '保存订单并校验',
currentProcessing: {
waitingStart: '等待系统启动',
},
currentTask: {
statusRunning: '系统处理中',
nextStepWaitingExternal: '等待外部系统回执,暂不需要人工操作',
},
},
shippingProcessing: {
gateReasons: {
generic: '当前步骤需要人工处理',
},
},
},
},
},
});
@@ -44,6 +70,20 @@ describe('ReviewCurrentProcessingCard', () => {
expect(wrapper.find('[data-testid="review-current-processing-retry"]').exists()).toBe(true);
});
it('hides the order-review entry when the user is already in the lifecycle workbench', () => {
const wrapper = mount(ReviewCurrentProcessingCard, {
props: {
stageCode: 'order_review',
userStatus: 'waiting_human',
primaryAction: { code: 'open_order_review', i18nKey: 'chat.shippingProcessing.action.open_order_review' },
},
global: { plugins: [i18n] },
});
// 批次中心可以用它进入工作台;工作台当前阶段不能再显示同一个自跳转入口。
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
});
it('renders Gate label_key for every primary action presentation', () => {
const wrapper = mount(ReviewCurrentProcessingCard, {
props: {
@@ -60,13 +100,87 @@ describe('ReviewCurrentProcessingCard', () => {
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').text()).toBe('重新库存匹配');
});
it('does not render save and validate as a current-task action', () => {
const wrapper = mount(ReviewCurrentProcessingCard, {
props: {
stageCode: 'order_review',
userStatus: 'waiting_human',
},
global: { plugins: [i18n] },
});
// 保存订单并校验是底栏唯一动作;未提交校验必须给出明确交接提示,不能显示系统处理中。
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
expect(wrapper.get('[data-testid="review-current-task-next-step-text"]').text()).toBe('保存订单并校验');
});
it('labels an unqueued automatic Gate as waiting for system start', () => {
const wrapper = mount(ReviewCurrentProcessingCard, {
props: {
stageCode: 'fulfillment_prep',
userStatus: 'running',
gateStatus: 'pending',
},
global: { plugins: [i18n] },
});
expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toContain('等待系统启动');
});
it('explains external wait without calling it generic system processing', () => {
const wrapper = mount(ReviewCurrentProcessingCard, {
props: {
stageCode: 'upload_complete',
userStatus: 'running',
gateStatus: 'waiting_external',
},
global: { plugins: [i18n] },
});
expect(wrapper.get('[data-testid="review-current-task-next-step-text"]').text())
.toBe('等待外部系统回执,暂不需要人工操作');
});
it('never exposes an internal action code when its presentation is absent', () => {
const wrapper = mount(ReviewCurrentProcessingCard, {
props: {
stageCode: 'order_review',
userStatus: 'waiting_human',
primaryAction: { code: 'edit_draft' },
},
global: { plugins: [i18n] },
});
// 回退显示 edit_draft 会泄漏内部能力码;必须 fail-closed 隐藏。
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
expect(wrapper.text()).not.toContain('edit_draft');
});
it('renders a localized reason instead of an internal blocking code in the next step', () => {
const wrapper = mount(ReviewCurrentProcessingCard, {
props: {
stageCode: 'inventory_matching',
userStatus: 'waiting_human',
blockingReason: { code: 'inventory_shortage_review_required' },
},
global: { plugins: [i18n] },
});
const nextStep = wrapper.get('[data-testid="review-current-task-next-step-text"]').text();
expect(nextStep).toBe('存在库存缺口,需要人工处理');
expect(nextStep).not.toContain('inventory_shortage_review_required');
});
it('renders server-provided recovery actions without duplicating the primary action', async () => {
const wrapper = mount(ReviewCurrentProcessingCard, {
props: {
stageCode: 'inventory_matching',
userStatus: 'waiting_human',
primaryAction: { code: 'retry_inventory_matching', i18nKey: 'retry_inventory_matching' },
recoveryActions: [{ code: 'retry_inventory_from_preparation' }],
recoveryActions: [{
code: 'retry_inventory_from_preparation',
i18nKey: 'chat.shippingOrderReview.processGate.actionCodes.retry_inventory_matching',
}],
},
global: { plugins: [i18n] },
});
@@ -15,6 +15,8 @@ import type {
ShippingProcessingPrimaryAction,
} from '@/features/chat/types/shipping.api.types';
import { resolveShippingProcessingStageLabel } from '@/features/chat/shipping/shippingProcessingLabels';
import { resolveGateReasonLabel } from '@/features/shipping-progress/gateReasonLabel';
import { lookupWorkbenchAction, shouldRenderWorkbenchAction } from '@/features/shipping-progress/workbenchActionRegistry';
const props = defineProps<{
stageCode?: string | null;
@@ -41,6 +43,8 @@ const props = defineProps<{
label_key?: string | null;
parameters?: Record<string, unknown>;
}>;
/** 正式 Gate 原始状态仅用于区分未入队、运行中与外部回执等待;不参与按钮裁决。 */
gateStatus?: string | null;
taskMissing?: boolean;
confirmedTaskId?: number | null;
@@ -103,12 +107,16 @@ const statusLabel = computed(() => {
if (props.taskMissing) {
return t('chat.shippingOrderReview.currentProcessing.taskMissing');
}
if (s === 'running' && String(props.gateStatus || '').trim().toLowerCase() === 'pending') {
return t('chat.shippingOrderReview.currentProcessing.waitingStart');
}
if (!s) return t('chat.shippingOrderReview.currentProcessing.statusIdle');
return map[s] ?? t('chat.shippingOrderReview.currentProcessing.statusIdle');
});
/**
* 下一步(「下一步」section 的问题/说明文案):优先展示 blocking_reason,否则按 user_status 给系统态文案。
* 下一步(「下一步」section 的问题/说明文案):优先展示 blocking_reason 的统一 i18n 映射,
* 否则按 user_status 给系统态文案;禁止将后端内部原因码直接展示给用户。
*/
const nextStepText = computed(() => {
const safeMessage = (value: unknown): string => {
@@ -136,8 +144,27 @@ const nextStepText = computed(() => {
if (i18nKey && te(i18nKey)) {
return t(i18nKey);
}
// i18n 键缺失时回落为 code(不裸露给普通用户,最终 QA 期间应全部补齐)
return safeMessage(br.code) || t('chat.shippingOrderReview.currentTask.nextStepUnknown');
return resolveGateReasonLabel(br.code, { t, te })
|| t('chat.shippingOrderReview.currentTask.nextStepUnknown');
}
// 建单前订单冻结校验尚未提交时,明确告诉用户下一步是保存并校验。
// 保存是底栏唯一的表单提交入口,不升级为右栏 CTA;该分支也兼容历史响应
// 仍携带 validate 的情形,避免「待人工」与「无需操作」产生语义矛盾。
if (
String(props.stageCode || '').trim() === 'order_review'
&& !props.blockingReason
&& (
String(props.primaryAction?.code || '').trim() === 'validate'
|| String(props.userStatus || '').trim() === 'waiting_human'
)
) {
return t('chat.shippingOrderReview.saveOrderAndValidate');
}
if (
String(props.userStatus || '').trim() === 'running'
&& String(props.gateStatus || '').trim().toLowerCase() === 'waiting_external'
) {
return t('chat.shippingOrderReview.currentTask.nextStepWaitingExternal');
}
// 2) 无阻断时,按 user_status 给系统说明文案
const s = String(props.userStatus || '').trim() as ReviewCurrentUserStatus | '';
@@ -168,9 +195,33 @@ const showNextStep = computed(() => {
return !['completed', 'cancelled'].includes(status);
});
/**
* 判断当前工作台是否应隐藏后端下发的纯导航动作。
* 批次中心可用它打开工作台;进入工作台后必须复用注册表规则,避免当前阶段再次显示
* 「进入订单复核」或「编辑正式任务」等自跳转入口。
*/
function isHiddenWorkbenchNavigationAction(code: string): boolean {
const entry = lookupWorkbenchAction(code);
return Boolean(entry && !shouldRenderWorkbenchAction(entry, {
actionsExecutable: true,
surface: 'review',
actionCode: code,
}));
}
/**
* 当前任务卡只承载正式 Gate 的可执行业务动作。
*
* 草稿编辑/建草稿是页面能力,保存校验是底栏唯一提交;它们即使出现在历史响应中,
* 也不能升级为右栏 CTA,更不能因缺失文案泄漏内部动作码。
*/
function isNonTaskCapabilityAction(code: string): boolean {
return new Set(['edit_draft', 'create_draft', 'validate']).has(code.trim().toLowerCase());
}
/**
* 业务动作按钮:后端确认 retryable=true → 主按钮为「重试」;
* 否则若 primary_action.code 非 retry → 用 primary_action.code + i18n_key 渲染对应人工动作(进入复核/确认客户等)。
* 否则若 primary_action.code 非 retry 且不是工作台内自跳转 → 渲染对应人工动作。
*/
const showBusinessAction = computed(() => {
if (props.loading) return false;
@@ -181,6 +232,8 @@ const showBusinessAction = computed(() => {
if (props.retryable) return true;
const code = String(props.primaryAction?.code || '').trim();
if (!code) return false;
if (isNonTaskCapabilityAction(code)) return false;
if (isHiddenWorkbenchNavigationAction(code)) return false;
// retry 仅当 retryable=true 时展示(避免按钮闪烁矛盾)
if (code === 'retry') return false;
return true;
@@ -195,6 +248,7 @@ const businessActionLabel = computed(() => {
}
const pa = props.primaryAction;
if (!pa) return '';
if (isNonTaskCapabilityAction(String(pa.code || ''))) return '';
// Gate action presentation uses label_key; normalize it at the shared card boundary
// so every gate renders its business label instead of exposing the action code.
const i18nKey = String(
@@ -210,7 +264,8 @@ const businessActionLabel = computed(() => {
if (te(legacyKey)) {
return t(legacyKey);
}
return pa.code;
// 当前任务按钮没有受控文案时 fail-closed,禁止泄漏内部 action code。
return '';
});
/** 题7A:按钮 tooltip(exhausted_sources 列表与文案)。 */
@@ -231,7 +286,14 @@ const businessActionTitle = computed(() => {
const actionIsRetry = computed(() => Boolean(props.retryable) || String(props.primaryAction?.code || '') === 'retry');
const recoveryActions = computed(() => (props.recoveryActions || []).filter((action) => {
const code = String(action.code || '').trim();
return code && code !== String(props.primaryAction?.code || '').trim();
if (!code || isNonTaskCapabilityAction(code)) return false;
if (code === String(props.primaryAction?.code || '').trim()) return false;
const key = String(
action.i18nKey
|| action.label_key
|| `workspace.shippingNotice.processGate.actionCodes.${code}`,
).trim();
return Boolean(key && te(key));
}));
function recoveryActionLabel(action: (typeof recoveryActions.value)[number]): string {
@@ -240,7 +302,7 @@ function recoveryActionLabel(action: (typeof recoveryActions.value)[number]): st
|| action.label_key
|| `workspace.shippingNotice.processGate.actionCodes.${action.code}`,
).trim();
return key && te(key) ? t(key) : action.code;
return key && te(key) ? t(key) : '';
}
function handleBusinessActionClick() {
@@ -20,6 +20,13 @@ const i18n = createI18n({
unnamedDocument: '未命名 PDF',
documentNavigation: '导航',
caseStatuses: { draft: '草稿', unknown: '未知' },
lifecycle: {
stages: {
order_review: '订单复核',
fulfillment_prep: '通知准备',
upload_complete: '通知完成',
},
},
otNav: {
listTitle: '订单列表 · {count}',
searchPlaceholder: '搜索',
@@ -71,16 +78,65 @@ describe('ReviewDocumentNavigation', () => {
expect(wrapper.find('[data-testid="review-document-navigation"]').exists()).toBe(false);
});
it('uses top tabs for 2–4 OTs', () => {
const wrapper = mountNav(3, 'tabs');
it('uses compact top tabs for 2–4 OTs', () => {
const wrapper = mountNav(3);
expect(wrapper.find('[data-testid="review-doc-nav-tabs"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="review-doc-nav-list"]').exists()).toBe(false);
expect(wrapper.attributes('data-nav-mode')).toBe('tabs');
});
it('uses sidebar list for 5–20 OTs', () => {
const wrapper = mountNav(8, 'sidebar');
expect(wrapper.find('[data-testid="review-doc-nav-list"]').exists()).toBe(true);
expect(wrapper.attributes('data-nav-mode')).toBe('sidebar');
expect(wrapper.classes()).toContain('sticky');
});
it('keeps the sidebar collapse rail and the explicitly forced sidebar mode', async () => {
const wrapper = mount(ReviewDocumentNavigation, {
props: {
items: items(8),
activeCaseNo: 'C-1',
navAriaLabel: 'nav',
forceMode: 'sidebar',
initiallyCollapsed: true,
},
global: { plugins: [i18n] },
});
// 关键断言:生命周期四阶段兼容不能改变既有的强制侧栏与编号折叠轨交互。
expect(wrapper.attributes('data-nav-mode')).toBe('sidebar');
expect(wrapper.get('[data-testid="review-doc-nav-C-2"]').text()).toContain('2');
await wrapper.get('[data-testid="review-doc-nav-collapse"]').trigger('click');
expect(wrapper.get('[data-testid="review-doc-nav-C-2"]').text()).toContain('f2.pdf');
});
it('keeps the file name as the queue row title while projecting PO, lifecycle stage and status', () => {
const rows = items(5);
rows[1] = {
...rows[1],
file_name: 'purchase-order-2.pdf',
po_number: 'PO-002',
lifecycle_stage: 'fulfillment_prep',
status: 'processing',
};
const wrapper = mount(ReviewDocumentNavigation, {
props: {
items: rows,
activeCaseNo: 'C-1',
navAriaLabel: 'nav',
forceMode: 'sidebar',
},
global: { plugins: [i18n] },
});
// 文件导航先展示可识别的文件名;PO/阶段/状态仍都来自后端队列 DTO。
const queueRow = wrapper.get('[data-testid="review-doc-nav-C-2"]');
expect(queueRow.find('.font-medium').text()).toBe('purchase-order-2.pdf');
expect(queueRow.text()).toContain('PO-002');
expect(queueRow.text()).toContain('通知准备');
// 关键断言:队列行内容必须是实际 DOM 子节点,不能被原生 template 隐藏成空白框。
expect(queueRow.find('template').exists()).toBe(false);
});
it('shows search for 20+ OTs', () => {
@@ -94,4 +150,25 @@ describe('ReviewDocumentNavigation', () => {
await wrapper.get('[data-testid="review-doc-nav-C-2"]').trigger('click');
expect(wrapper.emitted('select')?.[0]).toEqual(['C-2']);
});
it('keeps backend lifecycle stage visible in tabs and narrow queue', async () => {
const rows = items(2);
rows[1] = { ...rows[1], lifecycle_stage: 'fulfillment_prep', status: 'processing' };
const tabs = mount(ReviewDocumentNavigation, {
props: { items: rows, activeCaseNo: 'C-1', navAriaLabel: 'nav', forceMode: 'tabs' },
global: { plugins: [i18n] },
});
const narrow = mount(ReviewDocumentNavigation, {
props: { items: rows, activeCaseNo: 'C-1', navAriaLabel: 'nav', forceMode: 'narrow' },
global: { plugins: [i18n] },
attachTo: document.body,
});
// 关键断言:文件队列在任何响应式形态都只投影后端已裁决阶段。
expect(tabs.get('[data-testid="review-doc-nav-C-2"]').text()).toContain('通知准备');
await narrow.get('[data-testid="review-doc-nav-narrow-trigger"]').trigger('click');
// 窄屏抽屉通过 Teleport 挂到 body,断言真实可见容器而非组件根节点。
expect(document.body.querySelector('[data-testid="review-doc-nav-C-2"]')?.textContent).toContain('通知准备');
narrow.unmount();
});
});
@@ -1,8 +1,8 @@
<!--
features/chat/components/shipping-review/ReviewDocumentNavigation.vue
用途:订单处理工作台 OT/PDF 导航(按数量响应式:隐藏 / 顶栏标签 / 左侧列表 / 窄屏抽屉)。
用途:订单处理工作台 OT/PDF 导航(按数量响应式:隐藏 / 紧凑标签 / 左侧列表 / 窄屏抽屉)。
依赖:vue-i18n、lucide-vue-next。
逻辑:1 份隐藏;2–4 顶栏;≥5 左侧列表(可收起);20+ 搜索过滤;窄屏「订单 i/n」抽屉。
逻辑:1 份隐藏;桌面端 2–4 紧凑标签、5–20 左侧列表(可收起);20+ 搜索过滤;窄屏「订单 i/n」抽屉。
-->
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
@@ -26,8 +26,12 @@ export type ReviewDocumentNavItem = {
po_number?: string | null;
customer_name?: string | null;
stage_label?: string | null;
/** 队列接口下发的生命周期码;仅用于本地化展示,不参与阶段裁决。 */
lifecycle_stage?: ReviewLifecycleStageCode | null;
};
type ReviewLifecycleStageCode = 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'upload_complete';
export type ReviewDocumentNavMode = 'hidden' | 'tabs' | 'sidebar' | 'sidebar_search' | 'narrow';
const props = defineProps<{
@@ -82,6 +86,7 @@ const mode = computed<ReviewDocumentNavMode>(() => {
const count = props.items.length;
if (count <= 1) return 'hidden';
if (isNarrow.value) return 'narrow';
// 多文件先选文件、后查看阶段;2–4 用紧凑标签,5+ 才占用左侧工作列。
if (count <= 4) return 'tabs';
if (count <= 20) return 'sidebar';
return 'sidebar_search';
@@ -102,6 +107,14 @@ function caseStatusLabel(status: string): string {
return te(key) ? t(key) : t('chat.shippingOrderReview.caseStatuses.unknown');
}
/** 后端阶段码只做 i18n 投影;缺失时保留空白,禁止按 Case 状态补造阶段。 */
function lifecycleStageLabel(item: ReviewDocumentNavItem): string | null {
const code = String(item.lifecycle_stage || '').trim() as ReviewLifecycleStageCode;
if (!['intake_parse', 'order_review', 'fulfillment_prep', 'upload_complete'].includes(code)) return null;
const key = `chat.shippingOrderReview.lifecycle.stages.${code}`;
return te(key) ? t(key) : null;
}
/**
* 导航状态图标语义。
*/
@@ -208,11 +221,15 @@ function onSelect(caseNo: string) {
class="h-3 w-3 shrink-0 text-slate-400"
aria-hidden="true"
/>
<span class="truncate">{{ item.po_number || item.file_name || t('chat.shippingOrderReview.unnamedDocument') }}</span>
<span class="truncate">{{ item.file_name || t('chat.shippingOrderReview.unnamedDocument') }}</span>
</span>
<span class="truncate text-[10px] text-slate-500 dark:text-slate-400">
{{ item.customer_name || caseStatusLabel(item.status) }}
<template v-if="item.stage_label"> · {{ item.stage_label }}</template>
{{ [
item.po_number,
lifecycleStageLabel(item),
item.stage_label,
item.customer_name || caseStatusLabel(item.status),
].filter(Boolean).join(' · ') }}
</span>
</button>
</div>
@@ -310,10 +327,14 @@ function onSelect(caseNo: string) {
/>
<span class="min-w-0 flex-1">
<span class="block truncate font-medium text-primary">
{{ item.po_number || item.file_name || t('chat.shippingOrderReview.unnamedDocument') }}
{{ item.file_name || t('chat.shippingOrderReview.unnamedDocument') }}
</span>
<span class="block truncate text-[10px] text-muted">
{{ item.customer_name || caseStatusLabel(item.status) }}
{{ [
item.po_number,
lifecycleStageLabel(item),
item.customer_name || caseStatusLabel(item.status),
].filter(Boolean).join(' · ') }}
</span>
</span>
</template>
@@ -367,7 +388,9 @@ function onSelect(caseNo: string) {
@click="onSelect(item.case_no)"
>
<span class="font-medium">{{ item.file_name || t('chat.shippingOrderReview.unnamedDocument') }}</span>
<span class="text-[10px] text-muted">{{ caseStatusLabel(item.status) }}</span>
<span class="text-[10px] text-muted">
{{ [lifecycleStageLabel(item), caseStatusLabel(item.status)].filter(Boolean).join(' · ') }}
</span>
</button>
</div>
</aside>
@@ -0,0 +1,68 @@
/**
* features/chat/components/shipping-review/ReviewFieldConflictPanel.spec.ts
* 用途:验证过期字段冲突卡在服务端返回 404 后会刷新,而不会保留为可再次提交的错误入口。
* 依赖:Vitest、Vue Test Utils、Vue I18n、ReviewFieldConflictPanel。
* 逻辑:模拟并发刷新已消耗冲突,组件必须通知父工作台重取 Case 最新投影。
*/
import { mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import { describe, expect, it, vi } from 'vitest';
import { BusinessError } from '@/shared/api/client';
import ReviewFieldConflictPanel from './ReviewFieldConflictPanel.vue';
const { resolveFieldConflict } = vi.hoisted(() => ({
resolveFieldConflict: vi.fn(),
}));
vi.mock('@/features/chat/api/shipping.api', () => ({
resolveWorkspaceShippingOrderReviewFieldConflict: resolveFieldConflict,
}));
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
messages: {
'zh-CN': {
chat: { shippingOrderReview: {
fieldConflict: {
title: '字段冲突 {count} 项', subtitle: '请选择值', focusEvidence: '定位证据',
customValue: '手工值', customPlaceholder: '请输入', submitCustom: '确认手工值',
resolveReason: '人工裁决', resolveFailed: '提交失败', resolveSuccess: '已处理',
fields: { part_number: '料号' }, reasons: { field_conflict: '字段冲突' },
evidenceRole: {}, optionLabel: '候选 {index}', adoptOption: '采用候选值',
},
resume: { autoCreated: '已自动建单', waitingManualConfirm: '待人工确认' },
} },
},
},
});
describe('ReviewFieldConflictPanel', () => {
it('refreshes the case when confirming a stale manual value returns conflict-not-found', async () => {
resolveFieldConflict.mockRejectedValueOnce(new BusinessError({
message: 'Field conflict not found',
code: 'SHIPPING.REVIEW_FIELD_CONFLICT_NOT_FOUND',
status: 404,
}));
const wrapper = mount(ReviewFieldConflictPanel, {
props: {
caseNo: 'SORC-1', draftVersion: 1, editable: true,
conflicts: [{
conflict_key: '-1:part_number', field_code: 'part_number', line_index: -1,
reason: 'field_conflict', options: [],
}],
},
global: { plugins: [i18n] },
});
await wrapper.get('[data-testid="review-field-conflict-custom-toggle"]').trigger('click');
await wrapper.get('[data-testid="review-field-conflict-custom-input"]').setValue('PN-001');
await wrapper.get('[data-testid="review-field-conflict-custom-submit"]').trigger('click');
await vi.waitFor(() => expect(wrapper.emitted('refreshed')).toHaveLength(1));
// 关键断言:404 代表页面投影过期,父工作台会加载最新 Case 并移除这张卡。
expect(resolveFieldConflict).toHaveBeenCalledWith('SORC-1', '-1:part_number', expect.objectContaining({
resolution: 'custom', custom_value: 'PN-001', expected_draft_version: 1,
}));
});
});
@@ -105,6 +105,12 @@ async function adoptOption(conflict: ShippingOrderReviewFieldConflict, optionInd
showReviewResumeOutcome(result.resume_outcome, msg, t, t('chat.shippingOrderReview.fieldConflict.resolveSuccess'));
emit('refreshed');
} catch (error: unknown) {
if (error instanceof BusinessError && error.code === 'SHIPPING.REVIEW_FIELD_CONFLICT_NOT_FOUND') {
// 冲突已被其他刷新/裁决消耗:以服务端最新 Case 为准,撤掉当前过期卡片。
msg.info(resolveLocalizedErrorMessage(error.code, error.message));
emit('refreshed');
return;
}
const message = error instanceof BusinessError
? resolveLocalizedErrorMessage(error.code, error.message)
: (error instanceof Error ? error.message : t('chat.shippingOrderReview.fieldConflict.resolveFailed'));
@@ -146,6 +152,12 @@ async function submitCustom(conflict: ShippingOrderReviewFieldConflict) {
showReviewResumeOutcome(result.resume_outcome, msg, t, t('chat.shippingOrderReview.fieldConflict.resolveSuccess'));
emit('refreshed');
} catch (error: unknown) {
if (error instanceof BusinessError && error.code === 'SHIPPING.REVIEW_FIELD_CONFLICT_NOT_FOUND') {
// 与采用候选值保持同一 stale-data 恢复路径,禁止把已解决冲突留在页面上。
msg.info(resolveLocalizedErrorMessage(error.code, error.message));
emit('refreshed');
return;
}
const message = error instanceof BusinessError
? resolveLocalizedErrorMessage(error.code, error.message)
: (error instanceof Error ? error.message : t('chat.shippingOrderReview.fieldConflict.resolveFailed'));
@@ -0,0 +1,139 @@
/**
* features/chat/components/shipping-review/ReviewIntakeParsePanel.spec.ts
* 用途:锁定接收解析工作面只展示当前 Case 已授权的邮件正文与附件预览。
* 依赖:Vitest、Vue Test Utils、vue-i18n、ReviewIntakeParsePanel。
* 逻辑:PDF 才允许嵌入预览;非 PDF 明确降级;所有处置仅向父级发出意图。
*/
import { mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import { describe, expect, it } from 'vitest';
import ReviewIntakeParsePanel from './ReviewIntakeParsePanel.vue';
import type { ShippingOrderReviewIntakeParseContext } from '@/features/chat/types/shipping.api.types';
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
messages: {
'zh-CN': {
chat: {
shippingOrderReview: {
lifecycle: {
intakeParse: {
title: '接收解析',
email: '邮件正文',
noEmail: '无邮件上下文',
attachment: '当前附件',
fileName: '文件名',
fileType: '文件类型',
preview: '附件预览',
loadPreview: '加载附件预览',
previewUnsupported: '当前附件不支持预览',
loadFailed: '接收解析上下文加载失败',
retry: '重试',
loading: '正在加载接收解析上下文',
},
},
markNonOrder: '标记为非订单',
markQualityIssue: '文件质量异常',
reparse: '重新识别此 PDF',
uploadReplacement: '上传替代 PDF',
},
},
},
},
});
const emailPdfContext: ShippingOrderReviewIntakeParseContext = {
case_no: 'CASE-1',
attachment: {
document_id: 11,
filename: 'current.pdf',
mime_type: 'application/pdf',
preview_kind: 'pdf',
},
email: {
document_id: 7,
filename: 'source.eml',
text: 'approved body text',
},
};
const unsupportedContext: ShippingOrderReviewIntakeParseContext = {
...emailPdfContext,
attachment: {
document_id: 12,
filename: 'source.xlsx',
mime_type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
preview_kind: 'unsupported',
},
email: null,
};
function mountPanel(props: Record<string, unknown>) {
return mount(ReviewIntakeParsePanel, {
props: {
loading: false,
loadFailed: false,
previewUrl: null,
previewLoading: false,
saving: false,
canMarkNonOrder: false,
canMarkQualityIssue: false,
canReparse: false,
canUploadReplacement: false,
...props,
},
global: { plugins: [i18n] },
});
}
describe('ReviewIntakeParsePanel', () => {
it('renders EML text and only the selected attachment preview', () => {
const wrapper = mountPanel({ context: emailPdfContext, previewUrl: 'blob:pdf' });
// 关键断言:邮件正文与当前附件来自同一个受控 Case context,PDF 才嵌入预览。
expect(wrapper.get('[data-testid="intake-parse-email-body"]').text()).toContain('approved body text');
expect(wrapper.get('[data-testid="intake-parse-attachment-preview"] iframe').attributes('src')).toBe('blob:pdf');
});
it('does not render a PDF frame for an unsupported attachment', () => {
const wrapper = mountPanel({ context: unsupportedContext });
// 关键断言:非 PDF 不得退化为 iframe,必须明确告知不可预览。
expect(wrapper.find('[data-testid="intake-parse-attachment-preview"]').exists()).toBe(false);
expect(wrapper.get('[data-testid="intake-parse-preview-unsupported"]').exists()).toBe(true);
expect(wrapper.get('[data-testid="intake-parse-no-email"]').text()).toContain('无邮件上下文');
});
it('emits parse disposition intent without executing Case commands', async () => {
const wrapper = mountPanel({
context: emailPdfContext,
canMarkNonOrder: true,
canMarkQualityIssue: true,
canReparse: true,
canUploadReplacement: true,
});
await wrapper.get('[data-testid="intake-parse-mark-non-order"]').trigger('click');
await wrapper.get('[data-testid="intake-parse-mark-quality-issue"]').trigger('click');
await wrapper.get('[data-testid="intake-parse-reparse"]').trigger('click');
await wrapper.get('[data-testid="intake-parse-upload-replacement"] input').trigger('change');
expect(wrapper.emitted('mark-non-order')).toHaveLength(1);
expect(wrapper.emitted('mark-quality-issue')).toHaveLength(1);
expect(wrapper.emitted('reparse')).toHaveLength(1);
expect(wrapper.emitted('upload-replacement')).toHaveLength(1);
});
it('does not infer replacement permission from another disposition permission', () => {
const wrapper = mountPanel({
context: emailPdfContext,
canMarkQualityIssue: true,
canUploadReplacement: false,
});
// 关键断言:父级必须显式授予替代上传,不能因质量异常动作可用而显示上传入口。
expect(wrapper.get('[data-testid="intake-parse-mark-quality-issue"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="intake-parse-upload-replacement"]').exists()).toBe(false);
});
});
@@ -0,0 +1,200 @@
<!--
features/chat/components/shipping-review/ReviewIntakeParsePanel.vue
用途:在接收解析阶段展示当前 Case 已授权的邮件正文、当前附件及安全预览。
依赖:vue、vue-i18n、ShippingOrderReviewIntakeParseContext。
逻辑:只消费父级按 Case 获取的受控上下文;仅 PDF 可请求/渲染 iframe;处置操作只 emit,
由父页沿用既有确认弹窗和 Case 命令。
-->
<script setup lang="ts">
import { watch } from 'vue';
import { useI18n } from 'vue-i18n';
import type { ShippingOrderReviewIntakeParseContext } from '@/features/chat/types/shipping.api.types';
const props = defineProps<{
context: ShippingOrderReviewIntakeParseContext | null;
loading: boolean;
loadFailed: boolean;
previewUrl: string | null;
previewLoading: boolean;
saving: boolean;
canMarkNonOrder: boolean;
canMarkQualityIssue: boolean;
canReparse: boolean;
canUploadReplacement: boolean;
}>();
const emit = defineEmits<{
'retry-context': [];
'load-preview': [];
'mark-non-order': [];
'mark-quality-issue': [];
reparse: [];
'upload-replacement': [event: Event];
}>();
const { t } = useI18n();
/**
* 当前附件为 PDF 且尚无受控 Blob 时,通知父级使用当前 Case 加载预览。
* 仅 Case context 改变时触发,禁止对不受支持文件发起预览请求。
*/
watch(
() => props.context,
(context) => {
if (context?.attachment.preview_kind === 'pdf' && !props.previewUrl) {
emit('load-preview');
}
},
{ immediate: true },
);
</script>
<template>
<section
class="space-y-4"
data-testid="intake-parse-panel"
>
<div
v-if="loading"
class="rounded-xl border border-dashed border-slate-300 bg-slate-50 p-4 text-sm text-slate-600 dark:border-slate-700 dark:bg-slate-900/40 dark:text-slate-300"
data-testid="intake-parse-loading"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.loading') }}
</div>
<div
v-else-if="loadFailed"
class="rounded-xl border border-rose-200 bg-rose-50 p-4 text-sm text-rose-900 dark:border-rose-900 dark:bg-rose-950/40 dark:text-rose-100"
data-testid="intake-parse-load-failed"
>
<p>{{ t('chat.shippingOrderReview.lifecycle.intakeParse.loadFailed') }}</p>
<button
type="button"
class="mt-3 rounded border border-rose-300 px-2.5 py-1 text-xs hover:bg-rose-100 dark:border-rose-800 dark:hover:bg-rose-950"
data-testid="intake-parse-retry-context"
@click="emit('retry-context')"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.retry') }}
</button>
</div>
<template v-else-if="context">
<section class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900">
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.lifecycle.intakeParse.email') }}</h2>
<template v-if="context.email">
<p class="mt-1 text-xs text-slate-500">{{ context.email.filename }}</p>
<pre
class="mt-3 max-h-72 overflow-auto whitespace-pre-wrap break-words rounded bg-slate-50 p-3 text-xs text-slate-700 dark:bg-slate-950/50 dark:text-slate-200"
data-testid="intake-parse-email-body"
>{{ context.email.text }}</pre>
</template>
<p
v-else
class="mt-2 text-sm text-slate-500"
data-testid="intake-parse-no-email"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.noEmail') }}
</p>
</section>
<section class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900">
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.lifecycle.intakeParse.attachment') }}</h2>
<dl class="mt-3 grid gap-2 text-sm sm:grid-cols-2">
<div>
<dt class="text-xs text-slate-500">{{ t('chat.shippingOrderReview.lifecycle.intakeParse.fileName') }}</dt>
<dd class="mt-0.5 break-all">{{ context.attachment.filename }}</dd>
</div>
<div>
<dt class="text-xs text-slate-500">{{ t('chat.shippingOrderReview.lifecycle.intakeParse.fileType') }}</dt>
<dd class="mt-0.5 break-all">{{ context.attachment.mime_type || '-' }}</dd>
</div>
</dl>
<div
v-if="context.attachment.preview_kind === 'pdf'"
class="mt-4"
data-testid="intake-parse-attachment-preview"
>
<h3 class="text-xs font-medium text-slate-600 dark:text-slate-300">{{ t('chat.shippingOrderReview.lifecycle.intakeParse.preview') }}</h3>
<p
v-if="previewLoading"
class="mt-2 text-sm text-slate-500"
data-testid="intake-parse-preview-loading"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.previewLoading') }}
</p>
<iframe
v-else-if="previewUrl"
:src="previewUrl"
:title="context.attachment.filename"
class="mt-2 h-[32rem] w-full rounded border border-slate-200 dark:border-slate-700"
/>
<button
v-else
type="button"
class="mt-2 rounded border border-slate-300 px-2.5 py-1 text-xs hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800"
data-testid="intake-parse-load-preview"
@click="emit('load-preview')"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.loadPreview') }}
</button>
</div>
<p
v-else
class="mt-4 rounded bg-slate-50 p-3 text-sm text-slate-500 dark:bg-slate-950/50"
data-testid="intake-parse-preview-unsupported"
>
{{ t('chat.shippingOrderReview.lifecycle.intakeParse.previewUnsupported') }}
</p>
</section>
<div class="flex flex-wrap gap-2" data-testid="intake-parse-disposition-actions">
<button
v-if="canMarkNonOrder"
type="button"
:disabled="saving"
class="rounded border border-rose-200 px-3 py-2 text-sm text-rose-700 disabled:opacity-50 dark:border-rose-900 dark:text-rose-300"
data-testid="intake-parse-mark-non-order"
@click="emit('mark-non-order')"
>
{{ t('chat.shippingOrderReview.markNonOrder') }}
</button>
<button
v-if="canMarkQualityIssue"
type="button"
:disabled="saving"
class="rounded border border-amber-200 px-3 py-2 text-sm text-amber-800 disabled:opacity-50 dark:border-amber-900 dark:text-amber-200"
data-testid="intake-parse-mark-quality-issue"
@click="emit('mark-quality-issue')"
>
{{ t('chat.shippingOrderReview.markQualityIssue') }}
</button>
<button
v-if="canReparse"
type="button"
:disabled="saving"
class="rounded border border-slate-300 px-3 py-2 text-sm text-slate-600 disabled:opacity-50 dark:border-slate-700 dark:text-slate-300"
data-testid="intake-parse-reparse"
@click="emit('reparse')"
>
{{ t('chat.shippingOrderReview.reparse') }}
</button>
<label
v-if="canUploadReplacement"
class="cursor-pointer rounded border border-slate-300 px-3 py-2 text-sm text-slate-600 dark:border-slate-700 dark:text-slate-300"
:class="saving ? 'pointer-events-none opacity-50' : ''"
data-testid="intake-parse-upload-replacement"
>
<input
class="sr-only"
type="file"
accept="application/pdf,.pdf"
:disabled="saving"
@change="emit('upload-replacement', $event)"
>
{{ t('chat.shippingOrderReview.uploadReplacement') }}
</label>
</div>
</template>
</section>
</template>
@@ -0,0 +1,94 @@
/**
* features/chat/components/shipping-review/ReviewLifecycleStageNavigation.spec.ts
* 用途:验收订单生命周期阶段导航的只读查看与前置阻断交互。
* 依赖:ReviewLifecycleStageNavigation;Vue Test Utils 与 Vue I18n 测试运行时。
* 逻辑:阶段状态由父级传入;本测试只验证组件不会绕过 blocked 状态发出选择事件。
*/
import { describe, expect, it } from 'vitest';
import { mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import ReviewLifecycleStageNavigation, {
type ReviewLifecycleStageItem,
} from './ReviewLifecycleStageNavigation.vue';
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
messages: {
'zh-CN': {
chat: {
shippingOrderReview: {
lifecycle: {
navigation: '订单生命周期阶段',
current: '当前可处理',
completed: '已完成,可查看',
blocked: '前置未完成',
},
},
},
},
},
});
const stages: ReviewLifecycleStageItem[] = [
{ code: 'order_review', label: '订单复核', state: 'completed' },
{ code: 'fulfillment_prep', label: '通知准备', state: 'current' },
{ code: 'upload_complete', label: '通知完成', state: 'blocked', reason: '请先完成通知准备' },
];
/** 挂载导航,复用真实 i18n 以覆盖状态文案渲染。 */
function mountNavigation() {
return mount(ReviewLifecycleStageNavigation, {
props: { stages, activeCode: 'fulfillment_prep' },
global: { plugins: [i18n] },
});
}
describe('ReviewLifecycleStageNavigation', () => {
it('renders intake_parse as the first lifecycle stage', () => {
const wrapper = mount(ReviewLifecycleStageNavigation, {
props: {
stages: [
{ code: 'intake_parse' as ReviewLifecycleStageItem['code'], label: '接收解析', state: 'current' },
...stages,
],
activeCode: 'intake_parse' as ReviewLifecycleStageItem['code'],
},
global: { plugins: [i18n] },
});
const nodes = wrapper.findAll('div[data-testid^="review-lifecycle-stage-"]');
// 关键断言:接收解析必须在用户生命周期导航首位,不得回退为三阶段。
expect(nodes.map((node) => node.attributes('data-testid'))).toEqual([
'review-lifecycle-stage-intake_parse',
'review-lifecycle-stage-order_review',
'review-lifecycle-stage-fulfillment_prep',
'review-lifecycle-stage-upload_complete',
]);
expect(wrapper.find('[data-testid="review-lifecycle-stage-navigation"] > div').classes()).toContain('sm:grid-cols-4');
});
it('allows opening a completed stage for inspection', async () => {
const wrapper = mountNavigation();
await wrapper.get('[data-testid="review-lifecycle-stage-order_review"]').findAll('button')[1].trigger('click');
// 关键断言:完成的阶段可回看,不会因已完成而被禁用。
expect(wrapper.emitted('select')).toEqual([['order_review']]);
});
it('disables a future stage and does not emit a selection', async () => {
const wrapper = mountNavigation();
const future = wrapper.get('[data-testid="review-lifecycle-stage-upload_complete"]');
// 关键断言:前置未完成只展示原因,不能通过前端导航越过后端阶段。
expect(future.text()).toContain('请先完成通知准备');
await future.findAll('button')[1].trigger('click');
expect(wrapper.emitted('select')).toBeUndefined();
});
it('opens process details from the stage label without reserving a separate row', async () => {
const wrapper = mountNavigation();
const detail = wrapper.get('[data-testid="review-lifecycle-stage-detail-fulfillment_prep"]');
// 关键断言:阶段名称本身是流程详情入口,不额外占用工作台一整行。
await detail.trigger('click');
expect(wrapper.emitted('open-detail')).toEqual([['fulfillment_prep']]);
});
});
@@ -0,0 +1,87 @@
<!--
features/chat/components/shipping-review/ReviewLifecycleStageNavigation.vue
用途:订单生命周期工作台的四阶段导航,只呈现父级已裁决的阶段状态。
依赖:父级 ShippingOrderReviewView 提供阶段、状态和阻断原因;lucide-vue-next 图标。
逻辑:用户可打开当前或已完成阶段查看;后续阶段由父级传入 blocked 并禁用,本组件不写业务状态。
-->
<script setup lang="ts">
import { Check, LockKeyhole } from 'lucide-vue-next';
export type ReviewLifecycleStageCode = 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'upload_complete';
export type ReviewLifecycleStageState = 'current' | 'completed' | 'blocked';
export interface ReviewLifecycleStageItem {
code: ReviewLifecycleStageCode;
label: string;
state: ReviewLifecycleStageState;
reason?: string | null;
}
const props = defineProps<{
stages: ReviewLifecycleStageItem[];
/** 后端尚未下发入口时为空;导航只能展示加载/未授权态,不能自行指定订单复核。 */
activeCode: ReviewLifecycleStageCode | null;
}>();
const emit = defineEmits<{
select: [code: ReviewLifecycleStageCode];
'open-detail': [code: ReviewLifecycleStageCode];
}>();
/**
* 阶段导航只允许进入当前或已完成阶段;blocked 仅说明前置条件,不替代后端 Gate 判定。
*/
function selectStage(stage: ReviewLifecycleStageItem) {
if (stage.state === 'blocked') return;
emit('select', stage.code);
}
</script>
<template>
<nav
class="rounded-xl border border-default bg-surface p-2"
:aria-label="$t('chat.shippingOrderReview.lifecycle.navigation')"
data-testid="review-lifecycle-stage-navigation"
>
<div class="grid gap-2 sm:grid-cols-4">
<div
v-for="stage in props.stages"
:key="stage.code"
class="min-w-0 rounded-lg border px-3 py-2 text-left transition-colors"
:class="[
stage.code === props.activeCode
? 'border-brand-500 bg-brand-50 text-brand-950 dark:bg-brand-950/30 dark:text-brand-50'
: 'border-transparent hover:bg-surface-soft',
stage.state === 'blocked' ? 'opacity-60' : '',
]"
:data-testid="`review-lifecycle-stage-${stage.code}`"
>
<span class="flex items-center gap-2 text-sm font-semibold">
<Check v-if="stage.state === 'completed'" class="h-4 w-4 shrink-0 text-emerald-600" />
<LockKeyhole v-else-if="stage.state === 'blocked'" class="h-4 w-4 shrink-0 text-muted" />
<span v-else class="h-2 w-2 shrink-0 rounded-full bg-brand-600" aria-hidden="true" />
<button
type="button"
class="truncate text-left hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500"
:data-testid="`review-lifecycle-stage-detail-${stage.code}`"
@click="emit('open-detail', stage.code)"
>{{ stage.label }}</button>
</span>
<button
type="button"
class="mt-1 block w-full truncate text-left text-xs focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500 disabled:cursor-not-allowed"
:class="stage.state === 'blocked' ? 'text-muted' : 'text-secondary'"
:title="stage.reason || undefined"
:disabled="stage.state === 'blocked'"
@click="selectStage(stage)"
>
{{ stage.state === 'current'
? $t('chat.shippingOrderReview.lifecycle.current')
: stage.state === 'completed'
? $t('chat.shippingOrderReview.lifecycle.completed')
: (stage.reason || $t('chat.shippingOrderReview.lifecycle.blocked')) }}
</button>
</div>
</div>
</nav>
</template>
@@ -0,0 +1,44 @@
/**
* features/chat/components/shipping-review/ReviewWorkbenchFooter.spec.ts
* 用途:验证字段冲突的 Gate 主动作只由右栏当前任务卡承载,底栏不得重复展示。
* 依赖:Vitest、Vue Test Utils、Vue I18n、ReviewWorkbenchFooter。
* 逻辑:订单复核底栏只保留保存校验,不展示已由当前任务卡或阶段页承载的流程动作。
*/
import { mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import { describe, expect, it } from 'vitest';
import ReviewWorkbenchFooter from './ReviewWorkbenchFooter.vue';
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
messages: {
'zh-CN': {
chat: {
shippingProcessing: { action: { resolve_field_conflicts: '处理字段冲突', view_result: '查看结果', none: '无操作' } },
shippingOrderReview: { unsavedSwitch: { unsavedCount: '未保存 {count} 项' } },
},
workspace: { shippingNotice: { processGate: { actions: {} } } },
},
},
});
describe('ReviewWorkbenchFooter', () => {
it('does not duplicate current-case flow actions in the order-review footer', () => {
const wrapper = mount(ReviewWorkbenchFooter, {
props: {
availableActions: [], canConfirmBuild: false, saving: false, isReadOnly: false, hasDraft: true,
flowPresentation: {
primary: { intent: 'resolve_field_conflicts', actionCode: 'resolve_field_conflicts', labelKey: 'chat.shippingProcessing.action.resolve_field_conflicts' },
secondary: { intent: 'view_result', actionCode: 'view_result', labelKey: 'chat.shippingProcessing.action.view_result' },
overflow: [],
},
},
global: { plugins: [i18n] },
});
// 关键断言:字段冲突、重试和查看结果各有上游上下文,复核底栏不得重复它们。
expect(wrapper.find('[data-testid="review-footer-flow-resolve_field_conflicts"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="review-footer-flow-view_result"]').exists()).toBe(false);
});
});
@@ -3,7 +3,7 @@
用途:订单处理工作台底部唯一写操作栏(处置 / 保存 / 统一流程动作)。
依赖:vue-i18n、lucide-vue-next、ActionPresentation。
逻辑:ShippingOrderReviewView 传入 available_actions 与流程动作投影;sticky bottom;
只读查看时仍可展示 view_result/view_record;写按钮受 actionsExecutable 约束;
订单复核只保留保存校验;流程动作由所属阶段或当前任务卡承载;写按钮受 actionsExecutable 约束;
流程写操作经 flow-action emit(与 Resolver 同链);flowBusy||saving 时禁用。
-->
<script setup lang="ts">
@@ -36,6 +36,8 @@ const props = withDefaults(defineProps<{
actionsExecutable?: boolean;
/** 统一流程动作提交中 */
flowBusy?: boolean;
/** 解析处置入口由接收解析工作面承载时,订单复核底栏隐藏四项解析操作。 */
showParseDispositions?: boolean;
}>(), {
unsavedCount: 0,
flowPresentation: null,
@@ -46,6 +48,7 @@ const props = withDefaults(defineProps<{
autoGateHint: '',
actionsExecutable: true,
flowBusy: false,
showParseDispositions: true,
});
const emit = defineEmits<{
@@ -59,7 +62,7 @@ const emit = defineEmits<{
'flow-action': [item: ActionPresentationItem];
}>();
const { t, te } = useI18n();
const { t } = useI18n();
/**
* 判断某 action 是否在当前 Case 可用。
@@ -68,40 +71,25 @@ function hasAction(action: string): boolean {
return props.availableActions.includes(action);
}
const flowItems = computed((): ActionPresentationItem[] => {
const presentation = props.flowPresentation;
if (!presentation) return [];
const items: ActionPresentationItem[] = [];
if (presentation.primary) items.push(presentation.primary);
if (presentation.secondary) items.push(presentation.secondary);
items.push(...presentation.overflow);
// 刷新留给顶部只读区;底栏不重复。
return items.filter((item) => item.intent !== 'refresh');
});
/**
* 订单复核底栏不承载流程投影动作。
*
* 核心逻辑:保存并校验是表单级提交,固定放在这里;字段裁决、重试、查看结果等
* Case/阶段级动作必须留在其业务上下文中,避免同一动作在顶栏、右栏和底栏重复出现。
*/
const footerFlowItems = computed((): ActionPresentationItem[] => []);
const hasViewOnlyFlow = computed(() => flowItems.value.some((item) => (
item.intent === 'view_result'
|| item.intent === 'view_record'
|| item.intent === 'open_profile_review'
)));
/** 保留统一动作的文案解析,供后续恢复 Footer 流程动作时复用。 */
function flowLabel(item: ActionPresentationItem): string {
return t(item.labelKey);
}
/** 可编辑底栏,或只读但仍有导航/查看类流程动作。 */
const showFooter = computed(() => (
props.hasDraft && (!props.isReadOnly || hasViewOnlyFlow.value)
));
/** 仅可编辑草稿显示表单提交底栏;只读版本不显示无上下文的流程按钮。 */
const showFooter = computed(() => props.hasDraft && !props.isReadOnly);
const controlsBusy = computed(() => props.saving || props.flowBusy);
const canWriteCaseActions = computed(() => props.actionsExecutable && !props.isReadOnly);
/**
* 流程动作文案。
*/
function flowLabel(item: ActionPresentationItem): string {
if (te(item.labelKey)) return t(item.labelKey);
const gateKey = `workspace.shippingNotice.processGate.actions.${item.actionCode}`;
if (te(gateKey)) return t(gateKey);
return t('chat.shippingProcessing.action.none');
}
</script>
<template>
@@ -116,7 +104,7 @@ function flowLabel(item: ActionPresentationItem): string {
<div class="order-1 flex flex-wrap items-center gap-2 sm:order-1">
<template v-if="!automating && canWriteCaseActions">
<button
v-if="hasAction('mark_non_order')"
v-if="showParseDispositions && hasAction('mark_non_order')"
type="button"
:disabled="controlsBusy"
class="rounded border border-rose-200 px-3 py-2 text-sm text-rose-700 hover:bg-rose-50 disabled:opacity-50 dark:border-rose-900 dark:text-rose-300 dark:hover:bg-rose-950/40"
@@ -125,7 +113,7 @@ function flowLabel(item: ActionPresentationItem): string {
{{ t('chat.shippingOrderReview.markNonOrder') }}
</button>
<button
v-if="hasAction('mark_quality_issue')"
v-if="showParseDispositions && hasAction('mark_quality_issue')"
type="button"
:disabled="controlsBusy"
class="rounded border border-amber-200 px-3 py-2 text-sm text-amber-800 hover:bg-amber-50 disabled:opacity-50 dark:border-amber-900 dark:text-amber-200 dark:hover:bg-amber-950/40"
@@ -134,7 +122,7 @@ function flowLabel(item: ActionPresentationItem): string {
{{ t('chat.shippingOrderReview.markQualityIssue') }}
</button>
<button
v-if="hasAction('reparse')"
v-if="showParseDispositions && hasAction('reparse')"
type="button"
:disabled="controlsBusy"
class="inline-flex items-center gap-1 rounded border border-slate-300 px-3 py-2 text-sm text-slate-600 hover:bg-slate-50 disabled:opacity-50 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800"
@@ -143,7 +131,7 @@ function flowLabel(item: ActionPresentationItem): string {
<RefreshCw class="h-4 w-4" />{{ t('chat.shippingOrderReview.reparse') }}
</button>
<label
v-if="hasAction('mark_quality_issue')"
v-if="showParseDispositions && hasAction('mark_quality_issue')"
class="cursor-pointer rounded border border-slate-300 px-3 py-2 text-sm text-slate-600 hover:bg-slate-50 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800"
:class="controlsBusy ? 'pointer-events-none opacity-50' : ''"
>
@@ -159,7 +147,7 @@ function flowLabel(item: ActionPresentationItem): string {
</template>
<button
v-for="item in flowItems"
v-for="item in footerFlowItems"
:key="`${item.intent}-${item.actionCode}`"
type="button"
:disabled="controlsBusy"
@@ -195,16 +183,6 @@ function flowLabel(item: ActionPresentationItem): string {
{{ autoGateHint || t('chat.shippingOrderReview.buildEligibility.autoGateWaitingHint') }}
</p>
<template v-if="!automating && canWriteCaseActions">
<button
v-if="showStpRetry || hasAction('retry_stp_auto_create')"
type="button"
:disabled="controlsBusy"
class="inline-flex items-center gap-1 rounded border border-amber-400 bg-amber-50 px-3 py-2 text-sm text-amber-950 disabled:opacity-50 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-100"
data-testid="review-retry-stp-auto-create"
@click="emit('retry-stp')"
>
<RefreshCw class="h-4 w-4" />{{ t('chat.shippingOrderReview.autoProgress.retryObject') }}
</button>
<button
v-if="hasAction('validate')"
type="button"
@@ -212,7 +190,7 @@ function flowLabel(item: ActionPresentationItem): string {
class="inline-flex items-center gap-1 rounded bg-sky-600 px-3 py-2 text-sm text-white disabled:opacity-50"
@click="emit('validate')"
>
<Save class="h-4 w-4" />{{ t('chat.shippingOrderReview.saveNow') }}
<Save class="h-4 w-4" />{{ t('chat.shippingOrderReview.saveOrderAndValidate') }}
</button>
</template>
</div>
@@ -14,6 +14,7 @@ const props = defineProps<{
runNo: string;
itemNo?: string | null;
versionLabel?: string;
selectedOrderSummary?: string | null;
saving: boolean;
saveFailed: boolean;
draftConflict: boolean;
@@ -38,19 +39,6 @@ const emit = defineEmits<{
const { t } = useI18n();
/**
* 副标题:优先工作项编号与版本,否则识别批次号。
*/
const subtitle = computed(() => {
if (props.itemNo) {
return t('chat.shippingOrderReview.workItemHeader', {
itemNo: props.itemNo,
version: props.versionLabel || '',
});
}
return t('chat.shippingOrderReview.run', { runNo: props.runNo });
});
const showRetry = computed(() => (
Boolean(props.showConversationRetry)
&& Number(props.conversationRetryEligibleCount || 0) > 0
@@ -69,7 +57,11 @@ const showRetry = computed(() => (
</button>
<div class="min-w-0 flex-1">
<h1 class="text-base font-semibold">{{ t('chat.shippingOrderReview.title') }}</h1>
<p class="truncate text-xs text-slate-500 dark:text-slate-400">{{ subtitle }}</p>
<p
v-if="selectedOrderSummary"
class="truncate text-xs text-slate-600 dark:text-slate-300"
data-testid="review-selected-order-summary"
>{{ selectedOrderSummary }}</p>
</div>
<button
v-if="showRetry"