feat(shipping, admin, workspace, docs): 迭代货代模块、补充文档并处理合并冲突问题
This commit is contained in:
1 parent
4587b56900
commit
3c0e08377c
94 files changed
+29222
-1218
No files matched your search
@@ -3,7 +3,9 @@
|
||||
* 用途:持久化请假、出货等不经过 SSE 的本地聊天消息。
|
||||
* 依赖:chat.api.saveLocalChatMessage、ChatMessage、Vue refs。
|
||||
* 逻辑:各业务 composable 传入本地消息;本模块绑定当前会话并返回明确保存结果。
|
||||
* 兼容:同时支持合同审查本地消息,并在首次落库后同步 URL conversation_id。
|
||||
*/
|
||||
import type { RouteLocationNormalizedLoaded, Router } from 'vue-router';
|
||||
import { saveLocalChatMessage } from '../api/chat.api';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ComputedRef, Ref } from 'vue';
|
||||
@@ -11,8 +13,14 @@ import type { ComputedRef, Ref } from 'vue';
|
||||
export interface ChatPageLocalMessageContext {
|
||||
conversationId: Ref<string | null>;
|
||||
currentAgentId: ComputedRef<number>;
|
||||
route?: RouteLocationNormalizedLoaded;
|
||||
router?: Router;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建本地消息落库 API。
|
||||
* @param ctx - 会话 ID、当前 Agent,以及可选的 route/router 用于同步 URL
|
||||
*/
|
||||
export function createChatPageLocalMessageApi(ctx: ChatPageLocalMessageContext) {
|
||||
let localMessageCounter = 0;
|
||||
|
||||
@@ -27,7 +35,7 @@ export function createChatPageLocalMessageApi(ctx: ChatPageLocalMessageContext)
|
||||
* @param localMsg - 待保存的用户或助手消息。
|
||||
* @param userQuery - 用户消息展示文本;助手消息必须为空。
|
||||
* @returns 服务端确认提交时为 true;网络或业务失败时为 false。
|
||||
*/
|
||||
*/
|
||||
const saveLocalMessageToBackend = async (localMsg: ChatMessage, userQuery: string = ''): Promise<boolean> => {
|
||||
try {
|
||||
const data = await saveLocalChatMessage({
|
||||
@@ -47,12 +55,25 @@ export function createChatPageLocalMessageApi(ctx: ChatPageLocalMessageContext)
|
||||
query: userQuery,
|
||||
agent_id: ctx.currentAgentId.value,
|
||||
});
|
||||
if (!ctx.conversationId.value && data.conversation_id) {
|
||||
ctx.conversationId.value = data.conversation_id;
|
||||
const cid = data.conversation_id ? String(data.conversation_id) : '';
|
||||
if (cid && !ctx.conversationId.value) {
|
||||
ctx.conversationId.value = cid;
|
||||
}
|
||||
if (data.chat_log_id) {
|
||||
localMsg.chat_log_id = data.chat_log_id;
|
||||
}
|
||||
// [STEP] 同步 URL,刷新后可按 conversation_id 拉回用户提问 + 结果卡
|
||||
if (cid && ctx.route && ctx.router) {
|
||||
const current = typeof ctx.route.query.conversation_id === 'string'
|
||||
? ctx.route.query.conversation_id
|
||||
: '';
|
||||
if (current !== cid) {
|
||||
await ctx.router.replace({
|
||||
path: ctx.route.path,
|
||||
query: { ...ctx.route.query, conversation_id: cid },
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* features/chat/page/useChatPageMarkdown.ts
|
||||
* 用途:统一处理聊天页 Markdown 渲染、内嵌文件块提取、消息可见性判断与特殊链接点击。
|
||||
* 依赖:Vue computed、marked、ChatMessageBubble handlers、聊天消息类型。
|
||||
* 依赖:Vue computed、marked、vue-i18n、ChatMessageBubble handlers、聊天消息类型。
|
||||
* 逻辑:由 useChatPage 组装上下文后创建页面级 Markdown API,再分发给 ChatMessageBubble 做消息渲染和交互。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { marked } from 'marked';
|
||||
import i18n from '@/i18n';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import type { ChatMessageBubbleHandlers } from '../components/messages/ChatMessageBubble.vue';
|
||||
import type { ChatMessage, InlineDownloadFile, SourceFileLink } from '../types/chat.types';
|
||||
@@ -19,6 +20,58 @@ import {
|
||||
|
||||
marked.setOptions({ gfm: true, breaks: true });
|
||||
|
||||
const tt = (key: string, params?: Record<string, unknown>) => String(i18n.global.t(key, params as any));
|
||||
|
||||
/** 内部规范表头键(兼容服务端中文列名);展示时再映射到 chat.assetColumns.* */
|
||||
const FIXED_ASSET_TABLE_TARGET_HEADERS = [
|
||||
'序号',
|
||||
'资产编号',
|
||||
'资产名称',
|
||||
'保管人',
|
||||
'保管部门',
|
||||
'图片',
|
||||
'账套',
|
||||
'供应商',
|
||||
'资产状态',
|
||||
'数量',
|
||||
'取得时间',
|
||||
] as const;
|
||||
|
||||
const FIXED_ASSET_HEADER_I18N_KEYS: Record<(typeof FIXED_ASSET_TABLE_TARGET_HEADERS)[number], string> = {
|
||||
序号: 'chat.assetColumns.id',
|
||||
资产编号: 'chat.assetColumns.assetId',
|
||||
资产名称: 'chat.assetColumns.assetName',
|
||||
保管人: 'chat.assetColumns.custodianPerson',
|
||||
保管部门: 'chat.assetColumns.custodianDept',
|
||||
图片: 'chat.assetColumns.image',
|
||||
账套: 'chat.assetColumns.accountPeriod',
|
||||
供应商: 'chat.assetColumns.supplier',
|
||||
资产状态: 'chat.assetColumns.assetStatus',
|
||||
数量: 'chat.assetColumns.quantity',
|
||||
取得时间: 'chat.assetColumns.acquisitionDate',
|
||||
};
|
||||
|
||||
function displayFixedAssetHeader(header: string): string {
|
||||
const key = FIXED_ASSET_HEADER_I18N_KEYS[header as keyof typeof FIXED_ASSET_HEADER_I18N_KEYS];
|
||||
return key ? tt(key) : header;
|
||||
}
|
||||
/**
|
||||
* 用途:为聊天中的 Mermaid 代码块保留可识别标记,交由消息组件渲染为 SVG 图表。
|
||||
* 逻辑:仅处理明确标为 `mermaid` 的代码块;其余代码仍保持 marked 的默认安全展示,
|
||||
* 避免把普通文本或 ASCII 图误当作可执行图表语法。
|
||||
*/
|
||||
const chatMarkdownRenderer = new marked.Renderer();
|
||||
chatMarkdownRenderer.code = ({ text, lang }: { text: string; lang?: string | null }) => {
|
||||
if (String(lang || '').trim().toLowerCase() === 'mermaid') {
|
||||
return `<pre class="chat-mermaid">${text}</pre>`;
|
||||
}
|
||||
const escaped = String(text || '')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
const languageClass = String(lang || '').trim().replace(/[^a-zA-Z0-9_-]/g, '');
|
||||
return `<pre><code${languageClass ? ` class="language-${languageClass}"` : ''}>${escaped}</code></pre>`;
|
||||
};
|
||||
const INLINE_FILE_BLOCK_REGEX = /\[FILE_START\]([\s\S]*?)\[FILE_END\]/g;
|
||||
const INLINE_ATTACHMENT_HINT_REGEX = /^.*(?:如果您需要查看全部数据,请下载附件。?|请下载附件。?).*$/gim;
|
||||
|
||||
@@ -185,24 +238,11 @@ function downloadInlineFile(file: InlineDownloadFile): void {
|
||||
|
||||
function normalizeAssetHistoryText(value: string): string {
|
||||
const normalized = String(value || '').trim();
|
||||
if (!normalized || normalized === '-' || normalized === '无') return '';
|
||||
const emptyLabel = tt('chat.assetColumns.empty');
|
||||
if (!normalized || normalized === '-' || normalized === '无' || normalized === emptyLabel) return '';
|
||||
return normalized;
|
||||
}
|
||||
|
||||
const FIXED_ASSET_TABLE_TARGET_HEADERS = [
|
||||
'序号',
|
||||
'资产编号',
|
||||
'资产名称',
|
||||
'保管人',
|
||||
'保管部门',
|
||||
'图片',
|
||||
'账套',
|
||||
'供应商',
|
||||
'资产状态',
|
||||
'数量',
|
||||
'取得时间',
|
||||
];
|
||||
|
||||
const FIXED_ASSET_TABLE_HEADER_ALIASES: Record<string, string[]> = {
|
||||
序号: ['序号', 'id'],
|
||||
资产编号: ['资产编号', 'asset_id', 'asset_no'],
|
||||
@@ -262,10 +302,12 @@ function normalizeFixedAssetPreviewTables(container: HTMLElement): void {
|
||||
if (header === '图片') {
|
||||
const assetIdIndex = headerIndexMap.get('资产编号');
|
||||
const assetId = assetIdIndex !== undefined ? normalizeAssetHistoryText(cells[assetIdIndex]?.textContent || '') : '';
|
||||
return assetId ? '查看' : '无';
|
||||
return assetId ? tt('chat.assetColumns.view') : tt('chat.assetColumns.empty');
|
||||
}
|
||||
const cellIndex = headerIndexMap.get(header);
|
||||
return cellIndex !== undefined ? normalizeAssetHistoryText(cells[cellIndex]?.textContent || '') || '无' : '无';
|
||||
return cellIndex !== undefined
|
||||
? normalizeAssetHistoryText(cells[cellIndex]?.textContent || '') || tt('chat.assetColumns.empty')
|
||||
: tt('chat.assetColumns.empty');
|
||||
};
|
||||
return FIXED_ASSET_TABLE_TARGET_HEADERS.map((header) => pickCellText(header));
|
||||
});
|
||||
@@ -275,32 +317,36 @@ function normalizeFixedAssetPreviewTables(container: HTMLElement): void {
|
||||
if (!thead || !tbody) return;
|
||||
|
||||
thead.innerHTML = `<tr>${FIXED_ASSET_TABLE_TARGET_HEADERS.map((header) => (
|
||||
`<th class="${header === '资产编号' || header === '图片' ? 'chat-fixed-asset-highlight-header' : ''}">${header}</th>`
|
||||
`<th class="${header === '资产编号' || header === '图片' ? 'chat-fixed-asset-highlight-header' : ''}">${displayFixedAssetHeader(header)}</th>`
|
||||
)).join('')}</tr>`;
|
||||
tbody.innerHTML = normalizedRows.map((row) => (
|
||||
`<tr>${row.map((cell) => `<td>${cell || '无'}</td>`).join('')}</tr>`
|
||||
`<tr>${row.map((cell) => `<td>${cell || tt('chat.assetColumns.empty')}</td>`).join('')}</tr>`
|
||||
)).join('');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 把聊天结果表格里的“资产编号”和“图片”列增强为可点击入口。
|
||||
* 核心逻辑:只处理包含“资产编号”表头的表格,并从同行“资产名称”列一并带出检索关键词;资产编号走履历检索,图片走图片预览检索。
|
||||
* 核心逻辑:只处理包含资产编号表头的表格(兼容服务端中文与本地化展示标签),并从同行资产名称列一并带出检索关键词。
|
||||
*/
|
||||
function enhanceAssetHistoryTableLinks(html: string): string {
|
||||
if (!html || typeof document === 'undefined' || !html.includes('<table')) return html;
|
||||
const container = document.createElement('div');
|
||||
container.innerHTML = html;
|
||||
normalizeFixedAssetPreviewTables(container);
|
||||
const assetIdLabel = tt('chat.assetColumns.assetId');
|
||||
const assetNameLabel = tt('chat.assetColumns.assetName');
|
||||
const imageLabel = tt('chat.assetColumns.image');
|
||||
const viewLabel = tt('chat.assetColumns.view');
|
||||
const tables = Array.from(container.querySelectorAll('table'));
|
||||
tables.forEach((table) => {
|
||||
const headerCells = Array.from(table.querySelectorAll('thead th'));
|
||||
if (headerCells.length === 0) return;
|
||||
const headerLabels = headerCells.map((cell) => normalizeAssetHistoryText(cell.textContent || ''));
|
||||
const assetIdIndex = headerLabels.findIndex((label) => label === '资产编号');
|
||||
const assetIdIndex = headerLabels.findIndex((label) => label === '资产编号' || label === assetIdLabel);
|
||||
if (assetIdIndex < 0) return;
|
||||
const assetNameIndex = headerLabels.findIndex((label) => label === '资产名称');
|
||||
const imageIndex = headerLabels.findIndex((label) => label === '图片');
|
||||
const assetNameIndex = headerLabels.findIndex((label) => label === '资产名称' || label === assetNameLabel);
|
||||
const imageIndex = headerLabels.findIndex((label) => label === '图片' || label === imageLabel);
|
||||
const rows = Array.from(table.querySelectorAll('tbody tr'));
|
||||
rows.forEach((row) => {
|
||||
const cells = Array.from(row.querySelectorAll('td'));
|
||||
@@ -319,7 +365,7 @@ function enhanceAssetHistoryTableLinks(html: string): string {
|
||||
if (imageIndex >= 0) {
|
||||
const imageCell = cells[imageIndex];
|
||||
if (!imageCell) return;
|
||||
const imageText = normalizeAssetHistoryText(imageCell.textContent || '') || '查看';
|
||||
const imageText = normalizeAssetHistoryText(imageCell.textContent || '') || viewLabel;
|
||||
const imageLink = document.createElement('a');
|
||||
imageLink.href = `#asset-image?asset_id=${encodeURIComponent(assetId)}&asset_name=${encodeURIComponent(assetName)}`;
|
||||
imageLink.className = 'chat-asset-history-link';
|
||||
@@ -347,6 +393,7 @@ export function createChatPageMarkdownApi(ctx: ChatPageMarkdownContext) {
|
||||
if (msgItem?.type === 'shipping-parse-review') return false;
|
||||
if (msgItem?.type === 'leave-form' || msgItem?.type === 'leave-confirmation' || msgItem?.type === 'leave-result') return true;
|
||||
if (msgItem?.shipping_order_extraction_state) return true;
|
||||
if (msgItem?.type === 'procurement-contract-review') return true;
|
||||
const content = (msgItem?.content || '').trim();
|
||||
if (content) return true;
|
||||
if (ctx.getMessageLinks(msgItem as unknown as Record<string, unknown>).length > 0) return true;
|
||||
@@ -366,7 +413,9 @@ export function createChatPageMarkdownApi(ctx: ChatPageMarkdownContext) {
|
||||
|| msgItem?.type === 'leave-confirmation'
|
||||
|| msgItem?.type === 'leave-result'
|
||||
|| msgItem?.type === 'shipping-parse-review'
|
||||
|| msgItem?.type === 'shipping-match-result') {
|
||||
|| msgItem?.type === 'shipping-match-result'
|
||||
|| msgItem?.type === 'maintenance-device-result'
|
||||
|| msgItem?.type === 'procurement-contract-review') {
|
||||
return true;
|
||||
}
|
||||
return Boolean(String(msgItem?.content || '').trim());
|
||||
@@ -413,7 +462,7 @@ export function createChatPageMarkdownApi(ctx: ChatPageMarkdownContext) {
|
||||
if (fileCheckRunId) {
|
||||
event.preventDefault();
|
||||
void downloadFileCheckExcelByRunId(fileCheckRunId).catch((error: unknown) => {
|
||||
const text = error instanceof Error ? error.message : '下载 Excel 失败';
|
||||
const text = error instanceof Error ? error.message : tt('chat.toolRun.downloadFailed');
|
||||
message.error(text);
|
||||
});
|
||||
return;
|
||||
@@ -434,11 +483,11 @@ export function createChatPageMarkdownApi(ctx: ChatPageMarkdownContext) {
|
||||
ctx.prepareMarkdownDisplayText(extracted.cleanedText),
|
||||
);
|
||||
try {
|
||||
const rendered = marked.parse(displayText);
|
||||
const rendered = marked.parse(displayText, { renderer: chatMarkdownRenderer });
|
||||
const html = typeof rendered === 'string' ? rendered : displayText;
|
||||
return enhanceAssetHistoryTableLinks(html)
|
||||
.replace(/<(td|th)\b([^>]*)>(?:\s| |<br\s*\/?>)*<\/\1>/gi, (_match, tagName: string, attrs: string) => (
|
||||
`<${tagName}${attrs}>无</${tagName}>`
|
||||
`<${tagName}${attrs}>${tt('chat.assetColumns.empty')}</${tagName}>`
|
||||
))
|
||||
.replace(/<table\b[\s\S]*?<\/table>/gi, (tableHtml: string) => (
|
||||
`<div class="chat-table-scroll"><div class="chat-table-inner">${tableHtml}</div></div>`
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* 用途:编排聊天消息发送、业务前置拦截、复制与重新生成。
|
||||
* 依赖:统一 BusinessError、剪贴板工具、Chat 消息与附件参数类型。
|
||||
* 逻辑:附件上传成功后调用 Dify SSE;仅在消息发送成功后清空附件,失败时保留供重试。
|
||||
* 兼容:依次处理货代附件、采购合同、请假与货代文本前置拦截。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
@@ -70,10 +71,15 @@ export interface ChatPageSendContext {
|
||||
content: string,
|
||||
trimmed: string,
|
||||
) => Promise<boolean>;
|
||||
tryHandleProcurementContractSend: (
|
||||
textOrEvent: string | Event | undefined,
|
||||
content: string,
|
||||
trimmed: string,
|
||||
) => Promise<boolean>;
|
||||
refreshToolRunProgressAfterSend: () => Promise<void>;
|
||||
prepareToolRunProgressBeforeSend: () => Promise<void>;
|
||||
msg: { warning: (text: string) => void; info: (text: string) => void };
|
||||
t: (key: string) => string;
|
||||
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 };
|
||||
onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void>;
|
||||
@@ -101,6 +107,9 @@ export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
if (await ctx.tryHandleShippingAttachmentAutoFlow(textOrEvent, content, trimmed)) {
|
||||
return;
|
||||
}
|
||||
if (await ctx.tryHandleProcurementContractSend(textOrEvent, content, trimmed)) {
|
||||
return;
|
||||
}
|
||||
if ((!trimmed && !hasAttachments) || ctx.isUploadingAttachments.value || (ctx.isThinking.value && !allowSendWhileThinking)) {
|
||||
return;
|
||||
}
|
||||
@@ -129,7 +138,7 @@ export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
if (requestId) suffix = `(rid=${requestId})`;
|
||||
}
|
||||
const message = e instanceof Error ? e.message : 'unknown error';
|
||||
ctx.msg.warning(`附件处理失败:${message}${suffix}`);
|
||||
ctx.msg.warning(ctx.t('chat.attachmentsUi.processFailed', { message, suffix }));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
import { computed, nextTick, ref, watch, type Ref } from 'vue';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
import {
|
||||
agentHasProgress,
|
||||
@@ -208,7 +209,7 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
...runErrors.value,
|
||||
|
||||
[runId]: e instanceof Error ? e.message : '任务进度查询失败',
|
||||
[runId]: e instanceof Error ? e.message : String(i18n.global.t('chat.toolRun.queryFailed')),
|
||||
|
||||
};
|
||||
|
||||
@@ -272,7 +273,7 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
...chatLogErrors.value,
|
||||
|
||||
[chatLogId]: '暂未找到关联的检核任务,请稍后刷新或查看排程执行记录',
|
||||
[chatLogId]: String(i18n.global.t('chat.toolRun.runNotFound')),
|
||||
|
||||
};
|
||||
|
||||
@@ -292,7 +293,7 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
...chatLogErrors.value,
|
||||
|
||||
[chatLogId]: e instanceof Error ? e.message : '任务进度查询失败',
|
||||
[chatLogId]: e instanceof Error ? e.message : String(i18n.global.t('chat.toolRun.queryFailed')),
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user