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,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;
}