feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-06 10:18:37 +08:00
1 parent 3a9fbac2fc
commit d2b3d74def
571 files changed
+78064 -24681

No files matched your search

@@ -0,0 +1,77 @@
/**
* features/shipping-progress/actionPresentation.spec.ts
* 用途:验收统一动作优先级与自动态空主按钮。
*/
import { describe, expect, it } from 'vitest';
import type { ShippingProcessingProjection } from '@/features/chat/types/shipping.api.types';
import { resolveProcessingActionPresentation } from './actionPresentation';
function projection(
overrides: Partial<ShippingProcessingProjection> = {},
): ShippingProcessingProjection {
return {
workItemType: 'order_task',
workItemNo: 'OT-1',
sourceType: 'eml',
rootOrderTaskNo: 'OT-1',
shippingNoticeNo: null,
conversationId: 'c1',
submissionNo: 'SOS-1',
intakeNo: 'SNI-1',
status: 'blocked',
stage: 'inventory_source_resolving',
progressVersion: 1,
lastActivityAt: '2026-08-05T00:00:00Z',
currentGate: null,
availableActions: [],
sourceSummary: {
emailSubject: null,
filename: 'a.pdf',
documentCount: 1,
parsedDocumentCount: 1,
candidateCount: 1,
customerName: null,
poNumber: null,
},
childOrderTasks: [],
...overrides,
};
}
describe('resolveProcessingActionPresentation', () => {
it('prefers gate nextActionCode as primary', () => {
const result = resolveProcessingActionPresentation(projection({
currentGate: {
gateCode: 'inventory_source_routing',
status: 'blocked',
nextActionCode: 'open_inventory_source_review',
blockingReasonCode: 'no_inventory_source_candidates',
attemptNo: 1,
},
availableActions: ['refresh', 'retry'],
}));
expect(result.primary?.intent).toBe('open_inventory_source_review');
expect(result.secondary?.intent).toBe('refresh');
expect(result.overflow.map((i) => i.intent)).toContain('retry');
});
it('hides primary while automating without gate', () => {
const result = resolveProcessingActionPresentation(projection({
status: 'automating',
stage: 'freight_uploading',
availableActions: ['refresh'],
}));
expect(result.primary).toBeNull();
});
it('maps retry_parse to retry intent', () => {
const result = resolveProcessingActionPresentation(projection({
status: 'failed',
stage: 'document_parsing',
availableActions: ['retry_parse'],
}));
expect(result.primary?.intent).toBe('retry');
expect(result.primary?.actionCode).toBe('retry_parse');
});
});
@@ -0,0 +1,112 @@
/**
* features/shipping-progress/actionPresentation.ts
* 用途:从统一投影解析四页面共用的 ActionPresentation(主/次/溢出)。
* 依赖:ShippingProcessingProjection、SHIPPING_PROCESSING_ACTION_INTENTS、types。
* 逻辑:优先级 Gate.nextActionCode → availableActions → 终态查看 → none;
* 自动处理中(processing/automating)主按钮为空,避免误导性 CTA。
*/
import type {
ShippingProcessingActionIntent,
ShippingProcessingProjection,
} from '@/features/chat/types/shipping.api.types';
import type { ActionPresentation, ActionPresentationItem } from './types';
/** 可映射为统一意图的原始动作码(gate / available_actions)。 */
const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
open_order_review: 'open_order_review',
open_review: 'open_order_review',
edit_formal_task: 'edit_formal_task',
open_inventory_source_review: 'open_inventory_source_review',
open_inventory_match_review: 'open_inventory_match_review',
open_shortage_review: 'open_shortage_review',
upload_inventory_file: 'upload_inventory_file',
retry: 'retry',
retry_parse: 'retry',
refresh: 'refresh',
regenerate_excel: 'regenerate_excel',
download_excel: 'download_excel',
open_manual_upload: 'open_manual_upload',
wait_manual_upload: 'open_manual_upload',
mark_manual_uploaded: 'open_manual_upload',
regenerate_manual_upload_todo: 'open_manual_upload',
view_result: 'view_result',
view_details: 'view_result',
view_record: 'view_record',
};
const AUTOMATING_STATUSES = new Set(['processing', 'automating', 'queued']);
/**
* 将原始动作码映射为统一意图;未知码返回 null。
*/
export function mapActionCodeToIntent(code: string | null | undefined): ShippingProcessingActionIntent | null {
const normalized = String(code || '').trim().toLowerCase();
if (!normalized) return null;
return ACTION_CODE_TO_INTENT[normalized] || null;
}
/**
* 构建单个动作项。
*/
function toItem(code: string, intent: ShippingProcessingActionIntent): ActionPresentationItem {
return {
intent,
actionCode: code,
labelKey: `chat.shippingProcessing.action.${intent}`,
};
}
/**
* 解析统一动作投影。
*
* 核心逻辑:
* 1. processing/automating/queued → 主按钮为空(自动推进中);
* 2. currentGate.nextActionCode 优先;
* 3. availableActions 依次填主/次/溢出;
* 4. completed/failed/cancelled → view_result / view_record 兜底。
*/
export function resolveProcessingActionPresentation(
projection: ShippingProcessingProjection | null | undefined,
): ActionPresentation {
const empty: ActionPresentation = { primary: null, secondary: null, overflow: [] };
if (!projection) return empty;
const status = String(projection.status || '').trim().toLowerCase();
if (AUTOMATING_STATUSES.has(status) && !projection.currentGate?.nextActionCode) {
return empty;
}
const items: ActionPresentationItem[] = [];
const seen = new Set<string>();
const pushCode = (raw: string | null | undefined) => {
const code = String(raw || '').trim();
if (!code) return;
const key = code.toLowerCase();
if (seen.has(key)) return;
const intent = mapActionCodeToIntent(code);
if (!intent || intent === 'none') return;
seen.add(key);
items.push(toItem(code, intent));
};
pushCode(projection.currentGate?.nextActionCode);
for (const action of projection.availableActions || []) {
pushCode(action);
}
if (items.length === 0 && (status === 'completed' || status === 'failed' || status === 'cancelled')) {
pushCode('view_result');
}
if (AUTOMATING_STATUSES.has(status) && items.length === 0) {
return empty;
}
return {
primary: items[0] || null,
secondary: items[1] || null,
overflow: items.slice(2),
};
}
@@ -0,0 +1,97 @@
<!--
features/shipping-progress/components/UnifiedActionBar.vue
用途:统一主/次/溢出动作栏;四页面禁止自行按 status 拼按钮。
依赖:vue-i18n、ActionPresentation、shippingProcessingLabels。
逻辑:挂载于进度轨道下方;点击仅 emit intent+actionCode,由宿主执行导航/写操作。
-->
<script setup lang="ts">
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import type { ActionPresentation, ActionPresentationItem } from '../types';
const props = defineProps<{
presentation: ActionPresentation;
}>();
const emit = defineEmits<{
action: [item: ActionPresentationItem];
}>();
const { t, te } = useI18n();
const hasAny = computed(() => Boolean(
props.presentation.primary
|| props.presentation.secondary
|| props.presentation.overflow.length,
));
/**
* 解析动作文案。
*/
function labelOf(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 item.actionCode;
}
/**
* 触发宿主动作。
*/
function onClick(item: ActionPresentationItem | null) {
if (!item) return;
emit('action', item);
}
</script>
<template>
<div
v-if="hasAny"
class="flex flex-wrap items-center gap-2"
data-testid="unified-action-bar"
>
<button
v-if="presentation.primary"
type="button"
class="rounded-xl bg-brand-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-brand-700"
data-testid="unified-action-primary"
:data-intent="presentation.primary.intent"
@click="onClick(presentation.primary)"
>
{{ labelOf(presentation.primary) }}
</button>
<button
v-if="presentation.secondary"
type="button"
class="rounded-xl border border-default bg-surface px-3 py-1.5 text-xs font-semibold text-ink hover:bg-surface-muted"
data-testid="unified-action-secondary"
:data-intent="presentation.secondary.intent"
@click="onClick(presentation.secondary)"
>
{{ labelOf(presentation.secondary) }}
</button>
<details
v-if="presentation.overflow.length"
class="relative"
data-testid="unified-action-overflow"
>
<summary
class="cursor-pointer list-none rounded-xl border border-default bg-surface px-3 py-1.5 text-xs font-semibold text-muted"
>
{{ t('chat.shippingProcessing.action.more') }}
</summary>
<div class="absolute z-10 mt-1 min-w-[10rem] rounded-xl border border-default bg-surface p-1 shadow-md">
<button
v-for="item in presentation.overflow"
:key="`${item.intent}-${item.actionCode}`"
type="button"
class="block w-full rounded-lg px-3 py-1.5 text-left text-xs hover:bg-surface-muted"
:data-intent="item.intent"
@click="onClick(item)"
>
{{ labelOf(item) }}
</button>
</div>
</details>
</div>
</template>
@@ -0,0 +1,105 @@
<!--
features/shipping-progress/components/UnifiedProgressTrack.vue
用途:四页面共用的统一 15 阶进度轨道(按密度窗口渲染)。
依赖:vue-i18n、ShippingProcessingProjection、progressWindow、shippingProcessingLabels。
逻辑:由复核/对话/任务台挂载;节点态只读投影;不执行写操作。
-->
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import type { ShippingProcessingProjection } from '@/features/chat/types/shipping.api.types';
import { shippingProcessingStageKey } from '@/features/chat/shipping/shippingProcessingLabels';
import { buildProgressWindow } from '../progressWindow';
import { useProgressDensity } from '../composables/useProgressDensity';
import type { ProgressDensity, ProgressWindowNode } from '../types';
const props = defineProps<{
projection: ShippingProcessingProjection | null | undefined;
/** 强制密度;缺省时按容器宽度推断。 */
density?: ProgressDensity | null;
compact?: boolean;
}>();
const { t, te } = useI18n();
const rootRef = ref<HTMLElement | null>(null);
const densityRef = useProgressDensity(rootRef, props.density ?? null);
const nodes = computed(() => buildProgressWindow(props.projection, densityRef.value));
/**
* 节点展示文案。
*/
function nodeLabel(node: ProgressWindowNode): string {
const key = shippingProcessingStageKey(node.stage);
return te(key) ? t(key) : node.stage;
}
/**
* 节点视觉样式。
*/
function nodeClass(status: ProgressWindowNode['status']): string {
if (status === 'passed') return 'border-emerald-200 bg-emerald-50 text-emerald-700';
if (status === 'running') return 'border-brand-300 bg-brand-50 text-brand-700';
if (status === 'blocked') return 'border-amber-300 bg-amber-50 text-amber-800';
if (status === 'failed') return 'border-rose-200 bg-rose-50 text-rose-700';
if (status === 'skipped') return 'border-dashed border-default bg-surface/60 text-muted opacity-60';
return 'border-default bg-surface text-muted';
}
function dotClass(status: ProgressWindowNode['status']): string {
if (status === 'passed') return 'bg-emerald-500';
if (status === 'running') return 'bg-brand-500';
if (status === 'blocked') return 'bg-amber-500';
if (status === 'failed') return 'bg-rose-500';
if (status === 'skipped') return 'bg-slate-200';
return 'bg-slate-300';
}
</script>
<template>
<div
ref="rootRef"
class="space-y-2"
data-testid="unified-progress-track"
:data-density="densityRef"
>
<div
class="text-[11px] font-semibold uppercase tracking-[0.18em] text-muted"
>
{{ t('chat.shippingProcessing.panelTitle') }}
</div>
<div
v-if="nodes.length"
class="grid gap-2"
:class="compact ? 'sm:grid-cols-3 xl:grid-cols-5' : 'md:grid-cols-4 xl:grid-cols-6'"
>
<div
v-for="node in nodes"
:key="node.stage"
class="rounded-2xl border px-3 py-2.5 transition"
:class="nodeClass(node.status)"
:data-stage="node.stage"
:data-state="node.status"
:data-current="node.isCurrent ? 'true' : 'false'"
data-testid="unified-progress-node"
>
<div class="flex items-center gap-2">
<span
class="inline-flex h-5 min-w-5 items-center justify-center rounded-full text-[11px] font-semibold text-white"
:class="dotClass(node.status)"
>
{{ node.absoluteIndex + 1 }}
</span>
<span class="text-xs font-semibold leading-snug">{{ nodeLabel(node) }}</span>
</div>
</div>
</div>
<p
v-else
class="text-xs text-muted"
data-testid="unified-progress-empty"
>
{{ t('chat.shippingProcessing.status.processing') }}
</p>
</div>
</template>
@@ -0,0 +1,21 @@
/**
* features/shipping-progress/composables/useProcessingActionPresentation.ts
* 用途:包装 resolveProcessingActionPresentation,供 Vue 组件消费。
* 依赖:vue computed、actionPresentation、ShippingProcessingProjection。
* 逻辑:投影变化时重算;页面禁止自行按 status/stage 拼按钮。
*/
import { computed, type ComputedRef, type Ref } from 'vue';
import type { ShippingProcessingProjection } from '@/features/chat/types/shipping.api.types';
import { resolveProcessingActionPresentation } from '../actionPresentation';
import type { ActionPresentation } from '../types';
/**
* 从投影 ref 得到响应式 ActionPresentation。
*/
export function useProcessingActionPresentation(
projection: Ref<ShippingProcessingProjection | null | undefined>
| ComputedRef<ShippingProcessingProjection | null | undefined>,
): ComputedRef<ActionPresentation> {
return computed(() => resolveProcessingActionPresentation(projection.value));
}
@@ -0,0 +1,58 @@
/**
* features/shipping-progress/composables/useProgressDensity.ts
* 用途:按容器宽度推断进度密度(chat/right/review/workbench)。
* 依赖:Vue ref / onMounted / ResizeObserver、types ProgressDensity。
* 逻辑:宿主可传入强制 density;否则按宽度档位:≤360 chat、≤640 right、≤1100 review、否则 workbench。
*/
import { onBeforeUnmount, onMounted, ref, type Ref } from 'vue';
import type { ProgressDensity } from '../types';
/**
* 根据像素宽度映射密度。
*/
export function densityFromWidth(width: number): ProgressDensity {
if (width <= 360) return 'chat';
if (width <= 640) return 'right';
if (width <= 1100) return 'review';
return 'workbench';
}
/**
* 观察容器宽度并返回响应式密度。
*
* @param targetRef - 宿主元素 ref
* @param forced - 可选强制密度(复核/工作台固定窗口)
*/
export function useProgressDensity(
targetRef: Ref<HTMLElement | null>,
forced?: ProgressDensity | null,
): Ref<ProgressDensity> {
const density = ref<ProgressDensity>(forced || 'review');
let observer: ResizeObserver | null = null;
const measure = () => {
if (forced) {
density.value = forced;
return;
}
const el = targetRef.value;
const width = el?.clientWidth || 0;
density.value = densityFromWidth(width || 800);
};
onMounted(() => {
measure();
if (forced || typeof ResizeObserver === 'undefined') return;
observer = new ResizeObserver(() => measure());
if (targetRef.value) observer.observe(targetRef.value);
});
onBeforeUnmount(() => {
observer?.disconnect();
observer = null;
});
return density;
}
@@ -0,0 +1,83 @@
/**
* features/shipping-progress/progressWindow.spec.ts
* 用途:验收密度窗口切分与节点态推导。
*/
import { describe, expect, it } from 'vitest';
import type { ShippingProcessingProjection } from '@/features/chat/types/shipping.api.types';
import {
buildProgressWindow,
computeProgressWindowRange,
resolveStageNodeStatus,
stageAbsoluteIndex,
} from './progressWindow';
function baseProjection(
overrides: Partial<ShippingProcessingProjection> = {},
): ShippingProcessingProjection {
return {
workItemType: 'order_task',
workItemNo: 'OT-1',
sourceType: 'eml',
rootOrderTaskNo: 'OT-1',
shippingNoticeNo: null,
conversationId: 'c1',
submissionNo: 'SOS-1',
intakeNo: 'SNI-1',
status: 'blocked',
stage: 'inventory_source_resolving',
progressVersion: 1,
lastActivityAt: '2026-08-05T00:00:00Z',
currentGate: null,
availableActions: [],
sourceSummary: {
emailSubject: null,
filename: 'a.pdf',
documentCount: 1,
parsedDocumentCount: 1,
candidateCount: 1,
customerName: null,
poNumber: null,
},
childOrderTasks: [],
...overrides,
};
}
describe('progressWindow', () => {
it('anchors inventory_source_resolving at index 7', () => {
expect(stageAbsoluteIndex('inventory_source_resolving')).toBe(7);
});
it('workbench shows all 15 stages', () => {
const nodes = buildProgressWindow(baseProjection({ sourceType: 'eml' }), 'workbench');
expect(nodes).toHaveLength(15);
expect(nodes[7]?.isCurrent).toBe(true);
expect(nodes[7]?.status).toBe('blocked');
});
it('chat window stays within 3–5 visible nodes', () => {
const nodes = buildProgressWindow(baseProjection(), 'chat');
expect(nodes.length).toBeGreaterThanOrEqual(3);
expect(nodes.length).toBeLessThanOrEqual(5);
expect(nodes.some((n) => n.isCurrent)).toBe(true);
});
it('marks EML-only stages skipped for direct_pdf', () => {
const status = resolveStageNodeStatus({
absoluteIndex: 1,
currentIndex: 7,
projectionStatus: 'processing',
sourceType: 'direct_pdf',
stage: 'email_parsing',
});
expect(status).toBe('skipped');
});
it('centers window around current index', () => {
const { start, end } = computeProgressWindowRange(7, 'right', 15);
expect(end - start).toBe(6);
expect(start).toBeLessThanOrEqual(7);
expect(end).toBeGreaterThan(7);
});
});
@@ -0,0 +1,116 @@
/**
* features/shipping-progress/progressWindow.ts
* 用途:按密度从 15 阶中切出可见进度窗口,并推导节点执行态。
* 依赖:SHIPPING_PROCESSING_STAGES / EML_ONLY / types ProgressDensity。
* 逻辑:锚点为当前 stage;紧凑模式折叠窗口外节点与边缘 skipped;workbench 展示全 15 阶。
*/
import {
EML_ONLY_PROCESSING_STAGES,
SHIPPING_PROCESSING_STAGES,
type OrderIntakeSourceType,
type ShippingProcessingProjection,
type ShippingProcessingStage,
type ShippingProcessingStageNodeStatus,
type ShippingProcessingStatus,
} from '@/features/chat/types/shipping.api.types';
import {
PROGRESS_DENSITY_WINDOW_SIZE,
type ProgressDensity,
type ProgressWindowNode,
} from './types';
/**
* 返回 stage 在 15 阶中的下标;未知码回退 0。
*/
export function stageAbsoluteIndex(stage: string | null | undefined): number {
const code = String(stage || '').trim() as ShippingProcessingStage;
const idx = SHIPPING_PROCESSING_STAGES.indexOf(code);
return idx >= 0 ? idx : 0;
}
/**
* 推导单个节点执行态。
*
* 核心逻辑:direct_pdf 的 EML 专属阶 → skipped;当前阶按投影 status 映射;
* 已过阶 → passed;未到 → pending;失败/阻断仅落在当前阶。
*/
export function resolveStageNodeStatus(options: {
absoluteIndex: number;
currentIndex: number;
projectionStatus: ShippingProcessingStatus | string | null | undefined;
sourceType?: OrderIntakeSourceType | string | null;
stage: ShippingProcessingStage;
}): ShippingProcessingStageNodeStatus {
const source = String(options.sourceType || '').trim().toLowerCase();
if (source === 'direct_pdf' && EML_ONLY_PROCESSING_STAGES.has(options.stage)) {
return 'skipped';
}
if (options.absoluteIndex < options.currentIndex) return 'passed';
if (options.absoluteIndex > options.currentIndex) return 'pending';
const status = String(options.projectionStatus || '').trim().toLowerCase();
if (status === 'failed' || status === 'cancelled') return 'failed';
if (status === 'blocked' || status === 'needs_action' || status === 'waiting_review') {
return 'blocked';
}
if (status === 'completed' && options.stage === 'completed') return 'passed';
if (status === 'automating' || status === 'processing' || status === 'queued') return 'running';
return 'running';
}
/**
* 计算可见窗口的 [start, end) 下标(含当前)。
*/
export function computeProgressWindowRange(
currentIndex: number,
density: ProgressDensity,
total = SHIPPING_PROCESSING_STAGES.length,
): { start: number; end: number } {
const size = Math.min(PROGRESS_DENSITY_WINDOW_SIZE[density], total);
if (size >= total) return { start: 0, end: total };
let start = Math.max(0, currentIndex - Math.floor((size - 1) / 2));
let end = start + size;
if (end > total) {
end = total;
start = Math.max(0, end - size);
}
return { start, end };
}
/**
* 从统一投影构建密度窗口节点列表。
*
* @param projection - ShippingProcessingProjection;空则返回空列表
* @param density - 页面密度
*/
export function buildProgressWindow(
projection: ShippingProcessingProjection | null | undefined,
density: ProgressDensity,
): ProgressWindowNode[] {
if (!projection) return [];
const currentIndex = stageAbsoluteIndex(projection.stage);
const { start, end } = computeProgressWindowRange(currentIndex, density);
const sourceType = projection.sourceType || null;
const nodes: ProgressWindowNode[] = [];
for (let i = start; i < end; i += 1) {
const stage = SHIPPING_PROCESSING_STAGES[i]!;
nodes.push({
stage,
absoluteIndex: i,
isCurrent: i === currentIndex,
status: resolveStageNodeStatus({
absoluteIndex: i,
currentIndex,
projectionStatus: projection.status,
sourceType,
stage,
}),
});
}
// 紧凑模式:去掉窗口两端连续 skipped,避免空白占位。
if (density === 'chat' || density === 'right') {
while (nodes.length > 1 && nodes[0]?.status === 'skipped') nodes.shift();
while (nodes.length > 1 && nodes[nodes.length - 1]?.status === 'skipped') nodes.pop();
}
return nodes;
}
@@ -0,0 +1,49 @@
/**
* features/shipping-progress/types.ts
* 用途:统一进度轨道与动作栏的前端 DTO(密度、窗口节点、ActionPresentation)。
* 依赖:shipping.api.types 的 Stage / StageNodeStatus / ActionIntent。
* 逻辑:供 progressWindow / actionPresentation / Unified* 组件共用;禁止页面私自发明状态码。
*/
import type {
ShippingProcessingActionIntent,
ShippingProcessingStage,
ShippingProcessingStageNodeStatus,
} from '@/features/chat/types/shipping.api.types';
/** 四页面展示密度(决定可见节点数窗口)。 */
export type ProgressDensity = 'chat' | 'right' | 'review' | 'workbench';
/** 密度 → 目标可见节点数(含当前;skipped 在紧凑模式可折叠)。 */
export const PROGRESS_DENSITY_WINDOW_SIZE: Record<ProgressDensity, number> = {
chat: 4,
right: 6,
review: 12,
workbench: 15,
};
/** 进度窗口中的单个节点。 */
export interface ProgressWindowNode {
stage: ShippingProcessingStage;
/** 在完整 15 阶中的下标。 */
absoluteIndex: number;
status: ShippingProcessingStageNodeStatus;
/** 是否为当前投影 stage。 */
isCurrent: boolean;
}
/** 统一动作项(主/次/溢出)。 */
export interface ActionPresentationItem {
intent: ShippingProcessingActionIntent;
/** 原始 gate / available_actions 码,便于导航与提交。 */
actionCode: string;
/** i18n 键优先 chat.shippingProcessing.action.* */
labelKey: string;
}
/** 统一动作投影:四页面只消费本结构拼按钮。 */
export interface ActionPresentation {
primary: ActionPresentationItem | null;
secondary: ActionPresentationItem | null;
overflow: ActionPresentationItem[];
}