Files
syops/frontend/src/features/chat/shipping/shippingProcessingLabels.ts
T
hugoandCursor fd6a23f870 feat(shipping-notice): 收敛复核阶段同源投影与 OT 后履约推进
统一 Case/Progress 阶段 label_key、修复 Job 成功未推进 OT 的可重试失败投影与写路径,并落地 OT 后行级匹配/波次履约与版面诊断开关。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 13:11:14 +08:00

152 lines
5.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* features/chat/shipping/shippingProcessingLabels.ts
* 用途:将统一 ShippingProcessing 状态/阶段码映射到四语言 i18n 键。
* 依赖:vue-i18n Composer(由调用方传入 t / te)。
* 逻辑:统一读 chat.shippingProcessing.*;阶段展示优先消费后端 label_key
* (如 waiting_system_start),禁止把 stage code 直接当用户文案。
*/
/** 会话 processing 旧 status_label → 统一 ShippingProcessingStatus。 */
const LEGACY_STATUS_TO_PROCESSING: Record<string, string> = {
queued: 'processing',
processing: 'processing',
pending_review: 'waiting_review',
waiting_review: 'waiting_review',
failed: 'failed',
completed: 'completed',
cancelled: 'cancelled',
cancelling: 'processing',
blocked: 'blocked',
automating: 'automating',
review_case_draft: 'waiting_review',
};
/**
* 解析统一处理状态的展示文案键。
* 核心逻辑:优先 `chat.shippingProcessing.status.<code>`。
* @param status - ShippingProcessingStatus 码
* @returns i18n key
*/
export function shippingProcessingStatusKey(status: string): string {
const code = String(status || '').trim();
const mapped = LEGACY_STATUS_TO_PROCESSING[code] || code;
return mapped
? `chat.shippingProcessing.status.${mapped}`
: 'chat.shippingProcessing.status.processing';
}
/**
* 解析任务状态展示文案。
*
* @param code - 后端 status / status_label
* @param te - i18n te
* @param t - i18n t
* @returns 本地化文案;皆无则回退原码
*/
export function resolveShippingProcessingStatusLabel(
code: string,
te: (key: string) => boolean,
t: (key: string) => string,
): string {
const raw = String(code || '').trim();
if (!raw) return '—';
const processingKey = shippingProcessingStatusKey(raw);
if (te(processingKey)) return t(processingKey);
const taskStatusKey = `chat.shippingProcessing.taskStatus.${raw}`;
if (te(taskStatusKey)) return t(taskStatusKey);
return raw;
}
/**
* 解析统一处理文案。
*
* @param leaf - 文案叶子键(如 groupNeedsAction)
* @param te - i18n te
* @param t - i18n t
* @param params - 插值参数
* @returns 本地化文案
*/
export function resolveShippingProcessingMessage(
leaf: string,
te: (key: string) => boolean,
t: (key: string, params?: Record<string, unknown>) => string,
params?: Record<string, unknown>,
): string {
const code = String(leaf || '').trim();
if (!code) return '';
const primary = `chat.shippingProcessing.${code}`;
if (te(primary)) return t(primary, params);
return code;
}
/**
* 解析统一处理阶段的展示文案键(技术阶段码)。
* @param stage - ShippingProcessingStage 码
* @returns i18n key
*/
export function shippingProcessingStageKey(stage: string): string {
const code = String(stage || '').trim();
return code
? `chat.shippingProcessing.stage.${code}`
: 'chat.shippingProcessing.stage.upload_received';
}
/**
* 解析阶段用户文案:优先后端 label_key,禁止直接展示 stage code。
* 核心逻辑:label_key → stageLabel.* / currentProcessing.stages.*;再回退 stage.*。
*
* @param stage - 技术阶段码
* @param te - i18n te
* @param t - i18n t
* @param labelKey - 后端投影 label_key(如 waiting_system_start)
* @returns 本地化文案
*/
export function resolveShippingProcessingStageLabel(
stage: string,
te: (key: string) => boolean,
t: (key: string) => string,
labelKey?: string | null,
): string {
const lk = String(labelKey || '').trim();
if (lk) {
const stageLabelKey = `chat.shippingProcessing.stageLabel.${lk}`;
if (te(stageLabelKey)) return t(stageLabelKey);
const reviewKey = `chat.shippingOrderReview.currentProcessing.stages.${lk}`;
if (te(reviewKey)) return t(reviewKey);
}
const code = String(stage || '').trim();
if (!code) return '—';
const stageKey = shippingProcessingStageKey(code);
if (te(stageKey)) return t(stageKey);
const reviewCodeKey = `chat.shippingOrderReview.currentProcessing.stages.${code}`;
if (te(reviewCodeKey)) return t(reviewCodeKey);
// 禁止把码当文案:无键时回退通用等待文案,而非裸 code。
return te('chat.shippingProcessing.stageLabel.waiting_system_start')
? t('chat.shippingProcessing.stageLabel.waiting_system_start')
: code;
}
/**
* 解析工作项类型文案键。
* @param workItemType - order_intake | order_task
* @returns i18n key
*/
export function shippingProcessingWorkItemTypeKey(workItemType: string): string {
const code = String(workItemType || '').trim();
return code
? `chat.shippingProcessing.workItemType.${code}`
: 'chat.shippingProcessing.workItemType.order_task';
}
/**
* 解析来源类型文案键(eml / direct_pdf)。
* @param sourceType - OrderIntakeSourceType
* @returns i18n key
*/
export function shippingProcessingSourceTypeKey(sourceType: string): string {
const code = String(sourceType || '').trim();
return code
? `chat.shippingProcessing.sourceType.${code}`
: 'chat.shippingProcessing.sourceType.eml';
}