127 lines
4.4 KiB
TypeScript
127 lines
4.4 KiB
TypeScript
/**
|
|
* features/chat/shipping/shippingStepper.ts
|
|
* 用途:基于 shipping task 状态推导前端七步 Stepper 展示数据。
|
|
* 依赖:无外部模块;ShippingWorkflowStepper.vue 消费本模块输出。
|
|
* 逻辑:buildShippingWorkflowSteps 将 process_status / checkpoint 等映射为步骤 id 与 done/active 状态。
|
|
*/
|
|
export interface ShippingTaskStepperSource {
|
|
process_status?: string | null;
|
|
review_status?: string | null;
|
|
pending_human_reason?: string | null;
|
|
match_status?: string | null;
|
|
export_file_name?: string | null;
|
|
current_step?: string | null;
|
|
}
|
|
|
|
export interface ShippingWorkflowStepItem {
|
|
id: string;
|
|
label: string;
|
|
status: 'completed' | 'current' | 'pending' | 'blocked';
|
|
}
|
|
|
|
export const SHIPPING_WORKFLOW_STEP_LABELS = [
|
|
'chat.shippingNoticeUi.stepper.noticeSubmit',
|
|
'chat.shippingNoticeUi.stepper.parseConfirm',
|
|
'chat.shippingNoticeUi.stepper.inventoryPrepare',
|
|
'chat.shippingNoticeUi.stepper.alignConfirm',
|
|
'chat.shippingNoticeUi.stepper.matchInventory',
|
|
'chat.shippingNoticeUi.stepper.generateFile',
|
|
'chat.shippingNoticeUi.stepper.uploadFreight',
|
|
] as const;
|
|
|
|
const CURRENT_STEP_INDEX_MAP: Record<string, number> = {
|
|
step1_notice_submit: 0,
|
|
step2_parse_confirm: 1,
|
|
step3_inventory_prepare: 2,
|
|
step2_inventory_prepare: 2,
|
|
step4_align_confirm: 3,
|
|
step5_match_inventory: 4,
|
|
step3_inventory_match: 4,
|
|
step4_shortage_review: 4,
|
|
step6_generate_file: 5,
|
|
step5_export_excel: 5,
|
|
step7_upload_freight: 6,
|
|
step6_upload_freight: 6,
|
|
step7_finish: 6,
|
|
};
|
|
|
|
function deriveCurrentIndex(task: ShippingTaskStepperSource | null | undefined): number {
|
|
const currentStep = String(task?.current_step || '').trim();
|
|
const processStatus = String(task?.process_status || '').trim();
|
|
const reviewStatus = String(task?.review_status || '').trim();
|
|
const pendingReason = String(task?.pending_human_reason || '').trim();
|
|
const matchStatus = String(task?.match_status || '').trim();
|
|
const hasExport = !!String(task?.export_file_name || '').trim();
|
|
|
|
if (currentStep) {
|
|
const currentStepIndex = CURRENT_STEP_INDEX_MAP[currentStep];
|
|
if (currentStepIndex !== undefined) {
|
|
return currentStepIndex;
|
|
}
|
|
}
|
|
|
|
if (processStatus === 'uploaded' || processStatus === 'closed') return 6;
|
|
if (processStatus === 'waiting_upload' || processStatus === 'upload_failed' || hasExport) return 5;
|
|
if (processStatus === 'matched') return 4;
|
|
if (reviewStatus === 'shortage_review' || pendingReason === 'shortage_review' || pendingReason === 'shortage') return 4;
|
|
if (reviewStatus === 'align_review' || pendingReason === 'align_review') return 3;
|
|
if (processStatus === 'inventory_ready' || matchStatus) return 4;
|
|
if (
|
|
processStatus === 'waiting_inventory'
|
|
|| pendingReason === 'map_infer'
|
|
|| pendingReason === 'rpa_pending'
|
|
|| pendingReason === 'inv_unavail'
|
|
|| pendingReason === 'rpa_exhausted'
|
|
) {
|
|
return 2;
|
|
}
|
|
if (
|
|
processStatus === 'parsed'
|
|
|| processStatus === 'pending_review'
|
|
|| reviewStatus === 'pending_confirm'
|
|
|| reviewStatus === 'parse_review'
|
|
|| reviewStatus === 'rsv_required'
|
|
|| pendingReason === 'low_confidence'
|
|
|| pendingReason === 'rsv_required'
|
|
) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* 将 task 状态映射为七步 Stepper 项(id / label / done / active)。
|
|
*/
|
|
export function buildShippingWorkflowSteps(
|
|
task: ShippingTaskStepperSource | null | undefined,
|
|
): ShippingWorkflowStepItem[] {
|
|
const currentIndex = deriveCurrentIndex(task);
|
|
const reviewStatus = String(task?.review_status || '').trim();
|
|
const pendingReason = String(task?.pending_human_reason || '').trim();
|
|
const processStatus = String(task?.process_status || '').trim();
|
|
|
|
return SHIPPING_WORKFLOW_STEP_LABELS.map((label, index) => {
|
|
let status: ShippingWorkflowStepItem['status'] = 'pending';
|
|
if (index < currentIndex) {
|
|
status = 'completed';
|
|
} else if (index === currentIndex) {
|
|
status = 'current';
|
|
}
|
|
|
|
if (
|
|
(index === 1 && (reviewStatus === 'parse_review' || pendingReason === 'low_confidence' || pendingReason === 'rsv_required'))
|
|
|| (index === 3 && (reviewStatus === 'align_review' || pendingReason === 'align_review'))
|
|
|| (index === 4 && (reviewStatus === 'shortage_review' || pendingReason === 'shortage_review' || pendingReason === 'shortage'))
|
|
|| (index === 6 && processStatus === 'upload_failed')
|
|
) {
|
|
status = 'blocked';
|
|
}
|
|
|
|
return {
|
|
id: `shipping-step-${index + 1}`,
|
|
label,
|
|
status,
|
|
};
|
|
});
|
|
}
|