feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码

This commit is contained in:
hugo committed 2026-08-23 00:27:18 +08:00
1 parent 935bf26fa6
commit 7cfd5d167e
230 files changed
+9337 -10989

No files matched your search

@@ -8,7 +8,6 @@ import { computed, ref } from 'vue';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { createChatPageConversationApi } from './useChatPageConversation';
import {
clearPendingNoticeBatchRetry,
createShippingUploadHandlers,
resetShippingNoticeBatchSubmitStateForTests,
type ShippingUploadHandlerContext,
@@ -49,13 +48,11 @@ const createConversationContext = () => {
messages.value = loaded;
},
createNewChatView,
clearPendingNoticeBatchRetry,
onConversationIdChanging: vi.fn(),
onConversationLoadedEmpty: vi.fn(async () => undefined),
onConversationLoadFailed: vi.fn(async () => undefined),
isShippingNoticeAgent: computed(() => true),
shippingTaskIdFromQuery: computed(() => ''),
shippingBatchNoFromQuery: computed(() => ''),
clearHistory: vi.fn(),
clearAttachments: vi.fn(),
input: ref(''),
@@ -86,9 +83,6 @@ const createUploadContext = (
pendingShippingNoticeTaskId: ref(''),
pendingShippingInventoryFile: ref(null),
resolvedShippingTaskId: ref(''),
resolvedShippingBatchNo: ref(''),
shippingBatchSummary: ref(null),
shippingBatchTasks: ref([]),
shippingInventorySelectionActive: ref(false),
shippingInventorySelectionTaskId: ref(''),
getActiveShippingTaskId: () => '',
@@ -17,13 +17,11 @@ export interface ChatPageConversationContext {
isThinking: Ref<boolean>;
loadConversationState: (id: string, loaded: ChatMessage[]) => void;
createNewChatView: () => void;
clearPendingNoticeBatchRetry: () => void;
onConversationIdChanging: (nextId: string, prevId: string | null | undefined) => void;
onConversationLoadedEmpty: () => Promise<void>;
onConversationLoadFailed: () => Promise<void>;
isShippingNoticeAgent: ComputedRef<boolean>;
shippingTaskIdFromQuery: ComputedRef<string>;
shippingBatchNoFromQuery?: ComputedRef<string>;
clearHistory: () => void;
clearAttachments: () => void;
input: Ref<string>;
@@ -98,7 +96,7 @@ export function createChatPageConversationApi(ctx: ChatPageConversationContext)
await ctx.onConversationLoadFailed();
if (
ctx.isShippingNoticeAgent.value
&& (ctx.shippingTaskIdFromQuery.value || ctx.shippingBatchNoFromQuery?.value)
&& ctx.shippingTaskIdFromQuery.value
&& !ctx.isThinking.value
) {
return;
@@ -108,7 +106,6 @@ export function createChatPageConversationApi(ctx: ChatPageConversationContext)
};
const startNewChat = () => {
ctx.clearPendingNoticeBatchRetry();
ctx.createNewChatView();
ctx.clearAttachments();
ctx.input.value = '';
@@ -122,7 +119,6 @@ export function createChatPageConversationApi(ctx: ChatPageConversationContext)
};
const resetChatStateForAgentChange = () => {
ctx.clearPendingNoticeBatchRetry();
ctx.createNewChatView();
ctx.clearHistory();
ctx.clearAttachments();
@@ -1,6 +1,6 @@
/**
* features/chat/page/useChatPageDialogs.ts
* 用途:对话页删除确认、发货「重试所有失败」确认、反馈弹窗与轻量 toast 状态。
* 用途:对话页删除确认、反馈弹窗与轻量 toast 状态。
* 依赖:vue computed/ref、chat.types。
* 逻辑:由 useChatPage 组装;ChatViewOverlays 绑定 DeleteConfirmDialog 与 toast 条。
*/
@@ -43,37 +43,6 @@ export function useChatPageDialogs(messages: Ref<ChatMessage[]>) {
closeDeleteConfirmDialog();
};
const showRetryFailedConfirmDialog = ref(false);
let pendingRetryFailedAction: (() => Promise<void> | void) | null = null;
/**
* 打开「重试所有失败」确认弹窗。
* 核心逻辑:仅登记确认后要执行的动作,实际请求由调用方注入。
* @param onConfirm - 用户点「确认重试」后执行的回调
*/
const openRetryFailedConfirm = (onConfirm: () => Promise<void> | void) => {
pendingRetryFailedAction = onConfirm;
showRetryFailedConfirmDialog.value = true;
};
/** 关闭重试确认弹窗并清空待执行动作。 */
const closeRetryFailedConfirm = () => {
showRetryFailedConfirmDialog.value = false;
pendingRetryFailedAction = null;
};
/**
* 用户确认后执行重试动作;弹窗由 DeleteConfirmDialog 自行关闭。
* 核心逻辑:取出并清空 pending,再 await 执行,避免重复确认。
*/
const handleRetryFailedConfirm = async () => {
const action = pendingRetryFailedAction;
pendingRetryFailedAction = null;
showRetryFailedConfirmDialog.value = false;
if (!action) return;
await action();
};
const shippingToastMessage = ref('');
let shippingToastTimer: ReturnType<typeof setTimeout> | null = null;
@@ -85,7 +54,7 @@ export function useChatPageDialogs(messages: Ref<ChatMessage[]>) {
};
/**
* 展示非阻塞顶部 toast(用于发货批量重试等轻量成功反馈)。
* 展示非阻塞顶部 toast。
* @param message - toast 正文;空字符串视为关闭
*/
const showShippingToast = (message: string) => {
@@ -143,10 +112,6 @@ export function useChatPageDialogs(messages: Ref<ChatMessage[]>) {
openDeleteConfirmDialog,
closeDeleteConfirmDialog,
handleDeleteConfirm,
showRetryFailedConfirmDialog,
openRetryFailedConfirm,
closeRetryFailedConfirm,
handleRetryFailedConfirm,
shippingToastMessage,
showShippingToast,
clearShippingToast,
@@ -55,7 +55,7 @@ export interface ChatPageSendContext {
agentId: number,
kb: string,
files: ChatUploadFileSpec[],
context?: { task_id?: string; batch_no?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string },
context?: { task_id?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string },
hooks?: SendMessageLifecycleHooks,
) => Promise<ChatMessageSendResult>;
refreshHistoryAfterSend: () => Promise<void>;
@@ -81,7 +81,7 @@ export interface ChatPageSendContext {
msg: { warning: (text: string) => void; info: (text: string) => void };
t: (key: string, values?: Record<string, unknown>) => string;
copiedIndex: Ref<number | null>;
getChatContext?: () => { task_id?: string; batch_no?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string };
getChatContext?: () => { task_id?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string };
onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void>;
}