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
@@ -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>`
|
||||
|
||||
Reference in new issue
Block a user