feat(shipping-notice): 新增货代客户管理功能,支持客户导入、识别证据管理与客户确认
This commit is contained in:
1 parent
b595e157e9
commit
4fbaed2b4c
176 files changed
+14011
-994
No files matched your search
@@ -1,10 +1,14 @@
|
||||
/**
|
||||
* 对话页:发送消息编排(出货/请假前置拦截 → Dify SSE)、复制与重新生成。
|
||||
* features/chat/page/useChatPageSend.ts
|
||||
* 用途:编排聊天消息发送、业务前置拦截、复制与重新生成。
|
||||
* 依赖:统一 BusinessError、剪贴板工具、Chat 消息与附件参数类型。
|
||||
* 逻辑:附件上传成功后调用 Dify SSE;仅在消息发送成功后清空附件,失败时保留供重试。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { copyTextToClipboard } from '@/shared/utils/clipboard';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ChatMessage, ChatMessageAttachment } from '../types/chat.types';
|
||||
import type { SendMessageLifecycleHooks } from '../composables/useChat';
|
||||
import type { ChatUploadFileSpec } from '../types/shipping.types';
|
||||
import type { ComputedRef, Ref } from 'vue';
|
||||
|
||||
@@ -42,6 +46,7 @@ export interface ChatPageSendContext {
|
||||
attachments: Ref<unknown[]>;
|
||||
allowsSendWithAttachmentsOnly: ComputedRef<boolean>;
|
||||
buildFileSpecsForSend: () => Promise<ChatUploadFileSpec[]>;
|
||||
createMessageAttachmentSnapshots: () => ChatMessageAttachment[];
|
||||
clearAttachments: () => void;
|
||||
sendMessage: (
|
||||
content: string,
|
||||
@@ -49,8 +54,8 @@ export interface ChatPageSendContext {
|
||||
kb: string,
|
||||
files: ChatUploadFileSpec[],
|
||||
context?: { task_id?: string; batch_no?: string; shipping_intake_nos?: string[]; display_query?: string },
|
||||
hooks?: { onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void> },
|
||||
) => Promise<void>;
|
||||
hooks?: SendMessageLifecycleHooks,
|
||||
) => Promise<boolean | void>;
|
||||
refreshHistoryAfterSend: () => Promise<void>;
|
||||
refreshConversationAfterSend?: () => Promise<void>;
|
||||
tryHandleShippingAttachmentAutoFlow: (
|
||||
@@ -78,6 +83,11 @@ export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
const allowSendWhileThinking = canContinueSendWhileThinking(ctx.messages.value);
|
||||
if (ctx.isUploadingAttachments.value) return false;
|
||||
if (ctx.input.value.trim()) return !ctx.isThinking.value || allowSendWhileThinking;
|
||||
if (
|
||||
ctx.attachments.value.length > 0
|
||||
&& ctx.attachmentPolicy.value.anyEnabled
|
||||
&& (!ctx.isThinking.value || allowSendWhileThinking)
|
||||
) return true;
|
||||
if (ctx.allowsSendWithAttachmentsOnly.value) return true;
|
||||
return false;
|
||||
});
|
||||
@@ -85,11 +95,12 @@ export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
const handleSend = async (textOrEvent?: string | Event) => {
|
||||
const content = (typeof textOrEvent === 'string' ? textOrEvent : null) || ctx.input.value;
|
||||
const trimmed = content.trim();
|
||||
const hasAttachments = ctx.attachmentPolicy.value.anyEnabled && ctx.attachments.value.length > 0;
|
||||
const allowSendWhileThinking = canContinueSendWhileThinking(ctx.messages.value);
|
||||
if (await ctx.tryHandleShippingAttachmentAutoFlow(textOrEvent, content, trimmed)) {
|
||||
return;
|
||||
}
|
||||
if (!trimmed || ctx.isUploadingAttachments.value || (ctx.isThinking.value && !allowSendWhileThinking)) {
|
||||
if ((!trimmed && !hasAttachments) || ctx.isUploadingAttachments.value || (ctx.isThinking.value && !allowSendWhileThinking)) {
|
||||
return;
|
||||
}
|
||||
if (ctx.tryHandleLeaveSend(content)) {
|
||||
@@ -100,9 +111,11 @@ export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
}
|
||||
|
||||
let files: ChatUploadFileSpec[] = [];
|
||||
let messageAttachments: ChatMessageAttachment[] = [];
|
||||
if (ctx.attachmentPolicy.value.anyEnabled && ctx.attachments.value.length > 0) {
|
||||
try {
|
||||
files = await ctx.buildFileSpecsForSend();
|
||||
messageAttachments = ctx.createMessageAttachmentSnapshots();
|
||||
} catch (e: unknown) {
|
||||
let suffix = '';
|
||||
if (e instanceof BusinessError) {
|
||||
@@ -121,17 +134,26 @@ export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
}
|
||||
|
||||
if (typeof textOrEvent !== 'string') ctx.input.value = '';
|
||||
ctx.clearAttachments();
|
||||
|
||||
const requestContent = trimmed || ctx.t('chat.attachment.defaultPrompt');
|
||||
const sendContext = {
|
||||
...(ctx.getChatContext?.() || {}),
|
||||
...(!trimmed && messageAttachments.length > 0 ? { display_query: '' } : {}),
|
||||
};
|
||||
await ctx.prepareToolRunProgressBeforeSend();
|
||||
await ctx.sendMessage(
|
||||
content,
|
||||
const sent = await ctx.sendMessage(
|
||||
requestContent,
|
||||
ctx.currentAgentId.value,
|
||||
ctx.selectedKb.value,
|
||||
files,
|
||||
ctx.getChatContext?.(),
|
||||
{ onAssistantMessageFinished: ctx.onAssistantMessageFinished },
|
||||
Object.keys(sendContext).length > 0 ? sendContext : undefined,
|
||||
{
|
||||
userAttachments: messageAttachments,
|
||||
onAssistantMessageFinished: ctx.onAssistantMessageFinished,
|
||||
},
|
||||
);
|
||||
if (sent === false) return;
|
||||
ctx.clearAttachments();
|
||||
await ctx.refreshHistoryAfterSend();
|
||||
await ctx.refreshConversationAfterSend?.();
|
||||
await ctx.refreshToolRunProgressAfterSend();
|
||||
|
||||
Reference in new issue
Block a user