- 移除不必要的状态引用 - 更新上传处理提示文本,使用国际化支持 - 扩展发货任务摘要接口,增加错误信息和短缺信息 - 更新多语言支持的文本,改善用户体验 - 增加批次工作区的汇总信息和操作提示
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
/**
|
|
* 对话页:本地消息落库(请假/出货等不经过 SSE 的消息)。
|
|
*/
|
|
import { saveLocalChatMessage } from '../api/chat.api';
|
|
import type { ChatMessage } from '../types/chat.types';
|
|
import type { ComputedRef, Ref } from 'vue';
|
|
|
|
export interface ChatPageLocalMessageContext {
|
|
conversationId: Ref<string | null>;
|
|
currentAgentId: ComputedRef<number>;
|
|
}
|
|
|
|
export function createChatPageLocalMessageApi(ctx: ChatPageLocalMessageContext) {
|
|
let localMessageCounter = 0;
|
|
|
|
const newLocalMessageId = (prefix: string) => {
|
|
localMessageCounter += 1;
|
|
return `${prefix}-${Date.now()}-${localMessageCounter}`;
|
|
};
|
|
|
|
const saveLocalMessageToBackend = async (localMsg: ChatMessage, userQuery: string = '') => {
|
|
try {
|
|
const data = await saveLocalChatMessage({
|
|
conversation_id: ctx.conversationId.value,
|
|
role: localMsg.role,
|
|
type: localMsg.type,
|
|
content: localMsg.content,
|
|
payload: localMsg.payload,
|
|
query: userQuery,
|
|
agent_id: ctx.currentAgentId.value,
|
|
});
|
|
if (!ctx.conversationId.value && data.conversation_id) {
|
|
ctx.conversationId.value = data.conversation_id;
|
|
}
|
|
if (data.chat_log_id) {
|
|
localMsg.chat_log_id = data.chat_log_id;
|
|
}
|
|
} catch (e) {
|
|
console.error('Failed to save local message', e);
|
|
}
|
|
};
|
|
|
|
return { newLocalMessageId, saveLocalMessageToBackend };
|
|
}
|