refactor(chat/shipping): 重构发货通知模块为统一UI State驱动模式
- 重构发货通知的状态与动作获取逻辑:移除从聊天文本解析HXOPS_SHIPPING_ACTIONS注释的旧逻辑,改为统一从后端shipping_ui_state获取任务状态、动作按钮与工作流步骤 - 新增SSE实时推送shipping_ui_state事件,支持前端即时更新聊天气泡与工作台的状态与按钮 - 优化路由与登录流程:调整根路径重定向逻辑,退出登录时跳转到登录页;移除chat路由不必要的props传参;将原路由守卫中的根路径判断迁移到路由配置中 - 完善库存RPA与本地导入流程:新增本地库存文件托管接口,优化RPA回调的文件落盘与任务关联逻辑 - 新增多组单元测试覆盖焦点切换、决策处理、SSE同步等核心场景 - 修复多语言显示逻辑,使用te方法判断翻译key是否存在,避免缺失翻译时的渲染异常 - 新增reparse_inventory菜单动作,支持静默重新解析库存且不追加额外聊天消息 - 重构工作流步骤渲染函数,优先使用后端返回的步骤数据, fallback到本地推导的旧逻辑 - 清理后端旧的chat-actions API接口,将相关逻辑迁移到统一的ui_state接口中
This commit is contained in:
commit
9c036c825b
39 files changed
+3114
-456
No files matched your search
@@ -19,6 +19,13 @@ export interface ShippingWorkflowStepItem {
|
||||
status: 'completed' | 'current' | 'pending' | 'blocked';
|
||||
}
|
||||
|
||||
type ShippingWorkflowStepSource = {
|
||||
id?: string | null;
|
||||
code?: string | null;
|
||||
label?: string | null;
|
||||
status?: string | null;
|
||||
};
|
||||
|
||||
export const SHIPPING_WORKFLOW_STEP_LABELS = [
|
||||
'chat.shippingNoticeUi.stepper.noticeSubmit',
|
||||
'chat.shippingNoticeUi.stepper.parseConfirm',
|
||||
@@ -46,6 +53,44 @@ const CURRENT_STEP_INDEX_MAP: Record<string, number> = {
|
||||
};
|
||||
|
||||
const TERMINAL_PROCESS_STATUSES = new Set(['uploaded', 'closed']);
|
||||
const WORKFLOW_STEP_STATUSES = new Set<ShippingWorkflowStepItem['status']>([
|
||||
'completed',
|
||||
'current',
|
||||
'pending',
|
||||
'blocked',
|
||||
]);
|
||||
|
||||
/**
|
||||
* 将后端 UI State steps 收窄为 Stepper 可渲染的前端结构。
|
||||
*/
|
||||
export function normalizeShippingWorkflowSteps(
|
||||
steps: ShippingWorkflowStepSource[] | null | undefined,
|
||||
): ShippingWorkflowStepItem[] {
|
||||
if (!Array.isArray(steps)) return [];
|
||||
return steps
|
||||
.map((step, index) => {
|
||||
const status = String(step?.status || '').trim();
|
||||
if (!WORKFLOW_STEP_STATUSES.has(status as ShippingWorkflowStepItem['status'])) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
id: String(step?.id || step?.code || `shipping-step-${index + 1}`),
|
||||
label: String(step?.label || SHIPPING_WORKFLOW_STEP_LABELS[index] || ''),
|
||||
status: status as ShippingWorkflowStepItem['status'],
|
||||
};
|
||||
})
|
||||
.filter((step): step is ShippingWorkflowStepItem => !!step);
|
||||
}
|
||||
|
||||
/**
|
||||
* 优先消费后端状态机 UI State steps;没有时按 task 状态本地推导。
|
||||
*/
|
||||
export function resolveShippingWorkflowSteps(
|
||||
task: (ShippingTaskStepperSource & { ui_state?: { steps?: ShippingWorkflowStepSource[] | null } | null }) | null | undefined,
|
||||
): ShippingWorkflowStepItem[] {
|
||||
const uiStateSteps = normalizeShippingWorkflowSteps(task?.ui_state?.steps);
|
||||
return uiStateSteps.length ? uiStateSteps : buildShippingWorkflowSteps(task);
|
||||
}
|
||||
|
||||
function deriveCurrentIndex(task: ShippingTaskStepperSource | null | undefined): number {
|
||||
const currentStep = String(task?.current_step || '').trim();
|
||||
|
||||
Reference in new issue
Block a user