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:
hugo committed 2026-07-02 01:55:19 +08:00
commit 9c036c825b
39 files changed
+3114 -456

No files matched your search

@@ -25,7 +25,6 @@ import {
createShippingParseReviewHandlers,
createShippingSendHandlers,
createShippingUploadHandlers,
extractShippingActionsDirective,
findHistorySessionForShippingTask,
findLatestShippingTaskId,
getShippingInventoryMappingPayload,
@@ -42,6 +41,7 @@ import {
getWorkspaceShippingBatch,
getWorkspaceShippingTask,
switchWorkspaceShippingBatchFocusTask,
type ShippingBatchUiState,
type ShippingBatchSummary,
type ShippingConversationWorkspace,
type ShippingTaskDetail,
@@ -90,6 +90,34 @@ export interface UseChatShippingOptions {
createNewChatView: () => void;
}
/**
* 解析批次切换后的默认焦点状态。
* 核心逻辑:优先取状态机记录的 current focus,其次回退到 process summary 当前任务,再回退到任务列表首票;只有拿到 task_no 才回填默认聚焦原因。
* @param batchSummary - 当前批次摘要
* @param batchTasks - 当前批次任务列表
* @param defaultReason - 批次切换后写入输入栏提示的默认焦点原因
* @returns 供步骤条、按钮与右侧工作台共用的 focus 状态;取不到 task 时返回空焦点
*/
export const resolveShippingBatchFocusState = (
batchSummary: {
current_focus_task_no?: string | null;
process_summary?: { current_task_no?: string | null } | null;
} | null | undefined,
batchTasks: Array<{ task_no?: string | null }> | null | undefined,
defaultReason: string,
) => {
const taskNo = String(
batchSummary?.current_focus_task_no
|| batchSummary?.process_summary?.current_task_no
|| batchTasks?.[0]?.task_no
|| '',
).trim();
return {
taskNo,
focusReason: taskNo ? defaultReason : '',
};
};
/**
* 组装发货通知聊天所需的状态、动作处理器与发送拦截逻辑。
*
@@ -142,8 +170,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
const shippingInventorySelectionTaskId = ref('');
const prepareMarkdownDisplayText = (text: string) => {
const stripped = isShippingNoticeAgent.value ? extractShippingActionsDirective(text).cleanedText : text;
return sanitizeShippingConversationText(stripReasoningPrelude(stripped), isShippingNoticeAgent.value);
return sanitizeShippingConversationText(stripReasoningPrelude(text), isShippingNoticeAgent.value);
};
// ── 任务编号状态 ──────────────────────────────────────────
@@ -172,7 +199,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
let shippingStatusPollTimer: ReturnType<typeof setInterval> | null = null;
const applyShippingBatchDetail = (
detail: ShippingBatchSummary & { tasks?: ShippingTaskSummary[]; focus_task?: ShippingTaskSummary | null },
detail: ShippingBatchUiState,
fallbackBatchNo: string,
) => {
const normalizedBatchNo = detail.batch_no || fallbackBatchNo;
@@ -200,6 +227,15 @@ export function useChatShipping(options: UseChatShippingOptions) {
if (preferredTaskNo) {
resolvedShippingTaskId.value = preferredTaskNo;
}
if (detail.focus_task && detail.focus_task_ui_state) {
activeShippingTaskDetail.value = {
...(activeShippingTaskDetail.value || {}),
...detail.focus_task,
lines: activeShippingTaskDetail.value?.lines || [],
events: activeShippingTaskDetail.value?.events || [],
ui_state: detail.focus_task_ui_state,
} as ShippingTaskDetail;
}
};
const syncShippingBatchSummary = async (batchNo: string) => {
@@ -282,12 +318,14 @@ export function useChatShipping(options: UseChatShippingOptions) {
} else {
await syncShippingBatchSummary(normalizedBatchNo);
}
const nextTaskNo = String(
shippingBatchSummary.value?.current_focus_task_no
|| shippingBatchSummary.value?.process_summary?.current_task_no
|| shippingBatchTasks.value[0]?.task_no
|| '',
).trim();
const nextFocusState = resolveShippingBatchFocusState(
shippingBatchSummary.value,
shippingBatchTasks.value,
t('chat.shippingNoticeUi.currentFocusDefaultReason'),
);
const nextTaskNo = nextFocusState.taskNo;
focusedShippingTaskNo.value = nextFocusState.taskNo;
shippingFocusReason.value = nextFocusState.focusReason;
if (nextTaskNo) {
resolvedShippingTaskId.value = nextTaskNo;
await syncActiveShippingTaskDetail(nextTaskNo);