feat(shipping-notice): 升级货代发货流程为五阶段,完善业务校验

将货代发货流程从四阶段扩展为五阶段,拆分上传相关逻辑至独立的货代上传阶段;
统一多语言文案修正客户状态语义,将"客户尚未识别"调整为符合业务的"客户尚未确认";
新增严格的上传成功验证谓词,需同时满足任务状态、全部预约单上传成功、存在有效成功上传尝试三个条件方可标记为完成;
新增坐标取值模型配置,支持Legacy冻结绝对坐标和锚点框架受限平移两种模式;
更新全链路相关文档、前端组件、后端服务与测试用例,确保业务逻辑对齐新业务规则。
This commit is contained in:
hugo committed 2026-08-21 09:20:47 +08:00
1 parent 1b6483a4ea
commit 935bf26fa6
86 files changed
+2743 -311

No files matched your search

@@ -1,6 +1,6 @@
/**
* features/chat/components/ShippingWorkflowStepper.vue
* 用途:货代发货四阶段 Stepper 展示组件。
* 用途:货代发货五阶段 Stepper 展示组件。
* 依赖:shipping/shippingStepper、vue-i18n。
* 逻辑:Chat 与工作台传入 steps 数组;本组件只负责步骤高亮与标签渲染。
*/
@@ -33,7 +33,7 @@ const dotClass = (status: ShippingWorkflowStepItem['status']) => {
<template>
<div class="space-y-2">
<div class="text-[11px] font-semibold uppercase tracking-[0.18em] text-muted">{{ t('chat.shippingNoticeUi.stepperTitle') }}</div>
<div class="grid gap-2" :class="compact ? 'sm:grid-cols-4' : 'md:grid-cols-4'">
<div class="grid gap-2" :class="compact ? 'sm:grid-cols-5' : 'md:grid-cols-5'">
<div
v-for="(step, index) in steps"
:key="step.id"
@@ -167,7 +167,9 @@ const hasDiagnosticDetails = computed(() => Boolean(
<div class="min-h-0 flex-1 space-y-2 overflow-y-auto p-4">
<section
class="rounded-lg border px-3 py-2 text-xs"
:class="eligibility.can_build
:class="eligibility.can_build === null
? 'border-slate-200 bg-slate-50 text-slate-800 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100'
: eligibility.can_build
? 'border-emerald-200 bg-emerald-50 text-emerald-900 dark:border-emerald-900 dark:bg-emerald-950/30 dark:text-emerald-100'
: '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"
@@ -175,8 +177,10 @@ const hasDiagnosticDetails = computed(() => Boolean(
<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'">
<span data-testid="review-eligibility-manual-status">{{ eligibility.can_build
<span class="rounded-full px-2 py-0.5 font-medium" :class="eligibility.can_build === null ? 'bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-100' : 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'">
<span data-testid="review-eligibility-manual-status">{{ eligibility.can_build === null
? t('chat.shippingOrderReview.buildEligibility.notValidated')
: eligibility.can_build
? t('chat.shippingOrderReview.buildEligibility.canBuildYes')
: t('chat.shippingOrderReview.buildEligibility.canBuildNo') }}</span>
</span>
@@ -153,6 +153,7 @@ const lowConfidenceFields = computed(() => props.eligibility?.issues?.flatMap((i
) || []);
const unexplainedBlocked = computed(() => Boolean(
props.eligibility
&& props.eligibility.status !== 'not_validated'
&& props.eligibility.can_build === false
&& !props.eligibility.issues?.length
&& !props.eligibility.failed_gates?.length
@@ -212,13 +213,17 @@ const gateChecklist = computed(() => {
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.buildEligibility.title') }}</h2>
<span
class="rounded-full px-2.5 py-1 text-xs font-medium"
:class="eligibility.can_build
:class="eligibility.can_build === null
? 'bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-200'
: eligibility.can_build
? 'bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-100'
: 'bg-amber-100 text-amber-900 dark:bg-amber-950 dark:text-amber-100'"
data-testid="review-build-eligibility-badge"
>
{{
eligibility.can_build
eligibility.status === 'not_validated'
? t('chat.shippingOrderReview.buildEligibility.notValidated')
: eligibility.can_build
? t('chat.shippingOrderReview.buildEligibility.canBuildYes')
: t('chat.shippingOrderReview.buildEligibility.canBuildNo')
}}
@@ -0,0 +1,63 @@
/**
* features/chat/components/shipping-review/ReviewCustomerResolutionPanel.spec.ts
* 用途:锁定唯一标准客户候选的工作台提示,避免将可自动确认状态误报为未识别。
* 依赖:vitest、@vue/test-utils、vue-i18n、ReviewCustomerResolutionPanel。
* 逻辑:unique_candidate 显示自动确认说明和明确按钮;其他未确认状态维持人工选择入口。
*/
import { describe, expect, it } from 'vitest';
import { mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import ReviewCustomerResolutionPanel from './ReviewCustomerResolutionPanel.vue';
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
messages: {
'zh-CN': {
chat: {
shippingCustomer: { loadFailed: '加载失败', confirmFailed: '确认失败' },
shippingOrderReview: {
customerResolution: {
title: '客户确认', subtitle: '请选择标准客户', uniqueCandidateHint: '已找到唯一标准客户候选;保存校验时系统会自动确认,也可手动确认。',
confirmUniqueCandidate: '确认唯一候选', selectCustomer: '选择标准客户', retrying: '识别中…', retryCustomer: '重新识别客户',
retryDone: '已重新识别客户', retryFailed: '重新识别客户失败', confirmed: '客户已确认', confirmReason: '人工确认',
standardCustomer: '标准客户', customerCode: '客户编码', matchedInputs: '匹配输入', candidates: '候选客户', pdfReparseHint: '请重新识别 PDF',
inputLabels: { customerCode: '客户编码', customerName: '客户名称', address: '地址', email: '邮箱', domain: '域名', other: '其他' },
status: { unique_candidate: '唯一候选', unmatched: '未匹配', confirmed: '已确认' },
},
resume: { autoCreated: '已自动建单', waitingManualConfirm: '等待人工确认' },
},
},
},
},
});
function mountPanel(status: string) {
return mount(ReviewCustomerResolutionPanel, {
props: {
caseNo: 'CASE-CUSTOMER-1',
editable: true,
resolution: { resolved: false, status, raw_name: 'ACME' },
},
global: {
plugins: [i18n],
stubs: { ShippingCustomerConfirmDialog: true },
},
});
}
describe('ReviewCustomerResolutionPanel', () => {
it('唯一候选展示自动确认说明和明确确认入口', () => {
const wrapper = mountPanel('unique_candidate');
expect(wrapper.text()).toContain('保存校验时系统会自动确认');
expect(wrapper.get('[data-testid="review-select-customer"]').text()).toContain('确认唯一候选');
});
it('非唯一未确认状态维持人工选择客户入口', () => {
const wrapper = mountPanel('unmatched');
expect(wrapper.text()).not.toContain('保存校验时系统会自动确认');
expect(wrapper.get('[data-testid="review-select-customer"]').text()).toContain('选择标准客户');
});
});
@@ -41,6 +41,10 @@ const options = ref<ShippingCustomerOption[]>([]);
const loadingOptions = ref(false);
const resolved = computed(() => Boolean(props.resolution?.resolved));
const hasUniqueCandidate = computed(() => (
!resolved.value
&& String(props.resolution?.status || '').trim() === 'unique_candidate'
));
const statusLabel = computed(() => {
const status = String(props.resolution?.status || '').trim();
if (!status) {
@@ -198,7 +202,11 @@ async function onRetry() {
<header class="flex flex-wrap items-start justify-between gap-2">
<div>
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.customerResolution.title') }}</h2>
<p class="mt-0.5 text-xs text-muted">{{ t('chat.shippingOrderReview.customerResolution.subtitle') }}</p>
<p class="mt-0.5 text-xs text-muted">
{{ hasUniqueCandidate
? t('chat.shippingOrderReview.customerResolution.uniqueCandidateHint')
: t('chat.shippingOrderReview.customerResolution.subtitle') }}
</p>
</div>
<span
class="rounded-full px-2.5 py-1 text-xs font-medium"
@@ -244,7 +252,9 @@ async function onRetry() {
:disabled="busy"
@click="openSelectDialog"
>
{{ t('chat.shippingOrderReview.customerResolution.selectCustomer') }}
{{ hasUniqueCandidate
? t('chat.shippingOrderReview.customerResolution.confirmUniqueCandidate')
: t('chat.shippingOrderReview.customerResolution.selectCustomer') }}
</button>
<button
type="button"
@@ -30,7 +30,7 @@ export type ReviewDocumentNavItem = {
lifecycle_stage?: ReviewLifecycleStageCode | null;
};
type ReviewLifecycleStageCode = 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'upload_complete';
type ReviewLifecycleStageCode = 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'freight_upload' | 'upload_complete';
export type ReviewDocumentNavMode = 'hidden' | 'tabs' | 'sidebar' | 'sidebar_search' | 'narrow';
@@ -112,7 +112,7 @@ function caseStatusLabel(status: string): string {
/** 后端阶段码只做 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;
if (!['intake_parse', 'order_review', 'fulfillment_prep', 'freight_upload', 'upload_complete'].includes(code)) return null;
const key = `chat.shippingOrderReview.lifecycle.stages.${code}`;
return te(key) ? t(key) : null;
}
@@ -17,6 +17,7 @@ const i18n = createI18n({
messages: {
'zh-CN': {
chat: {
shippingNoticeRetryParse: '重试解析',
shippingOrderReview: {
lifecycle: {
navigation: '订单生命周期阶段',
@@ -33,6 +34,7 @@ const i18n = createI18n({
const stages: ReviewLifecycleStageItem[] = [
{ code: 'order_review', label: '订单复核', state: 'completed' },
{ code: 'fulfillment_prep', label: '通知准备', state: 'current' },
{ code: 'freight_upload', label: '货代上传', state: 'blocked', reason: '请先完成通知准备' },
{ code: 'upload_complete', label: '通知完成', state: 'blocked', reason: '请先完成通知准备' },
];
@@ -45,6 +47,30 @@ function mountNavigation() {
}
describe('ReviewLifecycleStageNavigation', () => {
it('only exposes retry_parse on the current intake stage when the server authorizes it', async () => {
const wrapper = mount(ReviewLifecycleStageNavigation, {
props: {
stages: [
{ code: 'intake_parse', label: '接收解析', state: 'current' },
...stages,
],
activeCode: 'intake_parse',
availableActions: ['retry_parse'],
retrying: false,
},
global: { plugins: [i18n] },
});
// 关键断言:重试入口必须位于已发送文件的当前阶段卡,且完全由后端动作授权。
const retry = wrapper.get('[data-testid="review-lifecycle-stage-retry-parse"]');
expect(retry.text()).toContain('重试解析');
await retry.trigger('click');
expect(wrapper.emitted('retry-parse')).toEqual([[]]);
await wrapper.setProps({ availableActions: [] });
expect(wrapper.find('[data-testid="review-lifecycle-stage-retry-parse"]').exists()).toBe(false);
});
it('renders intake_parse as the first lifecycle stage', () => {
const wrapper = mount(ReviewLifecycleStageNavigation, {
props: {
@@ -63,9 +89,10 @@ describe('ReviewLifecycleStageNavigation', () => {
'review-lifecycle-stage-intake_parse',
'review-lifecycle-stage-order_review',
'review-lifecycle-stage-fulfillment_prep',
'review-lifecycle-stage-freight_upload',
'review-lifecycle-stage-upload_complete',
]);
expect(wrapper.find('[data-testid="review-lifecycle-stage-navigation"] > div').classes()).toContain('sm:grid-cols-4');
expect(wrapper.find('[data-testid="review-lifecycle-stage-navigation"] > div').classes()).toContain('sm:grid-cols-5');
});
it('allows opening a completed stage for inspection', async () => {
@@ -1,13 +1,13 @@
<!--
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 ReviewLifecycleStageCode = 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'freight_upload' | 'upload_complete';
export type ReviewLifecycleStageState = 'current' | 'completed' | 'blocked';
export interface ReviewLifecycleStageItem {
@@ -21,13 +21,25 @@ const props = defineProps<{
stages: ReviewLifecycleStageItem[];
/** 后端尚未下发入口时为空;导航只能展示加载/未授权态,不能自行指定订单复核。 */
activeCode: ReviewLifecycleStageCode | null;
/** 仅消费当前对象后端下发的恢复动作,禁止按阶段或状态由前端猜测。 */
availableActions?: string[];
/** retry_parse 请求中的互斥状态,避免用户重复提交。 */
retrying?: boolean;
}>();
const emit = defineEmits<{
select: [code: ReviewLifecycleStageCode];
'open-detail': [code: ReviewLifecycleStageCode];
'retry-parse': [];
}>();
/** 接收解析的恢复只在后端明确授权且该阶段为当前阶段时展示。 */
function canRetryParse(stage: ReviewLifecycleStageItem): boolean {
return stage.code === 'intake_parse'
&& stage.state === 'current'
&& (props.availableActions || []).includes('retry_parse');
}
/**
* 阶段导航只允许进入当前或已完成阶段;blocked 仅说明前置条件,不替代后端 Gate 判定。
*/
@@ -43,7 +55,7 @@ function selectStage(stage: ReviewLifecycleStageItem) {
:aria-label="$t('chat.shippingOrderReview.lifecycle.navigation')"
data-testid="review-lifecycle-stage-navigation"
>
<div class="grid gap-2 sm:grid-cols-4">
<div class="grid gap-2 sm:grid-cols-5">
<div
v-for="stage in props.stages"
:key="stage.code"
@@ -81,6 +93,16 @@ function selectStage(stage: ReviewLifecycleStageItem) {
? $t('chat.shippingOrderReview.lifecycle.completed')
: (stage.reason || $t('chat.shippingOrderReview.lifecycle.blocked')) }}
</button>
<button
v-if="canRetryParse(stage)"
type="button"
class="mt-2 rounded border border-brand-300 px-2 py-1 text-xs font-medium text-brand-700 hover:bg-brand-50 disabled:cursor-not-allowed disabled:opacity-60 dark:border-brand-700 dark:text-brand-200 dark:hover:bg-brand-950/40"
data-testid="review-lifecycle-stage-retry-parse"
:disabled="props.retrying === true"
@click="emit('retry-parse')"
>
{{ $t('chat.shippingNoticeRetryParse') }}
</button>
</div>
</div>
</nav>
@@ -18,6 +18,10 @@ const i18n = createI18n({
title: '文档模板匹配', subtitle: '摘要', selected: '命中模板', noSelected: '未选定模板',
expandCandidates: '查看候选模板({count})', collapseCandidates: '收起候选模板',
routeType: '路由类型', executionMode: '执行模式',
coordinateModel: {
anchorFrame: '锚点坐标框架', status: '变换状态', translateX: '横向平移',
translateY: '纵向平移', reasonCodes: '原因码',
},
status: { matched: '已匹配', ambiguous: '多个候选' },
} } },
},
@@ -44,6 +48,34 @@ function mountPanel(needsReview = false) {
});
}
function mountAnchorFramePanel(visibility: 'admin' | 'admin_only' = 'admin') {
return mount(ReviewProfileMatchPanel, {
props: {
profileMatch: {
available: true,
visibility,
status: 'unique_match',
needs_review: false,
selected_profile: { profile_code: 'ODP-A', display_name: '客户订单模板', version: 1 },
candidates: [{
profile_code: 'ODP-A',
version: 1,
display_name: '客户订单模板',
score: 0.99,
coordinate_transform: {
status: 'applied',
translate_x: 0.001,
translate_y: 0.03,
reason_codes: [],
},
}],
fallback_reason_codes: [],
},
},
global: { plugins: [i18n] },
});
}
describe('ReviewProfileMatchPanel', () => {
it('默认收起无需关注的候选列表', () => {
const wrapper = mountPanel(false);
@@ -69,4 +101,23 @@ describe('ReviewProfileMatchPanel', () => {
expect(wrapper.get('[data-testid="review-profile-match-candidates"]').text()).toContain('客户订单模板');
expect(wrapper.get('[data-testid="review-profile-match-candidates"]').text()).not.toContain('ODP-A');
});
it('管理员技术详情展示锚点框架平移和稳定原因码,不展示原始正文或完整坐标', async () => {
const wrapper = mountAnchorFramePanel();
await wrapper.get('[data-testid="review-profile-match-candidates-toggle"]').trigger('click');
const details = wrapper.get('[data-testid="review-profile-match-details"]');
expect(details.text()).toContain('锚点坐标框架');
expect(details.text()).toContain('纵向平移');
expect(details.text()).toContain('0.03');
expect(details.text()).not.toContain('ORDER NO.');
expect(details.text()).not.toContain('x0');
});
it('非管理员不可见锚点框架技术详情', async () => {
const wrapper = mountAnchorFramePanel('admin_only');
expect(wrapper.find('[data-testid="review-profile-match-panel"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="review-profile-match-coordinate-transform"]').exists()).toBe(false);
});
});
@@ -30,6 +30,19 @@ const candidateCount = computed(() => (props.profileMatch?.candidates || []).len
const defaultCandidatesExpanded = computed(() => false);
const candidatesOpenOverride = ref<boolean | null>(null);
const candidatesExpanded = computed(() => candidatesOpenOverride.value ?? defaultCandidatesExpanded.value);
const selectedCoordinateTransform = computed(() => {
if (!isAdminView.value) return null;
const selectedCode = String(props.profileMatch?.selected_profile?.profile_code || '');
const selectedVersion = props.profileMatch?.selected_profile?.version;
const candidate = (props.profileMatch?.candidates || []).find((item) => (
item.profile_code === selectedCode
&& (selectedVersion == null || item.version === selectedVersion)
));
return candidate?.coordinate_transform || null;
});
const coordinateTransformReasonCodes = computed(() => (
selectedCoordinateTransform.value?.reason_codes || []
));
watch(
() => `${props.profileMatch?.status || ''}:${props.profileMatch?.selected_profile?.profile_code || ''}:${candidateCount.value}`,
@@ -118,6 +131,17 @@ const selectedLabel = computed(() => {
<dt class="text-muted">{{ t('chat.shippingOrderReview.profileMatch.executionMode') }}</dt>
<dd class="font-mono">{{ profileMatch.execution_mode }}</dd>
</div>
<div v-if="selectedCoordinateTransform" data-testid="review-profile-match-coordinate-transform" class="mt-2 rounded-lg border border-sky-200 bg-sky-50 px-2.5 py-2 text-[11px] text-sky-950 dark:border-sky-900 dark:bg-sky-950/30 dark:text-sky-100">
<div class="font-medium">{{ t('chat.shippingOrderReview.profileMatch.coordinateModel.anchorFrame') }}</div>
<div class="mt-1 flex flex-wrap gap-x-3 gap-y-1">
<span>{{ t('chat.shippingOrderReview.profileMatch.coordinateModel.status') }}: {{ selectedCoordinateTransform.status }}</span>
<span v-if="selectedCoordinateTransform.translate_x != null">{{ t('chat.shippingOrderReview.profileMatch.coordinateModel.translateX') }}: {{ selectedCoordinateTransform.translate_x }}</span>
<span v-if="selectedCoordinateTransform.translate_y != null">{{ t('chat.shippingOrderReview.profileMatch.coordinateModel.translateY') }}: {{ selectedCoordinateTransform.translate_y }}</span>
</div>
<div v-if="coordinateTransformReasonCodes.length" class="mt-1">
{{ t('chat.shippingOrderReview.profileMatch.coordinateModel.reasonCodes') }}: {{ coordinateTransformReasonCodes.join(', ') }}
</div>
</div>
</dl>
<ul
class="mt-2 max-h-48 space-y-1.5 overflow-y-auto pr-1"
@@ -801,6 +801,7 @@ describe('ShippingConversationProcessingCard', () => {
lifecycleEntries: [
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
],
blocking_reason: null,
@@ -820,6 +821,7 @@ describe('ShippingConversationProcessingCard', () => {
expect(row.text()).toContain('通知准备');
expect(row.text()).toContain('订单复核 · 可进入');
expect(row.text()).toContain('通知准备 · 当前可处理');
expect(row.text()).toContain('货代上传 · 前置未完成');
expect(row.text()).toContain('通知完成 · 前置未完成');
});
@@ -50,8 +50,8 @@ const props = defineProps<{
hasMoreHistory?: boolean;
/** 批次中心按状态 → EML → 文件展示,不再嵌入任务级 15 节点进度。 */
workbenchMode?: boolean;
/** 批次四阶段筛选;保留状态/EML 分组,仅隐藏不属于当前阶段的任务。 */
lifecycleFilter?: 'all' | 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'upload_complete';
/** 批次五阶段筛选;保留状态/EML 分组,仅隐藏不属于当前阶段的任务。 */
lifecycleFilter?: 'all' | 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'freight_upload' | 'upload_complete';
/** 批次中心本地搜索:只筛叶子文件,父 EML 卡仍保留。 */
fileSearchQuery?: string;
/** 后端已授权下载的正式 Excel 对应 OT。 */
@@ -94,12 +94,13 @@ type WorkbenchFileRow = {
po_number?: string | null;
projection?: ShippingProcessingProjection;
};
const LIFECYCLE_STAGE_CODES = ['intake_parse', 'order_review', 'fulfillment_prep', 'upload_complete'] as const;
const LIFECYCLE_STAGE_CODES = ['intake_parse', 'order_review', 'fulfillment_prep', 'freight_upload', 'upload_complete'] as const;
type LifecycleStageCode = typeof LIFECYCLE_STAGE_CODES[number];
const LIFECYCLE_STAGE_LABEL_KEYS: Record<string, string> = {
intake_parse: 'intakeParse',
order_review: 'orderReview',
fulfillment_prep: 'fulfillmentPrep',
freight_upload: 'freightUpload',
upload_complete: 'uploadComplete',
};
@@ -454,7 +455,7 @@ function workbenchFileReason(file: WorkbenchFileRow, task: ConversationProcessin
return taskReasonLabel(task);
}
/** 文件工作面显示四阶段业务语义;技术 stage 仍保留给进度诊断,不用于入口可达性。 */
/** 文件工作面显示五阶段业务语义;技术 stage 仍保留给进度诊断,不用于入口可达性。 */
function workbenchFileLifecycleStage(file: WorkbenchFileRow): string {
const code = String(file.projection?.uiState?.lifecycleStage || '').trim();
const key = LIFECYCLE_STAGE_LABEL_KEYS[code];
@@ -2,7 +2,7 @@
* features/chat/components/shipping/ShippingWorkflowTimeline.spec.ts
* 用途:验收批次进度中心只投影后端实时状态,不再保留文件详情抽屉。
* 依赖:Vitest、Vue Test Utils、Timeline、ShippingConversationProcessingCard、shipping API。
* 逻辑:四阶段、生命周期入口与单文件取消均由后端 Projection/availableActions 决定。
* 逻辑:五阶段、生命周期入口与单文件取消均由后端 Projection/availableActions 决定。
*/
import { flushPromises, mount } from '@vue/test-utils';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -116,23 +116,29 @@ describe('ShippingWorkflowTimeline', () => {
api.reparseBatch.mockClear();
});
it('renders backend-owned four-stage summaries and the authorized download toolbar', async () => {
it('prefers backend five-stage lifecycle nodes and shows the authorized download toolbar in freight upload', async () => {
const processing = processingProjection({
four_stage_nodes: [
lifecycle_nodes: [
{ code: 'intake_parse', status: 'passed', summary: { total: 1, completed: 1, needs_action: 0, processing: 0, failed: 0, blocking_reason: null } },
{ code: 'order_review', status: 'passed', summary: { total: 1, completed: 1, needs_action: 0, processing: 0, failed: 0, blocking_reason: null } },
{ code: 'fulfillment_prep', status: 'passed', summary: { total: 1, completed: 1, needs_action: 0, processing: 0, failed: 0, blocking_reason: null } },
{ code: 'upload_complete', status: 'running', summary: { total: 1, completed: 0, needs_action: 1, processing: 0, failed: 0, blocking_reason: { code: 'manual_upload_pending' } } },
{ code: 'freight_upload', status: 'running', summary: { total: 1, completed: 0, needs_action: 1, processing: 0, failed: 0, blocking_reason: { code: 'manual_upload_pending' } } },
{ code: 'upload_complete', status: 'pending', summary: { total: 1, completed: 0, needs_action: 0, processing: 0, failed: 0, blocking_reason: null } },
],
// 新字段存在时必须优先使用,不能显示兼容字段的旧/冲突结果。
four_stage_nodes: [{ code: 'upload_complete', status: 'passed', summary: { total: 9, completed: 9, needs_action: 0, processing: 0, failed: 0, blocking_reason: null } }],
output_artifacts: [{ order_task_no: 'OT-1', filename: 'notice.xlsx', type: 'xlsx', status: 'ready', action: { code: 'download_excel', enabled: true } }],
} as Partial<ConversationProcessingProjection>);
const wrapper = mountTimeline(processing, [fileProjection()]);
await flushPromises();
expect(wrapper.get('[data-testid="shipping-workflow-four-stage-progress"]').text()).toContain('接收解析');
const upload = wrapper.get('[data-testid="shipping-workflow-stage-filter-upload_complete"]');
// 四阶段卡仅保留阶段名和后端统计数量,状态由卡片样式表达。
expect(upload.text()).toBe('通知完成1');
const progress = wrapper.get('[data-testid="shipping-workflow-lifecycle-progress"]');
expect(progress.text()).toContain('接收解析');
expect(progress.text()).toContain('货代上传');
expect(progress.findAll('button')).toHaveLength(5);
const upload = wrapper.get('[data-testid="shipping-workflow-stage-filter-freight_upload"]');
// 五阶段卡仅保留阶段名和后端统计数量,状态由卡片样式表达。
expect(upload.text()).toBe('货代上传1');
await upload.trigger('click');
expect(wrapper.find('[data-testid="shipping-workflow-download-toolbar"]').exists()).toBe(true);
});
@@ -463,7 +469,7 @@ describe('ShippingWorkflowTimeline', () => {
}));
});
it('shows only title and total on four-stage cards', async () => {
it('falls back to the compatibility lifecycle field and shows only title and total', async () => {
const processing = processingProjection({
four_stage_nodes: [{
code: 'order_review', status: 'blocked',
@@ -1,6 +1,6 @@
/**
* features/chat/components/shipping/ShippingWorkflowTimeline.vue
* 用途:聊天页右侧「批次进度中心」——后端批次投影、四阶段进度和文件行操作。
* 用途:聊天页右侧「批次进度中心」——后端批次投影、五阶段进度和文件行操作。
* 依赖:vue-i18n、useMessage、useShippingNoticeWorkflow、ShippingConversationProcessingCard、
* ReasonDialog、ProcessGateRecoveryCard。
* 逻辑:顶层以 OT / ShippingProcessing 为主路径;标题栏仅保留批次名称、加载与截断提示,
@@ -115,25 +115,28 @@ const processing = computed(() => ctl.value.processing?.value ?? null);
/** 展示投影:统一 ShippingProcessing / conversation_processing。 */
const displayProcessing = computed(() => processing.value);
const batchArtifacts = computed(() => displayProcessing.value?.output_artifacts || []);
const batchFourStageNodes = computed(() => displayProcessing.value?.four_stage_nodes || []);
const lifecycleFilter = ref<'all' | 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'upload_complete'>('all');
const batchLifecycleNodes = computed(() => (
displayProcessing.value?.lifecycle_nodes || displayProcessing.value?.four_stage_nodes || []
));
const lifecycleFilter = ref<'all' | 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'freight_upload' | 'upload_complete'>('all');
const fileSearchQuery = ref('');
const selectedDownloadTaskNos = ref<string[]>([]);
/** 四阶段后端编码为 snake_case,语言资源键沿用 camelCase;映射仅做展示翻译,不参与状态裁决。 */
const BATCH_FOUR_STAGE_I18N_KEYS: Record<string, string> = {
/** 五阶段后端编码为 snake_case,语言资源键沿用 camelCase;映射仅做展示翻译,不参与状态裁决。 */
const BATCH_LIFECYCLE_I18N_KEYS: Record<string, string> = {
intake_parse: 'intakeParse',
order_review: 'orderReview',
fulfillment_prep: 'fulfillmentPrep',
freight_upload: 'freightUpload',
upload_complete: 'uploadComplete',
};
function batchFourStageLabelKey(code: string): string {
return BATCH_FOUR_STAGE_I18N_KEYS[code] || code;
function batchLifecycleLabelKey(code: string): string {
return BATCH_LIFECYCLE_I18N_KEYS[code] || code;
}
function selectLifecycleFilter(code: 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'upload_complete') {
function selectLifecycleFilter(code: 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'freight_upload' | 'upload_complete') {
lifecycleFilter.value = lifecycleFilter.value === code ? 'all' : code;
}
/** 阶段卡仅展示后端统计总数;状态、阻塞和推进语义由颜色与边框表达。 */
function stageTotalText(node: NonNullable<typeof batchFourStageNodes.value>[number]): string {
function stageTotalText(node: NonNullable<typeof batchLifecycleNodes.value>[number]): string {
return String(Number(node.summary?.total || 0));
}
/** 下载资格仅来自后端 output_artifacts 的授权动作;筛选仅影响展示,不缩减授权集合。 */
@@ -1024,15 +1027,15 @@ watch(
/>
</div>
</div>
<section v-if="batchFourStageNodes.length" class="mb-4 border-b border-default pb-4" data-testid="shipping-workflow-four-stage-progress">
<div class="grid grid-cols-4 gap-2">
<button v-for="node in batchFourStageNodes" :key="node.code" type="button" class="rounded-lg border px-2 py-2 text-left text-xs transition-colors" :class="[node.status === 'passed' ? 'border-emerald-200 bg-emerald-50 text-emerald-800' : node.status === 'blocked' ? 'border-amber-300 bg-amber-50 text-amber-800' : node.status === 'running' ? 'border-brand-300 bg-brand-50 text-brand-800' : 'border-default bg-surface-muted text-secondary', lifecycleFilter === node.code ? 'ring-2 ring-brand-400 ring-offset-1' : 'hover:brightness-95']" :data-testid="`shipping-workflow-stage-filter-${node.code}`" @click="selectLifecycleFilter(node.code)">
<span class="block font-semibold">{{ t(`chat.shippingNoticeUi.stage.${batchFourStageLabelKey(node.code)}`) }}</span>
<section v-if="batchLifecycleNodes.length" class="mb-4 border-b border-default pb-4" data-testid="shipping-workflow-lifecycle-progress">
<div class="grid grid-cols-2 gap-2 sm:grid-cols-5">
<button v-for="node in batchLifecycleNodes" :key="node.code" type="button" class="rounded-lg border px-2 py-2 text-left text-xs transition-colors" :class="[node.status === 'passed' ? 'border-emerald-200 bg-emerald-50 text-emerald-800' : node.status === 'blocked' ? 'border-amber-300 bg-amber-50 text-amber-800' : node.status === 'running' ? 'border-brand-300 bg-brand-50 text-brand-800' : 'border-default bg-surface-muted text-secondary', lifecycleFilter === node.code ? 'ring-2 ring-brand-400 ring-offset-1' : 'hover:brightness-95']" :data-testid="`shipping-workflow-stage-filter-${node.code}`" @click="selectLifecycleFilter(node.code)">
<span class="block font-semibold">{{ t(`chat.shippingNoticeUi.stage.${batchLifecycleLabelKey(node.code)}`) }}</span>
<span class="mt-0.5 block text-[11px] opacity-80">{{ stageTotalText(node) }}</span>
</button>
</div>
<div v-if="lifecycleFilter !== 'all'" class="mt-2 flex items-center justify-between gap-2 text-xs text-secondary">
<span>{{ t('chat.shippingProcessing.batchWorkbench.filteringByStage', { stage: t(`chat.shippingNoticeUi.stage.${batchFourStageLabelKey(lifecycleFilter)}`) }) }}</span>
<span>{{ t('chat.shippingProcessing.batchWorkbench.filteringByStage', { stage: t(`chat.shippingNoticeUi.stage.${batchLifecycleLabelKey(lifecycleFilter)}`) }) }}</span>
<button type="button" class="text-brand-700 hover:underline" data-testid="shipping-workflow-clear-stage-filter" @click="lifecycleFilter = 'all'">{{ t('chat.shippingProcessing.batchWorkbench.clearStageFilter') }}</button>
</div>
<p v-if="Number(displayProcessing?.unclassified_summary?.count || 0) > 0" class="mt-2 text-xs text-amber-700" data-testid="shipping-workflow-unclassified-summary">
@@ -1048,7 +1051,7 @@ watch(
<span class="sr-only">{{ t('chat.shippingProcessing.batchWorkbench.search.label') }}</span>
<input v-model="fileSearchQuery" type="search" class="w-full rounded-md border border-default bg-surface px-2.5 py-1.5 text-xs" :placeholder="t('chat.shippingProcessing.batchWorkbench.search.placeholder')" data-testid="shipping-workflow-file-search">
</label>
<div v-if="lifecycleFilter === 'upload_complete' && downloadableTaskNos.length" class="flex flex-wrap items-center gap-2" data-testid="shipping-workflow-download-toolbar">
<div v-if="lifecycleFilter === 'freight_upload' && downloadableTaskNos.length" class="flex flex-wrap items-center gap-2" data-testid="shipping-workflow-download-toolbar">
<label class="inline-flex items-center gap-1 text-xs text-secondary"><input type="checkbox" :checked="allDownloadableSelected" data-testid="shipping-workflow-download-select-all" @change="toggleAllDownloadSelections"><span>{{ t('chat.shippingProcessing.batchWorkbench.artifacts.selectAll') }}</span></label>
<span class="text-xs text-secondary">{{ t('chat.shippingProcessing.batchWorkbench.artifacts.selected', { count: selectedDownloadTaskNos.length }) }}</span>
<button type="button" class="rounded-md border border-brand-300 px-2.5 py-1 text-xs font-medium text-brand-700 disabled:opacity-50" :disabled="!selectedDownloadTaskNos.length" data-testid="shipping-workflow-download-selected" @click="downloadSelectedBatchArtifacts">{{ t('chat.shippingProcessing.batchWorkbench.artifacts.downloadSelected') }}</button>