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

@@ -0,0 +1,93 @@
/**
* features/chat/shipping/useChatShippingMenuHandler.spec.ts
* 用途:验证发货通知聊天菜单动作分流,避免 UI 按钮误走普通对话链路。
* 依赖:vitest、vue refs、useChatShippingMenuHandler。
* 逻辑:直接调用 createShippingMenuHandlers,覆盖 reparse_inventory 的 silent 决策提交、缺少 task 提示与上传器打开条件。
*/
import { ref } from 'vue';
import { describe, expect, it, vi } from 'vitest';
import { createShippingMenuHandlers, type ShippingMenuHandlerContext } from './useChatShippingMenuHandler';
import type { ChatMessage } from '../types/chat.types';
const createContext = (
overrides: Partial<ShippingMenuHandlerContext> = {},
): ShippingMenuHandlerContext => ({
isThinking: ref(false),
getActiveShippingTaskId: () => 'SN-FOCUS-001',
messages: ref([]),
newLocalMessageId: vi.fn(() => 'local-id'),
saveLocalMessageToBackend: vi.fn(async () => undefined),
sendShippingMenuMessage: vi.fn(async () => undefined),
openShippingInventoryMappingFormForTask: vi.fn(async () => true),
openShippingInventoryPicker: vi.fn(() => true),
openShippingNoticePicker: vi.fn(() => true),
executeShippingDecision: vi.fn(async () => true),
executeShippingManualUpload: vi.fn(async () => true),
refreshShippingActions: vi.fn(async () => undefined),
msg: {
warning: vi.fn(),
info: vi.fn(),
},
t: (key: string) => key,
...overrides,
});
describe('useChatShippingMenuHandler', () => {
it('clears inventory state and opens picker for reparse_inventory without sending chat text', async () => {
const ctx = createContext();
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
const chatMsg = { role: 'assistant', content: '请重新上传库存' } as ChatMessage & { shipping_actions_used?: boolean };
await handleShippingMenuAction(
{ id: 'reparse_inventory', message: '重新上传库存' },
chatMsg,
);
expect(chatMsg.shipping_actions_used).toBe(true);
expect(ctx.executeShippingDecision).toHaveBeenCalledTimes(1);
expect(ctx.executeShippingDecision).toHaveBeenCalledWith('reparse_inventory', '重新上传库存', { silent: true });
expect(ctx.openShippingInventoryPicker).toHaveBeenCalledTimes(1);
expect(ctx.sendShippingMenuMessage).not.toHaveBeenCalled();
});
it('keeps existing missing task warning when reparse_inventory has no active task', async () => {
const ctx = createContext({
getActiveShippingTaskId: () => '',
});
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
await handleShippingMenuAction({ id: 'reparse_inventory', message: '重新上传库存' });
expect(ctx.msg.warning).toHaveBeenCalledWith('chat.shippingNoticeMissingTaskId');
expect(ctx.executeShippingDecision).not.toHaveBeenCalled();
expect(ctx.openShippingInventoryPicker).not.toHaveBeenCalled();
expect(ctx.sendShippingMenuMessage).not.toHaveBeenCalled();
});
it('does not open picker when reparse_inventory decision fails', async () => {
const ctx = createContext({
executeShippingDecision: vi.fn(async () => false),
});
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
await handleShippingMenuAction({ id: 'reparse_inventory', message: '重新上传库存' });
expect(ctx.executeShippingDecision).toHaveBeenCalledWith('reparse_inventory', '重新上传库存', { silent: true });
expect(ctx.openShippingInventoryPicker).not.toHaveBeenCalled();
expect(ctx.sendShippingMenuMessage).not.toHaveBeenCalled();
});
it('does not mark button used when reparse_inventory has no active task', async () => {
const ctx = createContext({
getActiveShippingTaskId: () => '',
});
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
const chatMsg = { role: 'assistant', content: '请重新上传库存' } as ChatMessage & { shipping_actions_used?: boolean };
await handleShippingMenuAction({ id: 'reparse_inventory', message: '重新上传库存' }, chatMsg);
expect(chatMsg.shipping_actions_used).toBeUndefined();
expect(ctx.executeShippingDecision).not.toHaveBeenCalled();
expect(ctx.openShippingInventoryPicker).not.toHaveBeenCalled();
});
});