refactor(frontend): 重构前端第二版

This commit is contained in:
sophie committed 2026-06-11 13:47:06 +08:00
1 parent 2631f78b00
commit 4b562cfa82
205 files changed
+15399 -12015

No files matched your search

@@ -0,0 +1,42 @@
/**
* 出货聊天:会话侧栏同步、带任务编号的菜单消息发送。
*/
import type { ChatSessionItem } from '../types/chat.types';
import type { ChatUploadFileSpec } from '../types/shipping.types';
import type { ComputedRef, Ref } from 'vue';
export interface ShippingConversationContext {
conversationId: Ref<string | null>;
history: Ref<ChatSessionItem[]>;
loadHistory: () => Promise<void>;
getActiveShippingTaskId: () => string;
currentAgentId: ComputedRef<number>;
selectedKb: Ref<string>;
sendMessage: (
content: string,
agentId: number,
kb: string,
files: ChatUploadFileSpec[],
) => Promise<void>;
}
/** 发送菜单类消息后,若当前会话尚未出现在侧栏历史中则刷新列表 */
export async function ensureShippingHistorySynced(ctx: ShippingConversationContext) {
if (!ctx.conversationId.value && ctx.history.value.length === 0) {
await ctx.loadHistory();
} else if (ctx.conversationId.value) {
const exists = ctx.history.value.some((h) => h.conversation_id === ctx.conversationId.value);
if (!exists) await ctx.loadHistory();
}
}
export function createShippingConversationHelpers(ctx: ShippingConversationContext) {
const sendShippingMenuMessage = async (message: string) => {
const taskId = ctx.getActiveShippingTaskId();
const text = taskId ? `${message}\n任务编号:${taskId}` : message;
await ctx.sendMessage(text, ctx.currentAgentId.value, ctx.selectedKb.value, []);
await ensureShippingHistorySynced(ctx);
};
return { sendShippingMenuMessage, ensureShippingHistorySynced };
}