refactor(shipping-ui): 收口订单复核与库存流程前端投影
This commit is contained in:
1 parent
265a6e179a
commit
4e8b2f8db2
27 files changed
+618
-407
No files matched your search
@@ -175,6 +175,7 @@ export function buildProcessingSemanticKey(
|
||||
summary: {
|
||||
total_tasks: projection.summary?.total_tasks || 0,
|
||||
total_files: projection.summary?.total_files || 0,
|
||||
submitted_files: projection.summary?.submitted_files || 0,
|
||||
processing: projection.summary?.processing || 0,
|
||||
needs_action: projection.summary?.needs_action || 0,
|
||||
completed: projection.summary?.completed || 0,
|
||||
@@ -1037,7 +1038,10 @@ export function normalizeConversationProcessingProjection(
|
||||
status_groups: normalizedGroups,
|
||||
lifecycle_nodes: projection.lifecycle_nodes || [],
|
||||
unclassified_summary: projection.unclassified_summary || { count: 0 },
|
||||
ui_state: projection.ui_state || undefined,
|
||||
// [AUTHORITY] 批次级 ui_state 与任务级 uiState 同为后端 snake_case DTO,必须统一
|
||||
// 归一化(blocking_reason/primary_action 增补 i18nKey;lifecycle_stage→lifecycleStage),
|
||||
// 否则三面阶段口径与工作台导航会读到两套字段名。
|
||||
ui_state: normalizeUiState(projection.ui_state) || undefined,
|
||||
output_artifacts: projection.output_artifacts || [],
|
||||
};
|
||||
}
|
||||
@@ -179,6 +179,7 @@ function normalizeLifecycleEntries(raw: unknown): NonNullable<ConversationProces
|
||||
function normalizeFacts(raw: unknown): ShippingProcessingFacts | undefined {
|
||||
if (!raw || typeof raw !== 'object') return undefined;
|
||||
const item = raw as Record<string, unknown>;
|
||||
const out: ShippingProcessingFacts = {};
|
||||
const toStrArr = (value: unknown): string[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value.map((c) => String(c ?? '').trim()).filter(Boolean);
|
||||
@@ -187,7 +188,12 @@ function normalizeFacts(raw: unknown): ShippingProcessingFacts | undefined {
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value.filter((row): row is Record<string, unknown> => Boolean(row) && typeof row === 'object');
|
||||
};
|
||||
const out: ShippingProcessingFacts = {};
|
||||
// 冻结选择计划中「已选但尚未物化/未识别」的附件诊断标记;仅 false 显式落盘,
|
||||
// 已识别/缺省不设 recognize,便于前端以 facts.recognized === false 识别未识别行。
|
||||
if (item.recognized === false) out.recognized = false;
|
||||
if (item.plan_state != null || item.planState != null) {
|
||||
out.planState = String(item.plan_state ?? item.planState);
|
||||
}
|
||||
if ('inventory_source_status' in item || 'inventorySourceStatus' in item) {
|
||||
out.inventorySourceStatus =
|
||||
item.inventory_source_status != null
|
||||
@@ -278,6 +284,7 @@ function normalizeAggregateSummary(
|
||||
return {
|
||||
intakeNo,
|
||||
total: count('total'),
|
||||
inGroup: count('in_group') || count('inGroup'),
|
||||
completed: count('completed'),
|
||||
processing: count('processing'),
|
||||
needsAction: count('needs_action') || count('needsAction'),
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
* features/chat/shipping/orderExtractionProgressDisplay.ts
|
||||
* 用途:订单抽取进度展示的纯函数(阶段文案 key、耗时格式化),禁止前端发明阶段码。
|
||||
* 依赖:无;由 ShippingOrderExtractionCard / ShippingWorkflowTimeline 调用。
|
||||
* 逻辑:仅映射后端投影字段到 i18n key 与可读耗时;阈值与阶段判定一律以后端为准。
|
||||
* 逻辑:仅映射后端投影字段到 i18n key 与可读耗时;阈值与阶段判定一律以后端为准;
|
||||
* v2 新增 run 级阶段/状态 key 唯一出口(任务中心与聊天卡同源,输出不变契约见 spec §5.5)。
|
||||
*/
|
||||
|
||||
/** 将秒数格式化为「Xm Ys」风格;空值返回空串。 */
|
||||
@@ -35,3 +36,20 @@ export function resolveOrderExtractionUserStageKey(
|
||||
if (status) return `chat.shippingOrderExtractionDocumentStatus.${status}`;
|
||||
return 'chat.shippingOrderExtractionActivity.generic_processing';
|
||||
}
|
||||
|
||||
/**
|
||||
* run 级阶段/状态展示 key 的唯一出口(任务中心「我的识别」与聊天抽取卡同源消费)。
|
||||
* 核心逻辑:有 user_visible_stage → UserStage 短语文案族;否则回退 run status 的
|
||||
* CardTitle 文案族。仅做事实→key 的受控映射,禁止发明新阶段码。
|
||||
* @param userVisibleStage - 后端 current_activity.user_visible_stage
|
||||
* @param runStatus - 后端 run.status(queued/processing/completed/…)
|
||||
* @returns i18n key(输出不变契约:与改造前页面内联字面量逐字一致)
|
||||
*/
|
||||
export function resolveOrderExtractionRunStageKey(
|
||||
userVisibleStage: string | null | undefined,
|
||||
runStatus: string,
|
||||
): string {
|
||||
const stage = String(userVisibleStage || '').trim();
|
||||
if (stage) return `chat.shippingOrderExtractionUserStage.${stage}`;
|
||||
return `chat.shippingOrderExtractionCardTitle.${String(runStatus || '').trim()}`;
|
||||
}
|
||||
@@ -3,8 +3,18 @@
|
||||
* 用途:将统一 ShippingProcessing 状态/阶段码映射到四语言 i18n 键。
|
||||
* 依赖:vue-i18n Composer(由调用方传入 t / te)。
|
||||
* 逻辑:统一读 chat.shippingProcessing.*;阶段展示优先消费后端 label_key
|
||||
* (如 waiting_system_start),禁止把 stage code 直接当用户文案。
|
||||
* (如 waiting_system_start),禁止把 stage code 直接当用户文案;
|
||||
* v2 新增 Run 级 lifecycle_progress 的状态兜底映射与动态说明解析
|
||||
* (设计:docs/superpowers/specs/2026-08-31-shipping-review-status-display-unification-design.md)。
|
||||
*/
|
||||
import type {
|
||||
ShippingOrderExtractionLifecycleProgress,
|
||||
ShippingUserProcessingStatus,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
import {
|
||||
LIFECYCLE_STAGE_LABEL_KEYS,
|
||||
mapProcessingStageToLifecycle,
|
||||
} from '@/features/shipping-progress/stageMapping';
|
||||
|
||||
/** 会话 processing 旧 status_label → 统一 ShippingProcessingStatus。 */
|
||||
const LEGACY_STATUS_TO_PROCESSING: Record<string, string> = {
|
||||
@@ -137,7 +147,16 @@ export function resolveShippingProcessingStageLabel(
|
||||
if (te(reviewKey)) return t(reviewKey);
|
||||
}
|
||||
const code = String(stage || '').trim();
|
||||
if (!code) return '—';
|
||||
if (!code) {
|
||||
// [契约 §1.1「当前门禁 —」] 已知正式 OT 必有阶段,投影恒有 stage/lifecycle_stage;
|
||||
// 投影未就绪由右卡 :loading 驱动骨架占位。此处禁止落「—」,改为统一的「获取中」占位文案,
|
||||
// 避免用户看到无信息的破折号。仍在无 stage 且非 loading(连降级阶段都没有)时中性呈现。
|
||||
const loadingKey = 'chat.shippingOrderReview.currentProcessing.stageLoading';
|
||||
if (te(loadingKey)) return t(loadingKey);
|
||||
const waitingKey = 'chat.shippingProcessing.stageLabel.waiting_system_start';
|
||||
if (te(waitingKey)) return t(waitingKey);
|
||||
return '正在获取最新状态…';
|
||||
}
|
||||
const stageKey = shippingProcessingStageKey(code);
|
||||
if (te(stageKey)) return t(stageKey);
|
||||
const reviewCodeKey = `chat.shippingOrderReview.currentProcessing.stages.${code}`;
|
||||
@@ -148,6 +167,57 @@ export function resolveShippingProcessingStageLabel(
|
||||
: '等待系统启动';
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析「5 业务阶段」用户文案(批次中心与工作台共用词汇)。
|
||||
*
|
||||
* 三方统一约定:内联卡、右侧批次中心、工作台只消费后端 ui_state.lifecycle_stage,
|
||||
* 映射 `chat.shippingNoticeUi.stage.<code>`(接收解析/订单复核/通知准备/货代上传/上传完成)。
|
||||
* 入参可能是 5 业务阶段码或旧 15 技术阶段码:非业务码时按共享映射聚拢,确保永不显示
|
||||
* “等待系统启动”这类技术阶段措辞。
|
||||
*
|
||||
* @param stage - ui_state.lifecycle_stage(业务码),或兼容的技术阶段码
|
||||
* @param te - i18n te
|
||||
* @param t - i18n t
|
||||
* @returns 本地化文案;未知码回退 `—`
|
||||
*/
|
||||
export function resolveShippingLifecycleStageLabel(
|
||||
stage: string | null | undefined,
|
||||
te: (key: string) => boolean,
|
||||
t: (key: string) => string,
|
||||
): string {
|
||||
const raw = String(stage || '').trim();
|
||||
if (!raw) return '—';
|
||||
const code = LIFECYCLE_STAGE_LABEL_KEYS[raw]
|
||||
? raw
|
||||
: mapProcessingStageToLifecycle(raw);
|
||||
const labelKey = LIFECYCLE_STAGE_LABEL_KEYS[code];
|
||||
const stageKey = `chat.shippingNoticeUi.stage.${labelKey}`;
|
||||
if (labelKey && te(stageKey)) return t(stageKey);
|
||||
return '—';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判定阻塞原因是否为「通用兜底」(应在行内隐藏,避免与状态芯片重复)。
|
||||
*
|
||||
* 三方约定:仅当下发到具体、非兜底的阻塞原因(有真实 i18n 文案)才展示原因行;
|
||||
* 进到 reasonCode.unknown / 无 i18n_key 的通用码一律视为重复信息。
|
||||
*
|
||||
* @param reason - 后端 blocking_reason(code / i18n_key)
|
||||
* @param te - i18n te
|
||||
* @returns true=通用兜底(应隐藏)
|
||||
*/
|
||||
export function isGenericBlockingReason(
|
||||
reason: { code?: string | null; i18nKey?: string | null; i18n_key?: string | null } | null | undefined,
|
||||
te: (key: string) => boolean,
|
||||
): boolean {
|
||||
if (!reason) return true;
|
||||
const i18nKey = String(reason.i18nKey || reason.i18n_key || '').trim();
|
||||
if (i18nKey && te(i18nKey)) return false;
|
||||
const code = String(reason.code || '').trim();
|
||||
if (code && code !== 'unknown' && te(`chat.shippingProcessing.reasonCode.${code}`)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析工作项类型文案键。
|
||||
* @param workItemType - order_intake | order_task
|
||||
@@ -171,3 +241,117 @@ export function shippingProcessingSourceTypeKey(sourceType: string): string {
|
||||
? `chat.shippingProcessing.sourceType.${code}`
|
||||
: 'chat.shippingProcessing.sourceType.eml';
|
||||
}
|
||||
|
||||
/** ========================================================================
|
||||
* v2(状态展示统一):Run 级 lifecycle_progress 的状态兜底与动态说明。
|
||||
* 仅消费后端下发码;受控常量禁止运行时扩充。
|
||||
* ======================================================================== */
|
||||
|
||||
/** lifecycle_status 白名单:白名单外(completed/未知)一律不产生说明与状态映射。 */
|
||||
const EXTRACTION_ACTIVITY_STATUS_ALLOWLIST = new Set(['running', 'waiting', 'failed', 'cancelled']);
|
||||
|
||||
/**
|
||||
* Run 级 lifecycle_status → 用户态兜底映射(spec §5.1)。
|
||||
* 核心逻辑:waiting + 表内原因码才补充/细化用户态;表外原因码不映射(维持待机)。
|
||||
* queue_backlog / processing_slow / processing_attention 属 health tip,可与 running 并存。
|
||||
*/
|
||||
const RUN_STATUS_FALLBACK_MAP: Readonly<Record<string, ShippingUserProcessingStatus>> = {
|
||||
review_required: 'waiting_human',
|
||||
queue_backlog: 'running',
|
||||
processing_slow: 'running',
|
||||
processing_attention: 'running',
|
||||
};
|
||||
|
||||
/**
|
||||
* 允许隐藏动态说明的原因码白名单(spec §5.2)。
|
||||
* 核心逻辑:仅登记"纯重复状态语义"的原因;排队/偏慢/需关注属诊断信息,一律保留说明。
|
||||
* review_required 若未来文案携带更具体原因,应移出本集合。
|
||||
*/
|
||||
const REDUNDANT_DETAIL_REASON_CODES: ReadonlySet<string> = new Set(['review_required']);
|
||||
|
||||
/**
|
||||
* 从 lifecycle_progress 提取受控原因码。
|
||||
* 核心逻辑:取 blocking_reason_i18n_key 末段(受控后缀解析),禁止模糊关键词匹配;
|
||||
* 仅认 RUN_STATUS_FALLBACK_MAP 登记过的码,其余一律空串。
|
||||
* @param progress - Run 级生命周期进度投影
|
||||
* @returns 原因码(如 review_required);无则空串
|
||||
*/
|
||||
export function extractExtractionProgressReasonCode(
|
||||
progress: ShippingOrderExtractionLifecycleProgress | null | undefined,
|
||||
): string {
|
||||
const key = String(progress?.blocking_reason_i18n_key || '').trim();
|
||||
if (!key) return '';
|
||||
const segment = key.split('.').pop() || '';
|
||||
return segment in RUN_STATUS_FALLBACK_MAP ? segment : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run 级 lifecycle_status → 用户态兜底(spec §5.1;仅供 currentTaskUserStatus 链尾使用)。
|
||||
* 核心逻辑:running/waiting/failed 才补充用户态;原因码只能"补充/细化",
|
||||
* 不能覆盖 failed/cancelled/completed;completed/cancelled/未知一律 null
|
||||
* (避免误伤本页 next-step 与按钮逻辑)。
|
||||
* @param progress - Run 级生命周期进度投影
|
||||
* @returns 用户态 6 值之一;无可兜底值时 null
|
||||
*/
|
||||
export function resolveRunLifecycleUserStatus(
|
||||
progress: ShippingOrderExtractionLifecycleProgress | null | undefined,
|
||||
): ShippingUserProcessingStatus | null {
|
||||
const status = String(progress?.lifecycle_status || '').trim().toLowerCase();
|
||||
if (status === 'running') return 'running';
|
||||
if (status === 'failed') return 'failed';
|
||||
if (status === 'waiting') {
|
||||
return RUN_STATUS_FALLBACK_MAP[extractExtractionProgressReasonCode(progress)] ?? null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 Run 级 lifecycle_progress 的一行动态说明(spec §5.2 detailMessage / §5.3 轻提示共用)。
|
||||
* 核心逻辑:白名单外(completed/未知)返回 null,绝不回退成"等待启动";
|
||||
* running 才可声称自动处理:诊断原因(health tip)优先于步骤句,缺省通用处理中;
|
||||
* waiting 只用原因句、缺省中性等待;failed/cancelled 强制原因 key,禁止复用 running 的 step 文案。
|
||||
* @param progress - Run 级生命周期进度投影
|
||||
* @param i18n - 调用方传入的 te / t
|
||||
* @returns 单行说明文本 + running 位;无可展示内容时 null
|
||||
*/
|
||||
export function resolveExtractionActivityMessage(
|
||||
progress: ShippingOrderExtractionLifecycleProgress | null | undefined,
|
||||
i18n: { te: (key: string) => boolean; t: (key: string) => string },
|
||||
): { text: string; running: boolean } | null {
|
||||
const status = String(progress?.lifecycle_status || '').trim().toLowerCase();
|
||||
if (!progress || !EXTRACTION_ACTIVITY_STATUS_ALLOWLIST.has(status)) return null;
|
||||
const { t, te } = i18n;
|
||||
const localized = (key: string | null | undefined): string => {
|
||||
const normalized = String(key || '').trim();
|
||||
return normalized && te(normalized) ? t(normalized) : '';
|
||||
};
|
||||
const stepText = localized(progress.current_step_i18n_key);
|
||||
const reasonText = localized(progress.blocking_reason_i18n_key);
|
||||
if (status === 'running') {
|
||||
return { text: reasonText || stepText || t('chat.shippingProcessing.progress.systemProcessingNeed'), running: true };
|
||||
}
|
||||
if (status === 'waiting') {
|
||||
return { text: reasonText || t('chat.shippingProcessing.progress.lifecycleWaitingNeed'), running: false };
|
||||
}
|
||||
const terminalKey = status === 'failed'
|
||||
? 'chat.shippingProcessing.progress.lifecycleReason.failed'
|
||||
: 'chat.shippingProcessing.progress.lifecycleReason.cancelled';
|
||||
return { text: te(terminalKey) ? t(terminalKey) : reasonText, running: false };
|
||||
}
|
||||
|
||||
/**
|
||||
* 判定动态说明是否属"纯重复"可隐藏(spec §5.2)。
|
||||
* 核心逻辑:仅白名单内原因码且其状态兜底映射结果 == 当前展示 user_status 才隐藏;
|
||||
* 未知原因默认保留;不做模糊匹配、不比较任何语言的渲染文本。
|
||||
* @param reasonCode - extractExtractionProgressReasonCode 的输出
|
||||
* @param userStatus - 当前展示的用户态
|
||||
* @returns true=隐藏说明行
|
||||
*/
|
||||
export function isRedundantExtractionDetail(
|
||||
reasonCode: string,
|
||||
userStatus: string | null | undefined,
|
||||
): boolean {
|
||||
const code = String(reasonCode || '').trim();
|
||||
if (!REDUNDANT_DETAIL_REASON_CODES.has(code)) return false;
|
||||
return RUN_STATUS_FALLBACK_MAP[code] === String(userStatus || '').trim();
|
||||
}
|
||||
@@ -208,7 +208,6 @@ export function mapServerCandidate(remote: ShippingNoticeCandidateResponse): Shi
|
||||
fieldAdjudication: remote.field_adjudication && typeof remote.field_adjudication === 'object'
|
||||
? remote.field_adjudication
|
||||
: null,
|
||||
customerMatches: Array.isArray(remote.customer_matches) ? remote.customer_matches : [],
|
||||
businessSummary: remote.business_summary || {},
|
||||
duplicate,
|
||||
duplicateResolution: remote.duplicate_resolution
|
||||
|
||||
@@ -25,6 +25,12 @@ const TERMINAL_STATUSES = new Set([
|
||||
'completed',
|
||||
'cancelled',
|
||||
]);
|
||||
/** 用户态“中断/失败/等待人工”状态:结果不会自行变化,停止轮询(约定:中断不轮询)。 */
|
||||
const INTERRUPTED_USER_STATUSES = new Set([
|
||||
'waiting_human',
|
||||
'failed',
|
||||
'interrupted',
|
||||
]);
|
||||
|
||||
export type ShippingProcessingWorkItemTypeArg = 'order_intake' | 'order_task';
|
||||
|
||||
@@ -115,7 +121,12 @@ export function useShippingProcessingWorkItem(
|
||||
error.value = null;
|
||||
clearTimer();
|
||||
const next = projection.value;
|
||||
if (continuousPolling && next && !TERMINAL_STATUSES.has(next.status) && !stopped) {
|
||||
const userStatus = String(next?.userStatus || '').trim().toLowerCase();
|
||||
const stoppedByState = Boolean(next) && (
|
||||
TERMINAL_STATUSES.has(next!.status)
|
||||
|| INTERRUPTED_USER_STATUSES.has(userStatus)
|
||||
);
|
||||
if (continuousPolling && next && !stoppedByState && !stopped) {
|
||||
timer = window.setTimeout(() => {
|
||||
void refresh();
|
||||
}, pollMs);
|
||||
|
||||
Reference in new issue
Block a user