fix(chat): 修复固资管理首轮问答残留中断与历史会话异常
This commit is contained in:
1 parent
25876f94bd
commit
3b771fc0b6
16 files changed
+1042
-35
No files matched your search
@@ -3,7 +3,7 @@
|
||||
* 聊天输入栏:文本框、附件、语音、知识库选择与发送按钮。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import type { Ref } from 'vue';
|
||||
import {
|
||||
Check,
|
||||
@@ -56,6 +56,7 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const filePickerRef = ref<HTMLInputElement | null>(null);
|
||||
const textareaRef = ref<HTMLTextAreaElement | null>(null);
|
||||
const attachmentMenuRef = ref<HTMLElement | null>(null);
|
||||
const kbMenuRef = ref<HTMLElement | null>(null);
|
||||
const attachmentUrlInputRef = ref<HTMLInputElement | null>(null);
|
||||
@@ -63,7 +64,6 @@ const showAttachmentMenu = ref(false);
|
||||
const showAttachmentUrlPanel = ref(false);
|
||||
const showKbDropdown = ref(false);
|
||||
const attachmentUrlInput = ref('');
|
||||
|
||||
const closeAttachmentMenu = () => {
|
||||
showAttachmentMenu.value = false;
|
||||
showAttachmentUrlPanel.value = false;
|
||||
@@ -138,6 +138,26 @@ onBeforeUnmount(() => {
|
||||
document.removeEventListener('mousedown', handleDocumentPointerDown);
|
||||
document.removeEventListener('touchstart', handleDocumentPointerDown);
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.isThinking,
|
||||
async (thinking, prevThinking) => {
|
||||
if (thinking || !prevThinking || props.isVoiceTranscribing) return;
|
||||
await nextTick();
|
||||
textareaRef.value?.focus();
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => inputValue.value,
|
||||
async (value) => {
|
||||
if (value) return;
|
||||
await nextTick();
|
||||
if (textareaRef.value && textareaRef.value.value !== '') {
|
||||
textareaRef.value.value = '';
|
||||
}
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -145,12 +165,13 @@ onBeforeUnmount(() => {
|
||||
<div class="relative mx-auto max-w-4xl">
|
||||
<div class="flex flex-col rounded-2xl bg-surface p-2 shadow-[0_0_15px_rgba(0,0,0,0.05)] transition-all">
|
||||
<textarea
|
||||
ref="textareaRef"
|
||||
v-model="inputValue"
|
||||
rows="1"
|
||||
:placeholder="isVoiceTranscribing ? $t('chat.voiceTranscribing') : isVoiceRecording ? $t('chat.voiceListening') : $t('chat.askAnything')"
|
||||
class="w-full resize-none border-none bg-transparent px-3 py-2 text-[15px] leading-relaxed text-primary placeholder-slate-400 focus:border-transparent focus:outline-none focus:ring-0"
|
||||
style="min-height: 44px; max-height: 220px;"
|
||||
:disabled="isThinking || isVoiceTranscribing"
|
||||
:disabled="isVoiceTranscribing"
|
||||
spellcheck="false"
|
||||
autocorrect="off"
|
||||
autocapitalize="off"
|
||||
@@ -320,13 +341,14 @@ onBeforeUnmount(() => {
|
||||
: 'border-brand-500 bg-brand-500 text-white shadow-[0_0_0_4px_rgba(59,130,246,0.18)] hover:scale-105 hover:bg-brand-600 hover:shadow-[0_0_0_6px_rgba(59,130,246,0.24)] active:scale-95'"
|
||||
@click="emit('send')"
|
||||
>
|
||||
<Loader2 v-if="isUploadingAttachments" class="h-4 w-4 animate-spin" />
|
||||
<Loader2 v-if="isUploadingAttachments || isThinking" class="h-4 w-4 animate-spin" />
|
||||
<Send v-else class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 text-center text-[11px] text-muted">
|
||||
{{ $t('chat.disclaimer') }}
|
||||
<span v-if="isThinking">{{ $t('chat.thinking') }}</span>
|
||||
<span v-else>{{ $t('chat.disclaimer') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
@@ -54,6 +54,16 @@ const emit = defineEmits<{
|
||||
const bindScrollContainer = (node: unknown) => {
|
||||
scrollContainerHolder.el.value = (node as HTMLElement | null) ?? null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 生成稳定的消息 key,避免切换历史会话时仅因条数相同而复用旧气泡组件。
|
||||
* 核心逻辑:优先使用服务端/本地消息 ID,其次拼接角色、run_id 与内容摘要。
|
||||
*/
|
||||
const getMessageKey = (msg: ChatMessage, index: number) => (
|
||||
msg.local_id
|
||||
|| (typeof msg.chat_log_id === 'number' ? `chat-log:${msg.chat_log_id}` : '')
|
||||
|| `${msg.role}:${msg.run_id || 'none'}:${String(msg.content || '').slice(0, 40)}:${index}`
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -72,7 +82,7 @@ const bindScrollContainer = (node: unknown) => {
|
||||
@select-question="emit('select-question', $event)"
|
||||
/>
|
||||
|
||||
<template v-for="(msg, index) in messages" :key="index">
|
||||
<template v-for="(msg, index) in messages" :key="getMessageKey(msg, index)">
|
||||
<ChatMessageBubble
|
||||
v-if="shouldRenderMessage(msg)"
|
||||
:message="msg"
|
||||
|
||||
@@ -126,6 +126,7 @@ const page = useChatPageContext();
|
||||
/>
|
||||
|
||||
<ChatInputBar
|
||||
:key="`${page.currentAgentId}-${page.conversationId || 'draft'}-${page.messages.length}`"
|
||||
v-model="page.input"
|
||||
v-model:selected-kb="page.selectedKb"
|
||||
:attachments="page.attachments"
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
/**
|
||||
* features/chat/components/messages/ChatMessageBubble.vue
|
||||
* 单条聊天消息:用户气泡、助手 Markdown、请假/出货子组件、来源引用与操作栏。
|
||||
* 用途:渲染单条聊天消息,统一承接用户气泡、助手 Markdown、内嵌文件下载、请假/出货子组件与操作栏。
|
||||
* 依赖:Vue computed、lucide 图标、Leave/Shipping 子消息组件、chat.types 与页面级 handlers。
|
||||
* 逻辑:由 ChatMessageList 按消息逐条挂载;正文渲染与特殊交互委托 useChatPageMarkdown 等页面编排层提供的 handlers。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { Check, Copy, Edit2, LayoutGrid, MessageSquareText, RotateCw } from 'lucide-vue-next';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Check, Copy, Download, Edit2, Eye, LayoutGrid, MessageSquareText, RotateCw, X } from 'lucide-vue-next';
|
||||
import LeaveMessageBlock, { type LeaveMessageHandlers } from './LeaveMessageBlock.vue';
|
||||
import ShippingInventoryMappingMessage, { type ShippingMappingHandlers } from './ShippingInventoryMappingMessage.vue';
|
||||
import ShippingMatchResultCard from './ShippingMatchResultCard.vue';
|
||||
import ShippingParseReviewMessage, { type ShippingParseReviewHandlers } from './ShippingParseReviewMessage.vue';
|
||||
import type { ChatMessage, SourceFileLink } from '../../types/chat.types';
|
||||
import type { ChatMessage, InlineDownloadFile, SourceFileLink } from '../../types/chat.types';
|
||||
import type { ShippingInventoryMappingFormPayload, ShippingMatchResultPayload } from '../../types/shipping.types';
|
||||
|
||||
export interface ChatMessageBubbleHandlers {
|
||||
renderMarkdown: (text: string) => string;
|
||||
onMarkdownClick: (event: MouseEvent) => void;
|
||||
getInlineDownloadFiles: (text: string) => { cleanedText: string; files: InlineDownloadFile[] };
|
||||
downloadInlineFile: (file: InlineDownloadFile) => void;
|
||||
getShippingInventoryMappingPayload: (msg: ChatMessage) => ShippingInventoryMappingFormPayload | null;
|
||||
getShippingMatchResultPayload: (msg: ChatMessage) => ShippingMatchResultPayload | null;
|
||||
canOpenQueryPreview: (msg: ChatMessage) => boolean;
|
||||
@@ -87,6 +91,12 @@ const showShippingActionsPanel = computed(() =>
|
||||
);
|
||||
const isLastMessage = computed(() => index === messageCount - 1);
|
||||
const isCopied = computed(() => copiedIndex === index);
|
||||
const renderedMarkdown = computed(() => (
|
||||
message.role === 'assistant' ? handlers.renderMarkdown(message.content) : ''
|
||||
));
|
||||
const inlineDownloadFiles = computed(() => (
|
||||
message.role === 'assistant' ? handlers.getInlineDownloadFiles(message.content).files : []
|
||||
));
|
||||
const shippingParseReviewHandlers = computed<ShippingParseReviewHandlers>(() => ({
|
||||
getPayload: shippingHandlers.getParseReviewPayload,
|
||||
updateHeader: shippingHandlers.updateHeader,
|
||||
@@ -94,6 +104,335 @@ const shippingParseReviewHandlers = computed<ShippingParseReviewHandlers>(() =>
|
||||
addLine: shippingHandlers.addLine,
|
||||
removeLine: shippingHandlers.removeLine,
|
||||
}));
|
||||
|
||||
interface InlinePreviewTable {
|
||||
rawHeaders: string[];
|
||||
headers: string[];
|
||||
allRows: string[][];
|
||||
totalRows: number;
|
||||
isCsv: boolean;
|
||||
}
|
||||
|
||||
interface InlineFileEntry {
|
||||
file: InlineDownloadFile;
|
||||
fileIndex: number;
|
||||
table: InlinePreviewTable;
|
||||
}
|
||||
|
||||
const FIXED_ASSET_HEADER_LABELS: Record<string, string> = {
|
||||
id: '序号',
|
||||
asset_id: '资产编号',
|
||||
asset_no: '资产编号',
|
||||
asset_name: '资产名称',
|
||||
currency_amount: '本币金额(元)',
|
||||
specification: '规格型号',
|
||||
account_period: '账套',
|
||||
operating_center_code: '账套',
|
||||
custodian_person: '保管人姓名',
|
||||
custodian_name: '保管人姓名',
|
||||
custodian_dept: '保管部门名称',
|
||||
department_name: '保管部门名称',
|
||||
storage_location: '存放位置名称',
|
||||
location_name: '存放位置名称',
|
||||
asset_status: '资产状态',
|
||||
reserved_field: '预留残值',
|
||||
residual_value: '预留残值',
|
||||
supplier: '供应厂商',
|
||||
vendor_name: '供应厂商',
|
||||
asset_nature: '资产性质',
|
||||
nature: '资产性质',
|
||||
amount_local: '本币金额(元)',
|
||||
unit_price: '本币金额(元)',
|
||||
quantity: '数量',
|
||||
unit: '计量单位',
|
||||
unit_of_measurement: '计量单位',
|
||||
acquisition_date: '取得日期',
|
||||
acquired_date: '取得日期',
|
||||
accounting_date: '入账日期',
|
||||
recorded_date: '入账日期',
|
||||
created_at: '创建时间',
|
||||
created_time: '创建时间',
|
||||
updated_at: '更新时间',
|
||||
snapshot_time: '快照时间',
|
||||
};
|
||||
const INLINE_DIALOG_PAGE_SIZE = 15;
|
||||
|
||||
/**
|
||||
* 解析 CSV 行,支持双引号包裹字段与转义双引号。
|
||||
* 核心逻辑:逐字符扫描,避免简单 split(',') 破坏包含逗号的单元格。
|
||||
* @param line - 单行 CSV 文本。
|
||||
* @returns 当前行拆分后的列值数组。
|
||||
*/
|
||||
function parseCsvLine(line: string): string[] {
|
||||
const cells: string[] = [];
|
||||
let current = '';
|
||||
let inQuotes = false;
|
||||
|
||||
for (let i = 0; i < line.length; i += 1) {
|
||||
const char = line[i];
|
||||
const nextChar = line[i + 1];
|
||||
if (char === '"') {
|
||||
if (inQuotes && nextChar === '"') {
|
||||
current += '"';
|
||||
i += 1;
|
||||
} else {
|
||||
inQuotes = !inQuotes;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (char === ',' && !inQuotes) {
|
||||
cells.push(current);
|
||||
current = '';
|
||||
continue;
|
||||
}
|
||||
current += char;
|
||||
}
|
||||
|
||||
cells.push(current);
|
||||
return cells;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将固定资产 CSV 的英文列名转换成面向业务展示的中文列名。
|
||||
* 核心逻辑:优先命中已知字段映射;未知字段保留原值,避免误伤其他 Agent 的文件。
|
||||
* @param header - CSV 原始表头。
|
||||
* @returns 中文表头或原始表头。
|
||||
*/
|
||||
function localizeInlineTableHeader(header: string): string {
|
||||
const normalizedHeader = String(header || '').trim().toLowerCase();
|
||||
return FIXED_ASSET_HEADER_LABELS[normalizedHeader] || header || '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一表格中的空值展示。
|
||||
* 核心逻辑:对空串、短横线、null/none 等占位值统一显示“无”,但保留数字 0 与正常文本。
|
||||
* @param value - 原始单元格值。
|
||||
* @returns 归一化后的展示值。
|
||||
*/
|
||||
function normalizeInlineTableCell(value: string): string {
|
||||
const normalized = String(value ?? '').trim();
|
||||
if (!normalized) return '无';
|
||||
if (['-', '--', 'null', 'none', 'n/a', 'na'].includes(normalized.toLowerCase())) return '无';
|
||||
return normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容一批固定资产字段别名,定位筛选栏对应的列索引。
|
||||
* 核心逻辑:同一业务字段可能出现多种英文命名,命中任一别名即可。
|
||||
* @param headers - CSV 原始表头。
|
||||
* @param aliases - 候选字段名列表。
|
||||
* @returns 命中的列索引;未找到时返回 -1。
|
||||
*/
|
||||
function findInlineTableHeaderIndex(headers: string[], aliases: string[]): number {
|
||||
const normalizedAliases = aliases.map((item) => item.trim().toLowerCase());
|
||||
return headers.findIndex((header) => normalizedAliases.includes(String(header || '').trim().toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将用户输入与单元格内容统一成可搜索的文本。
|
||||
* 核心逻辑:统一 trim + lowerCase,避免筛选时受大小写和首尾空白干扰。
|
||||
* @param value - 原始值。
|
||||
* @returns 可用于 includes 的归一化字符串。
|
||||
*/
|
||||
function normalizeInlineFilterKeyword(value: string): string {
|
||||
return String(value ?? '').trim().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将二维表格重新序列化为 CSV 文本,并自动处理逗号、换行、双引号转义。
|
||||
* 核心逻辑:展示层与下载层共用这一序列化逻辑,保证用户看到的列头与下载文件完全一致。
|
||||
* @param rows - 需要写回 CSV 的二维数组,首行为表头。
|
||||
* @returns 可直接下载的 CSV 文本。
|
||||
*/
|
||||
function serializeCsvRows(rows: string[][]): string {
|
||||
return rows.map((row) => row.map((cell) => {
|
||||
const value = String(cell ?? '');
|
||||
if (/[",\r\n]/.test(value)) {
|
||||
return `"${value.replace(/"/g, '""')}"`;
|
||||
}
|
||||
return value;
|
||||
}).join(',')).join('\r\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 CSV 文本转成结构化表格,供聊天文件弹窗展示全部数据。
|
||||
* 核心逻辑:首行先做中文列名转换;若存在 id 列则重写为从 1 递增的序号,确保弹窗与下载文件显示一致。
|
||||
* @param file - 当前预览文件。
|
||||
* @returns 表头、完整数据行和总行数。
|
||||
*/
|
||||
function buildInlinePreviewTable(file: InlineDownloadFile): InlinePreviewTable {
|
||||
const isCsv = (file.mime_type || '').includes('csv') || /\.csv$/i.test(file.name);
|
||||
if (!isCsv || !file.data) {
|
||||
return { rawHeaders: [], headers: [], allRows: [], totalRows: 0, isCsv: false };
|
||||
}
|
||||
|
||||
const lines = file.data
|
||||
.replace(/\r\n/g, '\n')
|
||||
.replace(/\r/g, '\n')
|
||||
.split('\n')
|
||||
.filter((line) => line.length > 0);
|
||||
|
||||
if (lines.length === 0) {
|
||||
return { rawHeaders: [], headers: [], allRows: [], totalRows: 0, isCsv: true };
|
||||
}
|
||||
|
||||
const headerLine = lines[0] || '';
|
||||
const rawHeaders = parseCsvLine(headerLine);
|
||||
const dataRows = lines.slice(1).map((line) => parseCsvLine(line));
|
||||
const idColumnIndex = rawHeaders.findIndex((header) => String(header || '').trim().toLowerCase() === 'id');
|
||||
const headers = rawHeaders.map((header) => localizeInlineTableHeader(header));
|
||||
const allRows = dataRows.map((row, rowIndex) => rawHeaders.map((_, columnIndex) => {
|
||||
if (columnIndex === idColumnIndex) {
|
||||
return String(rowIndex + 1);
|
||||
}
|
||||
return normalizeInlineTableCell(row[columnIndex] ?? '');
|
||||
}));
|
||||
return {
|
||||
rawHeaders,
|
||||
headers,
|
||||
allRows,
|
||||
totalRows: dataRows.length,
|
||||
isCsv: true,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装当前消息内嵌文件的展示模型。
|
||||
* 核心逻辑:为每个文件预先计算 CSV 行数与表格内容,供按钮显示条件和弹窗直接复用。
|
||||
* @returns 当前消息可操作的文件条目列表。
|
||||
*/
|
||||
const inlineFileEntries = computed<InlineFileEntry[]>(() => inlineDownloadFiles.value.map((file, fileIndex) => ({
|
||||
file,
|
||||
fileIndex,
|
||||
table: buildInlinePreviewTable(file),
|
||||
})));
|
||||
|
||||
/**
|
||||
* 仅当数据量大于 5 行时展示“查看全部数据”入口。
|
||||
* 核心逻辑:小结果集直接依赖聊天正文里的预览表格,不再额外重复提供 CSV 附件按钮。
|
||||
*/
|
||||
const actionableInlineFileEntries = computed(() => inlineFileEntries.value.filter((entry) => (
|
||||
entry.table.totalRows === 0 || entry.table.totalRows > 5
|
||||
)));
|
||||
const activeInlineDialogEntry = ref<InlineFileEntry | null>(null);
|
||||
const inlineDialogAssetIdKeyword = ref('');
|
||||
const inlineDialogCustodianKeyword = ref('');
|
||||
const inlineDialogDeptKeyword = ref('');
|
||||
const inlineDialogPage = ref(1);
|
||||
|
||||
const activeInlineFilterIndexes = computed(() => {
|
||||
const table = activeInlineDialogEntry.value?.table;
|
||||
if (!table) {
|
||||
return { assetId: -1, custodianPerson: -1, custodianDept: -1 };
|
||||
}
|
||||
return {
|
||||
assetId: findInlineTableHeaderIndex(table.rawHeaders, ['asset_id', 'asset_no']),
|
||||
custodianPerson: findInlineTableHeaderIndex(table.rawHeaders, ['custodian_person', 'custodian_name']),
|
||||
custodianDept: findInlineTableHeaderIndex(table.rawHeaders, ['custodian_dept', 'department_name']),
|
||||
};
|
||||
});
|
||||
|
||||
const activeInlineFilteredRows = computed(() => {
|
||||
const entry = activeInlineDialogEntry.value;
|
||||
if (!entry) return [];
|
||||
|
||||
const filters = {
|
||||
assetId: normalizeInlineFilterKeyword(inlineDialogAssetIdKeyword.value),
|
||||
custodianPerson: normalizeInlineFilterKeyword(inlineDialogCustodianKeyword.value),
|
||||
custodianDept: normalizeInlineFilterKeyword(inlineDialogDeptKeyword.value),
|
||||
};
|
||||
const indexes = activeInlineFilterIndexes.value;
|
||||
|
||||
return entry.table.allRows.filter((row) => {
|
||||
const assetIdValue = indexes.assetId >= 0 ? normalizeInlineFilterKeyword(row[indexes.assetId] ?? '') : '';
|
||||
const custodianValue = indexes.custodianPerson >= 0 ? normalizeInlineFilterKeyword(row[indexes.custodianPerson] ?? '') : '';
|
||||
const deptValue = indexes.custodianDept >= 0 ? normalizeInlineFilterKeyword(row[indexes.custodianDept] ?? '') : '';
|
||||
return (!filters.assetId || assetIdValue.includes(filters.assetId))
|
||||
&& (!filters.custodianPerson || custodianValue.includes(filters.custodianPerson))
|
||||
&& (!filters.custodianDept || deptValue.includes(filters.custodianDept));
|
||||
});
|
||||
});
|
||||
|
||||
const activeInlineTotalPages = computed(() => Math.max(1, Math.ceil(activeInlineFilteredRows.value.length / INLINE_DIALOG_PAGE_SIZE)));
|
||||
const activeInlinePageRows = computed(() => {
|
||||
const startIndex = (inlineDialogPage.value - 1) * INLINE_DIALOG_PAGE_SIZE;
|
||||
return activeInlineFilteredRows.value.slice(startIndex, startIndex + INLINE_DIALOG_PAGE_SIZE);
|
||||
});
|
||||
const activeInlineRangeStart = computed(() => (activeInlineFilteredRows.value.length === 0 ? 0 : (inlineDialogPage.value - 1) * INLINE_DIALOG_PAGE_SIZE + 1));
|
||||
const activeInlineRangeEnd = computed(() => Math.min(inlineDialogPage.value * INLINE_DIALOG_PAGE_SIZE, activeInlineFilteredRows.value.length));
|
||||
|
||||
watch(activeInlineTotalPages, (totalPages) => {
|
||||
if (inlineDialogPage.value > totalPages) {
|
||||
inlineDialogPage.value = totalPages;
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
[inlineDialogAssetIdKeyword, inlineDialogCustodianKeyword, inlineDialogDeptKeyword],
|
||||
() => {
|
||||
inlineDialogPage.value = 1;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* 打开聊天文件全量预览弹窗。
|
||||
* 核心逻辑:点击按钮后把目标文件条目写入弹窗状态,在独立弹层中展示全部数据,避免聊天正文只保留 5 行。
|
||||
* @param entry - 当前消息中的可预览文件条目。
|
||||
*/
|
||||
function openInlinePreviewDialog(entry: InlineFileEntry): void {
|
||||
activeInlineDialogEntry.value = entry;
|
||||
inlineDialogAssetIdKeyword.value = '';
|
||||
inlineDialogCustodianKeyword.value = '';
|
||||
inlineDialogDeptKeyword.value = '';
|
||||
inlineDialogPage.value = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭聊天文件全量预览弹窗。
|
||||
*/
|
||||
function closeInlinePreviewDialog(): void {
|
||||
activeInlineDialogEntry.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置弹窗顶部筛选条件。
|
||||
*/
|
||||
function resetInlineDialogFilters(): void {
|
||||
inlineDialogAssetIdKeyword.value = '';
|
||||
inlineDialogCustodianKeyword.value = '';
|
||||
inlineDialogDeptKeyword.value = '';
|
||||
inlineDialogPage.value = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换弹窗分页页码。
|
||||
* 核心逻辑:统一做边界保护,防止筛选后页码越界。
|
||||
* @param nextPage - 目标页码。
|
||||
*/
|
||||
function changeInlineDialogPage(nextPage: number): void {
|
||||
inlineDialogPage.value = Math.min(Math.max(1, nextPage), activeInlineTotalPages.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应聊天消息里的内嵌文件下载按钮点击。
|
||||
* 核心逻辑:复用页面层 handlers 生成 Blob 下载,组件层只负责把当前文件对象回传出去。
|
||||
* @param file - 从当前消息内容解析出的单个可下载文件。
|
||||
*/
|
||||
function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
const table = buildInlinePreviewTable(file);
|
||||
if (!table.isCsv || table.headers.length === 0) {
|
||||
handlers.downloadInlineFile(file);
|
||||
return;
|
||||
}
|
||||
|
||||
const exportRows = activeInlineDialogEntry.value?.file === file ? activeInlineFilteredRows.value : table.allRows;
|
||||
const transformedCsv = serializeCsvRows([table.headers, ...exportRows]);
|
||||
handlers.downloadInlineFile({
|
||||
...file,
|
||||
data: `\uFEFF${transformedCsv}`,
|
||||
mime_type: 'text/csv;charset=utf-8',
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -142,12 +481,28 @@ const shippingParseReviewHandlers = computed<ShippingParseReviewHandlers>(() =>
|
||||
:on-action-click="(action) => handlers.onShippingActionClick(message, action)"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
v-else-if="renderedMarkdown"
|
||||
class="chat-markdown prose prose-sm max-w-none leading-7 text-primary prose-a:text-blue-600 prose-p:my-1 prose-li:my-0.5 prose-ol:my-2 prose-ul:my-2 prose-headings:my-2 prose-hr:my-3 prose-code:rounded prose-code:bg-slate-100 prose-code:px-1 prose-code:text-blue-700 prose-pre:my-3 prose-pre:border prose-pre:border-slate-700 prose-pre:bg-slate-900 prose-pre:text-slate-100 prose-th:border prose-th:border-slate-200 prose-th:bg-slate-50 prose-th:px-3 prose-th:py-2 prose-th:text-left prose-td:border prose-td:border-slate-200 prose-td:px-3 prose-td:py-2"
|
||||
@click="handlers.onMarkdownClick"
|
||||
v-html="handlers.renderMarkdown(message.content)"
|
||||
v-html="renderedMarkdown"
|
||||
/>
|
||||
|
||||
<div v-if="actionableInlineFileEntries.length > 0" class="mt-4">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button
|
||||
v-for="entry in actionableInlineFileEntries"
|
||||
:key="`${message.local_id || index}-inline-file-${entry.file.name}-${entry.fileIndex}`"
|
||||
type="button"
|
||||
class="inline-flex max-w-full items-center gap-2 rounded-xl border border-brand-200 bg-brand-50 px-3 py-2 text-xs font-medium text-brand-700 transition hover:bg-brand-100"
|
||||
:title="$t('chat.inlineFile.preview')"
|
||||
@click="openInlinePreviewDialog(entry)"
|
||||
>
|
||||
<Eye class="h-3.5 w-3.5 shrink-0" />
|
||||
<span class="truncate">{{ entry.file.name }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="message.role === 'assistant' && handlers.canOpenQueryPreview(message)"
|
||||
class="mt-4"
|
||||
@@ -296,6 +651,148 @@ const shippingParseReviewHandlers = computed<ShippingParseReviewHandlers>(() =>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="activeInlineDialogEntry"
|
||||
class="dialog-overlay z-[130] items-center"
|
||||
@click.self="closeInlinePreviewDialog"
|
||||
>
|
||||
<div class="dialog-panel flex max-h-[88vh] w-[min(96vw,1360px)] max-w-[1360px] flex-col">
|
||||
<div class="dialog-header">
|
||||
<div>
|
||||
<h3 class="section-title">{{ activeInlineDialogEntry.file.name }}</h3>
|
||||
<p class="section-desc mt-1">
|
||||
{{ $t('chat.inlineFile.previewHint', { rows: activeInlineDialogEntry.table.totalRows }) }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-brand-200 bg-brand-50 px-3 py-2 text-xs font-medium text-brand-700 transition hover:bg-brand-100"
|
||||
@click="handleInlineDownload(activeInlineDialogEntry.file)"
|
||||
>
|
||||
<Download class="h-3.5 w-3.5" />
|
||||
{{ $t('chat.inlineFile.download') }}
|
||||
</button>
|
||||
<button type="button" class="btn-icon-ds" aria-label="关闭" @click="closeInlinePreviewDialog">
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-body flex min-h-0 flex-1 flex-col gap-4 border-t-0 pt-4">
|
||||
<div
|
||||
v-if="activeInlineDialogEntry.table.headers.length > 0"
|
||||
class="grid gap-3 md:grid-cols-4"
|
||||
>
|
||||
<input
|
||||
v-model="inlineDialogAssetIdKeyword"
|
||||
type="text"
|
||||
class="rounded-xl border border-default bg-surface px-3 py-2 text-sm text-primary outline-none transition focus:border-blue-400"
|
||||
:placeholder="$t('chat.inlineFile.filters.assetId')"
|
||||
/>
|
||||
<input
|
||||
v-model="inlineDialogCustodianKeyword"
|
||||
type="text"
|
||||
class="rounded-xl border border-default bg-surface px-3 py-2 text-sm text-primary outline-none transition focus:border-blue-400"
|
||||
:placeholder="$t('chat.inlineFile.filters.custodianPerson')"
|
||||
/>
|
||||
<input
|
||||
v-model="inlineDialogDeptKeyword"
|
||||
type="text"
|
||||
class="rounded-xl border border-default bg-surface px-3 py-2 text-sm text-primary outline-none transition focus:border-blue-400"
|
||||
:placeholder="$t('chat.inlineFile.filters.custodianDept')"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary transition hover:bg-surface-soft"
|
||||
@click="resetInlineDialogFilters"
|
||||
>
|
||||
{{ $t('chat.inlineFile.filters.reset') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="min-h-0 flex-1 overflow-auto rounded-2xl border border-default bg-surface">
|
||||
<table
|
||||
v-if="activeInlineDialogEntry.table.headers.length > 0"
|
||||
class="min-w-full border-collapse text-sm"
|
||||
>
|
||||
<thead class="sticky top-0 z-10 bg-slate-50">
|
||||
<tr>
|
||||
<th
|
||||
v-for="(header, headerIndex) in activeInlineDialogEntry.table.headers"
|
||||
:key="`${activeInlineDialogEntry.file.name}-dialog-header-${headerIndex}`"
|
||||
class="border border-slate-200 px-3 py-2 text-left font-semibold text-primary"
|
||||
>
|
||||
{{ header || '-' }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="(row, rowIndex) in activeInlinePageRows"
|
||||
:key="`${activeInlineDialogEntry.file.name}-dialog-row-${rowIndex}`"
|
||||
class="odd:bg-white even:bg-slate-50/50"
|
||||
>
|
||||
<td
|
||||
v-for="(cell, cellIndex) in row"
|
||||
:key="`${activeInlineDialogEntry.file.name}-dialog-cell-${rowIndex}-${cellIndex}`"
|
||||
class="max-w-[320px] border border-slate-200 px-3 py-2 align-top text-secondary"
|
||||
>
|
||||
<div class="whitespace-pre-wrap break-all">{{ cell || '-' }}</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div v-else class="p-4 text-sm text-secondary">
|
||||
<div class="whitespace-pre-wrap break-all">{{ activeInlineDialogEntry.file.data }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="activeInlineDialogEntry.table.headers.length > 0"
|
||||
class="flex flex-col gap-3 md:flex-row md:items-center md:justify-between"
|
||||
>
|
||||
<div class="text-sm text-muted">
|
||||
{{
|
||||
activeInlineFilteredRows.length > 0
|
||||
? $t('chat.inlineFile.pagination.range', {
|
||||
start: activeInlineRangeStart,
|
||||
end: activeInlineRangeEnd,
|
||||
total: activeInlineFilteredRows.length,
|
||||
})
|
||||
: $t('chat.inlineFile.pagination.empty')
|
||||
}}
|
||||
</div>
|
||||
<div
|
||||
v-if="activeInlineFilteredRows.length > INLINE_DIALOG_PAGE_SIZE"
|
||||
class="flex items-center gap-2"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary transition hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="inlineDialogPage <= 1"
|
||||
@click="changeInlineDialogPage(inlineDialogPage - 1)"
|
||||
>
|
||||
{{ $t('chat.inlineFile.pagination.prev') }}
|
||||
</button>
|
||||
<div class="text-sm text-muted">
|
||||
{{ $t('chat.inlineFile.pagination.page', { page: inlineDialogPage, total: activeInlineTotalPages }) }}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary transition hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="inlineDialogPage >= activeInlineTotalPages"
|
||||
@click="changeInlineDialogPage(inlineDialogPage + 1)"
|
||||
>
|
||||
{{ $t('chat.inlineFile.pagination.next') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in new issue
Block a user