feat(shipping-notice): 落地 XFA 统一视觉拆分确认门禁与处理投影收敛

闭合拆分预览令牌单次消费、样本 checksum 绑定与确认审计;正式提取改为 bindings-only。
同步统一标注工作台交互,并补齐进度投影/任务中心与迁移文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-06 10:21:25 +08:00
1 parent d2b3d74def
commit 84a881b554
195 files changed
+20269 -3463

No files matched your search

@@ -1,8 +1,8 @@
/**
* features/shipping-progress/progressWindow.ts
* 用途:按密度从 15 阶中切出可见进度窗口,并推导节点执行态。
* 依赖:SHIPPING_PROCESSING_STAGES / EML_ONLY / types ProgressDensity。
* 逻辑:锚点为当前 stage;紧凑模式折叠窗口外节点与边缘 skipped;workbench 展示全 15 阶。
* 用途:按密度从 15 阶中切出可见进度窗口,推导节点执行态,并提供订单台五域摘要。
* 依赖:SHIPPING_PROCESSING_STAGES / EML_ONLY / types ProgressDensity·ProgressDomain*、shippingProcessingLabels。
* 逻辑:锚点为当前 stage;stageNodes 优先;workbench=全 15 阶;五域供 ReviewProgressStrip 紧凑条。
*/
import {
@@ -14,12 +14,25 @@ import {
type ShippingProcessingStageNodeStatus,
type ShippingProcessingStatus,
} from '@/features/chat/types/shipping.api.types';
import { shippingProcessingStageKey } from '@/features/chat/shipping/shippingProcessingLabels';
import {
PROGRESS_DENSITY_WINDOW_SIZE,
type ProgressDensity,
type ProgressDomainState,
type ProgressDomainSummaryItem,
type ProgressRangeHint,
type ProgressWindowNode,
} from './types';
/** 订单处理工作台五域(0-based 含端点,对齐 15 阶)。 */
export const REVIEW_PROGRESS_DOMAIN_RANGES = [
{ key: 'receive_parse', labelKey: 'chat.shippingProcessing.progress.domainReceiveParse', start: 0, end: 2 },
{ key: 'candidate_identity', labelKey: 'chat.shippingProcessing.progress.domainCandidateIdentity', start: 3, end: 7 },
{ key: 'order_confirm', labelKey: 'chat.shippingProcessing.progress.domainOrderConfirm', start: 8, end: 9 },
{ key: 'inventory', labelKey: 'chat.shippingProcessing.progress.domainInventoryHandle', start: 10, end: 11 },
{ key: 'fulfillment', labelKey: 'chat.shippingProcessing.progress.domainFulfillmentShip', start: 12, end: 14 },
] as const;
/**
* 返回 stage 在 15 阶中的下标;未知码回退 0。
*/
@@ -29,10 +42,26 @@ export function stageAbsoluteIndex(stage: string | null | undefined): number {
return idx >= 0 ? idx : 0;
}
/**
* 从投影 stageNodes 查找指定阶的后端权威态。
*/
function resolveBackendNodeStatus(
projection: ShippingProcessingProjection,
stage: ShippingProcessingStage,
absoluteIndex: number,
): ShippingProcessingStageNodeStatus | null {
const nodes = projection.stageNodes;
if (!nodes?.length) return null;
const matched = nodes.find((node) => (
node.stage === stage || node.absoluteIndex === absoluteIndex
));
return matched?.status ?? null;
}
/**
* 推导单个节点执行态。
*
* 核心逻辑:direct_pdf 的 EML 专属阶 → skipped;当前阶按投影 status 映射;
* 核心逻辑:stageNodes 优先;direct_pdf 的 EML 专属阶 → skipped;当前阶按投影 status 映射;
* 已过阶 → passed;未到 → pending;失败/阻断仅落在当前阶。
*/
export function resolveStageNodeStatus(options: {
@@ -41,7 +70,9 @@ export function resolveStageNodeStatus(options: {
projectionStatus: ShippingProcessingStatus | string | null | undefined;
sourceType?: OrderIntakeSourceType | string | null;
stage: ShippingProcessingStage;
backendStatus?: ShippingProcessingStageNodeStatus | null;
}): ShippingProcessingStageNodeStatus {
if (options.backendStatus) return options.backendStatus;
const source = String(options.sourceType || '').trim().toLowerCase();
if (source === 'direct_pdf' && EML_ONLY_PROCESSING_STAGES.has(options.stage)) {
return 'skipped';
@@ -77,6 +108,25 @@ export function computeProgressWindowRange(
return { start, end };
}
/**
* 解析单阶节点态(供窗口与范围摘要共用)。
*/
function resolveProjectionStageStatus(
projection: ShippingProcessingProjection,
stage: ShippingProcessingStage,
absoluteIndex: number,
currentIndex: number,
): ShippingProcessingStageNodeStatus {
return resolveStageNodeStatus({
absoluteIndex,
currentIndex,
projectionStatus: projection.status,
sourceType: projection.sourceType,
stage,
backendStatus: resolveBackendNodeStatus(projection, stage, absoluteIndex),
});
}
/**
* 从统一投影构建密度窗口节点列表。
*
@@ -90,7 +140,6 @@ export function buildProgressWindow(
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]!;
@@ -98,13 +147,7 @@ export function buildProgressWindow(
stage,
absoluteIndex: i,
isCurrent: i === currentIndex,
status: resolveStageNodeStatus({
absoluteIndex: i,
currentIndex,
projectionStatus: projection.status,
sourceType,
stage,
}),
status: resolveProjectionStageStatus(projection, stage, i, currentIndex),
});
}
// 紧凑模式:去掉窗口两端连续 skipped,避免空白占位。
@@ -114,3 +157,77 @@ export function buildProgressWindow(
}
return nodes;
}
/**
* 构建进度范围摘要(已完成 n/total、当前阶段键、窗口外剩余阶数)。
*
* @param projection - 统一投影
* @param density - 页面密度(决定 hiddenAfter 计算窗口)
* @returns 摘要 DTO;无投影时 null
*/
export function buildProgressRangeHint(
projection: ShippingProcessingProjection | null | undefined,
density: ProgressDensity,
): ProgressRangeHint | null {
if (!projection) return null;
const currentIndex = stageAbsoluteIndex(projection.stage);
let done = 0;
let total = 0;
for (let i = 0; i < SHIPPING_PROCESSING_STAGES.length; i += 1) {
const stage = SHIPPING_PROCESSING_STAGES[i]!;
const status = resolveProjectionStageStatus(projection, stage, i, currentIndex);
if (status === 'skipped') continue;
total += 1;
if (status === 'passed') done += 1;
}
const { end } = computeProgressWindowRange(currentIndex, density);
const hiddenAfter = Math.max(0, SHIPPING_PROCESSING_STAGES.length - end);
return {
done,
total,
currentLabelKey: shippingProcessingStageKey(projection.stage),
hiddenAfter,
};
}
/**
* 构建订单处理工作台五域摘要(默认紧凑条用,非完整 15 阶)。
*
* 核心逻辑:当前索引落在域内 → current/blocked/failed;整域已过 → passed;否则 pending。
*/
export function buildReviewProgressDomainSummary(
projection: ShippingProcessingProjection | null | undefined,
): ProgressDomainSummaryItem[] {
if (!projection) return [];
const currentIndex = stageAbsoluteIndex(projection.stage);
const statusNorm = String(projection.status || '').trim().toLowerCase();
return REVIEW_PROGRESS_DOMAIN_RANGES.map((domain) => {
let state: ProgressDomainState = 'pending';
if (currentIndex > domain.end) {
state = 'passed';
} else if (currentIndex >= domain.start && currentIndex <= domain.end) {
if (statusNorm === 'failed' || statusNorm === 'cancelled') state = 'failed';
else if (statusNorm === 'blocked' || statusNorm === 'waiting_review' || statusNorm === 'needs_action') {
state = 'blocked';
} else {
state = 'current';
}
}
return {
key: domain.key,
labelKey: domain.labelKey,
start: domain.start,
end: domain.end,
state,
};
});
}
/**
* 构建完整 15 阶窗口(流程详情抽屉专用)。
*/
export function buildFullProgressNodes(
projection: ShippingProcessingProjection | null | undefined,
): ProgressWindowNode[] {
return buildProgressWindow(projection, 'workbench');
}