1461 lines
57 KiB
Vue
1461 lines
57 KiB
Vue
/**
|
|
* features/chat/components/messages/ChatMessageBubble.vue
|
|
* 用途:渲染单条聊天消息,统一承接用户气泡、助手 Markdown、内嵌文件下载、请假/出货子组件与操作栏。
|
|
* 依赖:Vue computed、lucide 图标、消息附件/Leave/Shipping 子组件、chat.types 与页面级 handlers。
|
|
* 逻辑:由 ChatMessageList 按消息逐条挂载;货代履约写按钮不在气泡内渲染,仅展示只读卡与深链通知。
|
|
* 用户附件区支持 summaryOnly:下方已有抽取进度卡时只显示附件摘要。
|
|
* 助手 Markdown 排版在本组件内收口:全局 base 只恢复标题字重,列表序号/圆点、
|
|
* 层级缩进与标题字号层级由 scoped 样式统一补齐,避免回答渲染成无结构平铺文本。
|
|
* 兼容:同时承接采购合同审查、库存映射、订单提取和 Mermaid 展示。
|
|
*/
|
|
<script setup lang="ts">
|
|
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { Check, Copy, Download, Edit2, Eye, LayoutGrid, MessageSquareText, RotateCw, X } from 'lucide-vue-next';
|
|
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
|
import LeaveMessageBlock, { type LeaveMessageHandlers } from './LeaveMessageBlock.vue';
|
|
import ChatMessageAttachmentList from './ChatMessageAttachmentList.vue';
|
|
import MaintenanceDeviceResultCard from './MaintenanceDeviceResultCard.vue';
|
|
import ContractReviewResultCard from './ContractReviewResultCard.vue';
|
|
import TransferMessageView from './TransferMessageView.vue';
|
|
import ShippingMatchResultCard from './ShippingMatchResultCard.vue';
|
|
import ShippingParseReviewMessage, { type ShippingParseReviewHandlers } from './ShippingParseReviewMessage.vue';
|
|
import type { ShippingMessageHandlers } from './shippingMessageHandlers';
|
|
import TrainingExamQuestionMessage, { type TrainingHandlers } from './TrainingExamQuestionMessage.vue';
|
|
import TrainingVideoMessage from './TrainingVideoMessage.vue';
|
|
import TrainingSummaryMessage from './TrainingSummaryMessage.vue';
|
|
import TrainingResultCard from './TrainingResultCard.vue';
|
|
import ShippingOrderExtractionCard from '../shipping/ShippingOrderExtractionCard.vue';
|
|
import { buildMermaidFlowFallbackHtml } from '../../utils/mermaidChart';
|
|
import type { ChatMessage, InlineDownloadFile, SourceFileLink } from '../../types/chat.types';
|
|
import type { ShippingMatchResultPayload } from '../../types/shipping.types';
|
|
import type { MaintenanceDevice } from '@/features/maintenance/types/ledger.types';
|
|
import type { MaintenanceRecord } from '@/features/maintenance/types/record.types';
|
|
|
|
export interface ChatMessageBubbleHandlers {
|
|
renderMarkdown: (text: string) => string;
|
|
onMarkdownClick: (event: MouseEvent) => void;
|
|
openAssetHistory: (assetId: string, assetName?: string) => void;
|
|
openAssetImage: (assetId: string, assetName?: string) => void;
|
|
getInlineDownloadFiles: (text: string) => { cleanedText: string; files: InlineDownloadFile[] };
|
|
downloadInlineFile: (file: InlineDownloadFile) => void;
|
|
getShippingMatchResultPayload: (msg: ChatMessage) => ShippingMatchResultPayload | null;
|
|
canOpenQueryPreview: (msg: ChatMessage) => boolean;
|
|
getQueryPreviewSummary: (msg: ChatMessage) => string;
|
|
openQueryPreviewDialog: (msg: ChatMessage) => void;
|
|
getDisplayRetrieverResources: (msg: ChatMessage) => Array<Record<string, unknown>>;
|
|
getSourceLinks: (resources: Array<Record<string, unknown>>) => SourceFileLink[];
|
|
shouldExpandSourceDetails: (msg: ChatMessage) => boolean;
|
|
getSourceTitle: (doc: Record<string, unknown>) => string;
|
|
getSourceMeta: (doc: Record<string, unknown>) => string;
|
|
getSourceBrief: (doc: Record<string, unknown>) => string;
|
|
openPreview: (file: SourceFileLink) => void;
|
|
}
|
|
|
|
const {
|
|
message,
|
|
index,
|
|
messageCount,
|
|
isThinking,
|
|
showChatRating,
|
|
copiedIndex,
|
|
isLatestAssistantMessage,
|
|
handlers,
|
|
leaveHandlers,
|
|
shippingHandlers,
|
|
attachmentSummaryOnly = false,
|
|
} = defineProps<{
|
|
message: ChatMessage;
|
|
index: number;
|
|
messageCount: number;
|
|
isThinking: boolean;
|
|
showChatRating: boolean;
|
|
copiedIndex: number | null;
|
|
isShippingNoticeAgent: boolean;
|
|
isLatestAssistantMessage: boolean;
|
|
handlers: ChatMessageBubbleHandlers;
|
|
leaveHandlers: LeaveMessageHandlers;
|
|
shippingHandlers: ShippingMessageHandlers;
|
|
trainingHandlers: TrainingHandlers;
|
|
/** 下方已有货代进度卡时,用户气泡附件只显示摘要。 */
|
|
attachmentSummaryOnly?: boolean;
|
|
}>();
|
|
|
|
const emit = defineEmits<{
|
|
copy: [];
|
|
edit: [content: string];
|
|
resend: [content: string];
|
|
regenerate: [];
|
|
'open-feedback': [];
|
|
'maintenance-edit-record': [record: MaintenanceRecord];
|
|
'maintenance-view-record-history': [device: MaintenanceDevice];
|
|
'maintenance-create-record-for-device': [device: MaintenanceDevice];
|
|
}>();
|
|
|
|
const authStore = useAuthStore();
|
|
const { t } = useI18n();
|
|
const INLINE_DOWNLOAD_ALLOWED_EMPLOYEE_ID = '17070141';
|
|
const RESTRICTED_INLINE_DOWNLOAD_FILE_NAME = '资产明细全量导出表.csv';
|
|
|
|
/** 合同审查结果卡:自身已是完整卡片,外层只需透明容器。 */
|
|
const isContractReviewMessage = computed(() => message.type === 'procurement-contract-review');
|
|
const isTransferMessage = computed(
|
|
() =>
|
|
message.type === 'transfer-match'
|
|
|| message.type === 'transfer-progress'
|
|
|| message.type === 'transfer-result',
|
|
);
|
|
/** 调拨消息带宽表格(匹配明细 10+ 列),放宽气泡宽度上限避免横向挤压成局部布局。 */
|
|
const wideMessage = computed(() => isTransferMessage.value || isContractReviewMessage.value);
|
|
|
|
const isLeaveMessage = computed(() =>
|
|
message.type === 'leave-form'
|
|
|| message.type === 'leave-confirmation'
|
|
|| message.type === 'leave-result',
|
|
);
|
|
|
|
// 员工培训的答题、结果与视频步骤统一收口到工作区,聊天区仅保留普通问答,不再承接培训操作卡片。
|
|
const isTrainingExamMessage = computed(() => false);
|
|
const isTrainingVideoMessage = computed(() => false);
|
|
const isTrainingSummaryMessage = computed(() => false);
|
|
const isTrainingResultMessage = computed(() => false);
|
|
|
|
const retrieverResources = computed(() => handlers.getDisplayRetrieverResources(message));
|
|
const sourceLinks = computed(() => handlers.getSourceLinks(retrieverResources.value));
|
|
|
|
const showSourceSection = computed(() => {
|
|
if (message.role !== 'assistant' || isLeaveMessage.value) return false;
|
|
return retrieverResources.value.length > 0
|
|
|| (message.attribution_parts?.length ?? 0) > 0
|
|
|| sourceLinks.value.length > 0;
|
|
});
|
|
|
|
const hasUserContent = computed(() => message.role === 'user' && String(message.content || '').trim().length > 0);
|
|
const hasUserAttachments = computed(() => message.role === 'user' && !!message.attachments?.length);
|
|
const hasUserPayload = computed(() => hasUserContent.value || hasUserAttachments.value);
|
|
const showActions = computed(() => (
|
|
message.type !== 'leave-form'
|
|
&& (message.role !== 'user' || hasUserContent.value)
|
|
));
|
|
const shippingOrderExtractionState = computed(() => message.shipping_order_extraction_state);
|
|
const retryingOrderExtraction = ref(false);
|
|
const refreshingOrderExtraction = ref(false);
|
|
const cancellingOrderExtraction = ref(false);
|
|
const shippingOrderExtractionRunNo = computed(() => {
|
|
const payload = message.payload && typeof message.payload === 'object'
|
|
? message.payload as Record<string, unknown>
|
|
: {};
|
|
return String(payload.order_extraction_run_no || '').trim();
|
|
});
|
|
const shippingOrderExtractionReadonly = computed(() => (
|
|
shippingOrderExtractionState.value?.isCurrent === false
|
|
|| Boolean(shippingOrderExtractionState.value?.supersedingRunNo)
|
|
));
|
|
/** 失败卡片复用原 Run 重试;按钮本地防重,成功后状态卡由 Run 轮询原位更新。 */
|
|
const retryShippingOrderExtraction = async () => {
|
|
if (!shippingOrderExtractionRunNo.value || retryingOrderExtraction.value) return;
|
|
retryingOrderExtraction.value = true;
|
|
try {
|
|
await shippingHandlers.retryOrderExtractionRun(shippingOrderExtractionRunNo.value);
|
|
} finally {
|
|
retryingOrderExtraction.value = false;
|
|
}
|
|
};
|
|
/** 只读刷新 Run 投影,不改变后台业务状态。 */
|
|
const refreshShippingOrderExtraction = async () => {
|
|
if (!shippingOrderExtractionRunNo.value || refreshingOrderExtraction.value) return;
|
|
refreshingOrderExtraction.value = true;
|
|
try {
|
|
await shippingHandlers.refreshOrderExtractionRun(shippingOrderExtractionRunNo.value);
|
|
} finally {
|
|
refreshingOrderExtraction.value = false;
|
|
}
|
|
};
|
|
/** 请求取消整批;确认后走请求语义,不伪造即时终态。 */
|
|
const cancelShippingOrderExtraction = async (reason?: string) => {
|
|
if (!shippingOrderExtractionRunNo.value || cancellingOrderExtraction.value) return;
|
|
cancellingOrderExtraction.value = true;
|
|
try {
|
|
await shippingHandlers.cancelOrderExtractionRun(shippingOrderExtractionRunNo.value, reason || null);
|
|
} finally {
|
|
cancellingOrderExtraction.value = false;
|
|
}
|
|
};
|
|
const isLastMessage = computed(() => index === messageCount - 1 || (message.role === 'assistant' && isLatestAssistantMessage));
|
|
const isCopied = computed(() => copiedIndex === index);
|
|
const renderedMarkdown = computed(() => (
|
|
message.role === 'assistant' ? handlers.renderMarkdown(message.content) : ''
|
|
));
|
|
const markdownContainer = ref<HTMLElement | null>(null);
|
|
|
|
/**
|
|
* 用途:将回答中的 Mermaid 流程图代码块转换成内嵌流程卡片。
|
|
* 依赖:useChatPageMarkdown 为 `mermaid` 代码块保留 `.chat-mermaid` 标记。
|
|
* 逻辑:不直接执行 Mermaid,避免 Dify 非标准图语法使 Mermaid 在页面根节点注入错误 SVG;
|
|
* 对可提取的主流程展示节点卡片和箭头,其余图表代码块静默隐藏,不影响普通文本与表格。
|
|
*/
|
|
const renderMermaidCharts = async () => {
|
|
await nextTick();
|
|
const container = markdownContainer.value;
|
|
if (!container) return;
|
|
const nodes = Array.from(container.querySelectorAll<HTMLElement>('pre.chat-mermaid:not([data-mermaid-rendered])'));
|
|
if (!nodes.length) return;
|
|
for (const node of nodes) {
|
|
node.dataset.mermaidRendered = 'pending';
|
|
const fallbackHtml = buildMermaidFlowFallbackHtml(node.textContent || '');
|
|
if (fallbackHtml) {
|
|
node.outerHTML = fallbackHtml;
|
|
continue;
|
|
}
|
|
node.remove();
|
|
}
|
|
};
|
|
|
|
onMounted(() => { void renderMermaidCharts(); });
|
|
watch(renderedMarkdown, () => { void renderMermaidCharts(); });
|
|
const inlineDownloadFiles = computed(() => (
|
|
message.role === 'assistant' ? handlers.getInlineDownloadFiles(message.content).files : []
|
|
));
|
|
const shippingParseReviewHandlers = computed<ShippingParseReviewHandlers>(() => ({
|
|
getPayload: shippingHandlers.getParseReviewPayload,
|
|
updateHeader: shippingHandlers.updateHeader,
|
|
updateLine: shippingHandlers.updateLine,
|
|
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;
|
|
}
|
|
|
|
/** 英文字段名 → chat.assetColumns.* key(展示用;匹配仍用 aliases 中的中英文别名) */
|
|
const FIXED_ASSET_HEADER_KEYS: Record<string, string> = {
|
|
id: 'chat.assetColumns.id',
|
|
asset_id: 'chat.assetColumns.assetId',
|
|
asset_no: 'chat.assetColumns.assetId',
|
|
asset_name: 'chat.assetColumns.assetName',
|
|
currency_amount: 'chat.assetColumns.currencyAmount',
|
|
specification: 'chat.assetColumns.specification',
|
|
account_period: 'chat.assetColumns.accountPeriod',
|
|
operating_center_code: 'chat.assetColumns.accountPeriod',
|
|
custodian_person: 'chat.assetColumns.custodianPerson',
|
|
custodian_name: 'chat.assetColumns.custodianPerson',
|
|
custodian_dept: 'chat.assetColumns.custodianDept',
|
|
department_name: 'chat.assetColumns.custodianDept',
|
|
image: 'chat.assetColumns.image',
|
|
picture: 'chat.assetColumns.image',
|
|
storage_location: 'chat.assetColumns.storageLocation',
|
|
location_name: 'chat.assetColumns.storageLocation',
|
|
asset_status: 'chat.assetColumns.assetStatus',
|
|
reserved_field: 'chat.assetColumns.residualValue',
|
|
residual_value: 'chat.assetColumns.residualValue',
|
|
supplier: 'chat.assetColumns.supplier',
|
|
vendor_name: 'chat.assetColumns.supplier',
|
|
asset_nature: 'chat.assetColumns.assetNature',
|
|
nature: 'chat.assetColumns.assetNature',
|
|
amount_local: 'chat.assetColumns.currencyAmount',
|
|
unit_price: 'chat.assetColumns.currencyAmount',
|
|
quantity: 'chat.assetColumns.quantity',
|
|
unit: 'chat.assetColumns.unit',
|
|
unit_of_measurement: 'chat.assetColumns.unit',
|
|
acquisition_date: 'chat.assetColumns.acquisitionDate',
|
|
acquired_date: 'chat.assetColumns.acquisitionDate',
|
|
accounting_date: 'chat.assetColumns.accountingDate',
|
|
recorded_date: 'chat.assetColumns.accountingDate',
|
|
created_at: 'chat.assetColumns.createdAt',
|
|
created_time: 'chat.assetColumns.createdAt',
|
|
updated_at: 'chat.assetColumns.updatedAt',
|
|
snapshot_time: 'chat.assetColumns.snapshotTime',
|
|
};
|
|
const FIXED_ASSET_CANONICAL_COLUMNS = [
|
|
{ key: 'id', labelKey: 'chat.assetColumns.id', aliases: ['id', '序号'] },
|
|
{ key: 'asset_id', labelKey: 'chat.assetColumns.assetId', aliases: ['asset_id', 'asset_no', '资产编号'] },
|
|
{ key: 'asset_name', labelKey: 'chat.assetColumns.assetName', aliases: ['asset_name', '资产名称'] },
|
|
{ key: 'custodian_person', labelKey: 'chat.assetColumns.custodianPerson', aliases: ['custodian_person', 'custodian_name', '保管人', '保管人姓名'] },
|
|
{ key: 'custodian_dept', labelKey: 'chat.assetColumns.custodianDept', aliases: ['custodian_dept', 'department_name', '保管部门', '保管部门名称'] },
|
|
{ key: 'image', labelKey: 'chat.assetColumns.image', aliases: ['image', 'picture', '图片'] },
|
|
{ key: 'account_period', labelKey: 'chat.assetColumns.accountPeriod', aliases: ['account_period', 'operating_center_code', '账套'] },
|
|
{ key: 'supplier', labelKey: 'chat.assetColumns.supplier', aliases: ['supplier', 'vendor_name', '供应商', '供应厂商'] },
|
|
{ key: 'asset_status', labelKey: 'chat.assetColumns.assetStatus', aliases: ['asset_status', '资产状态'] },
|
|
{ key: 'quantity', labelKey: 'chat.assetColumns.quantity', aliases: ['quantity', '数量'] },
|
|
{ key: 'acquisition_date', labelKey: 'chat.assetColumns.acquisitionDate', aliases: ['acquisition_date', 'acquired_date', '取得时间', '取得日期'] },
|
|
] as const;
|
|
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();
|
|
const key = FIXED_ASSET_HEADER_KEYS[normalizedHeader];
|
|
return key ? t(key) : (header || '-');
|
|
}
|
|
|
|
/**
|
|
* 将固定资产时间字段统一裁剪为“年月日”。
|
|
* 核心逻辑:优先提取 `YYYY-MM-DD` 或 `YYYY/MM/DD` 形式;若无法识别标准日期,则保留原始值避免误改内容。
|
|
* @param value - 原始时间文本。
|
|
* @returns 仅保留年月日的展示值。
|
|
*/
|
|
function formatInlineDateOnly(value: string): string {
|
|
const normalized = String(value ?? '').trim();
|
|
if (!normalized) return '';
|
|
const dateMatch = normalized.match(/(\d{4})[-/](\d{1,2})[-/](\d{1,2})/);
|
|
if (!dateMatch) return normalized;
|
|
const year = dateMatch[1] || '';
|
|
const month = dateMatch[2] || '';
|
|
const day = dateMatch[3] || '';
|
|
if (!year || !month || !day) return normalized;
|
|
return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;
|
|
}
|
|
|
|
/**
|
|
* 统一表格中的空值展示。
|
|
* 核心逻辑:对空串、短横线、null/none 等占位值统一显示本地化“无”,但保留数字 0 与正常文本。
|
|
* @param value - 原始单元格值。
|
|
* @returns 归一化后的展示值。
|
|
*/
|
|
function normalizeInlineTableCell(value: string): string {
|
|
const normalized = String(value ?? '').trim();
|
|
if (!normalized) return t('chat.assetColumns.empty');
|
|
if (['-', '--', 'null', 'none', 'n/a', 'na'].includes(normalized.toLowerCase())) return t('chat.assetColumns.empty');
|
|
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()));
|
|
}
|
|
|
|
/**
|
|
* 判断当前 CSV 是否为固定资产明细导出结构。
|
|
* 核心逻辑:按业务关键列做命中检测,只有命中固定资产列集时才收敛为指定 10 列,避免影响其他 Agent 的 CSV 预览。
|
|
* @param headers - CSV 原始表头。
|
|
* @returns 是否按固定资产明细规则处理。
|
|
*/
|
|
function isFixedAssetInlineTable(headers: string[]): boolean {
|
|
return FIXED_ASSET_CANONICAL_COLUMNS
|
|
.filter((column) => column.key !== 'id')
|
|
.filter((column) => findInlineTableHeaderIndex(headers, [...column.aliases]) >= 0)
|
|
.length >= 5;
|
|
}
|
|
|
|
/**
|
|
* 将用户输入与单元格内容统一成可搜索的文本。
|
|
* 核心逻辑:统一 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');
|
|
}
|
|
|
|
/**
|
|
* 按固定资产业务要求抽取并重排列顺序。
|
|
* 核心逻辑:只输出指定的 10 个业务字段;若某列缺失则补“无”,并把取得时间统一裁剪为年月日。
|
|
* @param rawHeaders - CSV 原始表头。
|
|
* @param dataRows - 原始数据行。
|
|
* @returns 规范化后的表头与数据行。
|
|
*/
|
|
function buildFixedAssetInlineTable(rawHeaders: string[], dataRows: string[][]): InlinePreviewTable {
|
|
const headers = FIXED_ASSET_CANONICAL_COLUMNS.map((column) => t(column.labelKey));
|
|
const canonicalHeaders = FIXED_ASSET_CANONICAL_COLUMNS.map((column) => column.key);
|
|
const allRows = dataRows.map((row, rowIndex) => FIXED_ASSET_CANONICAL_COLUMNS.map((column) => {
|
|
if (column.key === 'id') return String(rowIndex + 1);
|
|
if (column.key === 'image') {
|
|
const assetIdColumnIndex = findInlineTableHeaderIndex(rawHeaders, ['asset_id', 'asset_no', '资产编号']);
|
|
const rawAssetId = assetIdColumnIndex >= 0 ? row[assetIdColumnIndex] ?? '' : '';
|
|
const normalizedAssetId = String(rawAssetId ?? '').trim();
|
|
const imageColumnIndex = findInlineTableHeaderIndex(rawHeaders, ['image', 'picture', '图片']);
|
|
const rawImageValue = imageColumnIndex >= 0 ? row[imageColumnIndex] ?? '' : '';
|
|
const normalizedImageValue = String(rawImageValue ?? '').trim();
|
|
if (normalizedImageValue) {
|
|
return normalizeInlineTableCell(normalizedImageValue);
|
|
}
|
|
return normalizedAssetId ? t('chat.assetColumns.view') : t('chat.assetColumns.empty');
|
|
}
|
|
const columnIndex = findInlineTableHeaderIndex(rawHeaders, [...column.aliases]);
|
|
const rawValue = columnIndex >= 0 ? row[columnIndex] ?? '' : '';
|
|
const normalizedValue = column.key === 'acquisition_date'
|
|
? formatInlineDateOnly(rawValue)
|
|
: rawValue;
|
|
return normalizeInlineTableCell(normalizedValue);
|
|
}));
|
|
return {
|
|
rawHeaders: canonicalHeaders,
|
|
headers,
|
|
allRows,
|
|
totalRows: dataRows.length,
|
|
isCsv: true,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 将 CSV 文本转成结构化表格,供聊天文件弹窗展示全部数据。
|
|
* 核心逻辑:固定资产明细优先收敛为指定业务列与日期格式;其他 CSV 保持原表头映射,避免误伤通用附件预览。
|
|
* @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));
|
|
if (isFixedAssetInlineTable(rawHeaders)) {
|
|
return buildFixedAssetInlineTable(rawHeaders, dataRows);
|
|
}
|
|
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, assetName: -1, custodianPerson: -1, custodianDept: -1 };
|
|
}
|
|
return {
|
|
assetId: findInlineTableHeaderIndex(table.rawHeaders, ['asset_id', 'asset_no']),
|
|
assetName: findInlineTableHeaderIndex(table.rawHeaders, ['asset_name']),
|
|
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));
|
|
const currentUserEmployeeId = computed(() => String(authStore.user?.employee_id || '').trim());
|
|
|
|
/**
|
|
* 判断当前文件是否命中“仅指定工号可下载”的特殊管控。
|
|
* AI 触发时机:当聊天内嵌 CSV 预览头部要决定是否展示【下载数据】按钮,或真正执行下载前需要二次校验时调用。
|
|
* 核心逻辑:仅对 `资产明细全量导出表.csv` 启用强限制,其他附件继续沿用现有下载能力,避免误伤普通文件预览。
|
|
* 参数约束:传入文件名允许为空;空值或非目标文件一律视为不命中管控。
|
|
*/
|
|
function requiresRestrictedInlineDownload(file: InlineDownloadFile | null | undefined): boolean {
|
|
const fileName = String(file?.name || '').trim();
|
|
return fileName === RESTRICTED_INLINE_DOWNLOAD_FILE_NAME;
|
|
}
|
|
|
|
/**
|
|
* 校验当前用户是否有权下载当前内嵌文件。
|
|
* AI 触发时机:当页面需要控制【下载数据】按钮显隐,或下载函数执行前做权限兜底时调用。
|
|
* 核心逻辑:命中特殊管控文件时,只放行工号 `17070141`;其余文件保持原权限不变。
|
|
* 参数约束:仅负责前端展示层和交互层兜底,不替代后端鉴权;若后续接入通用权限系统,应优先复用统一能力。
|
|
*/
|
|
function canDownloadInlineFile(file: InlineDownloadFile | null | undefined): boolean {
|
|
if (!requiresRestrictedInlineDownload(file)) {
|
|
return true;
|
|
}
|
|
return currentUserEmployeeId.value === INLINE_DOWNLOAD_ALLOWED_EMPLOYEE_ID;
|
|
}
|
|
|
|
const canDownloadActiveInlineFile = computed(() => canDownloadInlineFile(activeInlineDialogEntry.value?.file));
|
|
|
|
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);
|
|
}
|
|
|
|
function canOpenInlineAssetHistory(cellIndex: number, cellValue: string): boolean {
|
|
const normalizedValue = String(cellValue || '').trim();
|
|
const imageIndex = activeInlineDialogEntry.value?.table.rawHeaders.findIndex((header) => header === 'image' || header === '图片') ?? -1;
|
|
if (cellIndex === activeInlineFilterIndexes.value.assetId) {
|
|
return !!normalizedValue && normalizedValue !== '-';
|
|
}
|
|
if (cellIndex === imageIndex) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function isInlineHighlightHeader(header: string): boolean {
|
|
return header === t('chat.assetColumns.assetId')
|
|
|| header === t('chat.assetColumns.image')
|
|
|| header === '资产编号'
|
|
|| header === '图片';
|
|
}
|
|
|
|
async function openInlineAssetHistory(row: string[], cellIndex: number): Promise<void> {
|
|
const indexes = activeInlineFilterIndexes.value;
|
|
const assetId = indexes.assetId >= 0 ? String(row[indexes.assetId] || '').trim() : '';
|
|
const assetName = indexes.assetName >= 0 ? String(row[indexes.assetName] || '').trim() : '';
|
|
if (!assetId || assetId === '-') return;
|
|
const imageIndex = activeInlineDialogEntry.value?.table.rawHeaders.findIndex((header) => header === 'image' || header === '图片') ?? -1;
|
|
closeInlinePreviewDialog();
|
|
await nextTick();
|
|
if (cellIndex === imageIndex) {
|
|
handlers.openAssetImage(assetId, assetName === '-' ? '' : assetName);
|
|
return;
|
|
}
|
|
handlers.openAssetHistory(assetId, assetName === '-' ? '' : assetName);
|
|
}
|
|
|
|
/**
|
|
* 响应聊天消息里的内嵌文件下载按钮点击。
|
|
* 核心逻辑:复用页面层 handlers 生成 Blob 下载,组件层只负责把当前文件对象回传出去。
|
|
* @param file - 从当前消息内容解析出的单个可下载文件。
|
|
*/
|
|
function handleInlineDownload(file: InlineDownloadFile): void {
|
|
if (!canDownloadInlineFile(file)) {
|
|
return;
|
|
}
|
|
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>
|
|
<div
|
|
:data-msg-index="index"
|
|
class="group mx-auto mb-6 flex w-full animate-slide-up"
|
|
:class="message.role === 'user' ? 'justify-end' : wideMessage ? 'max-w-[min(96vw,1500px)]' : 'max-w-4xl justify-start'"
|
|
>
|
|
<div
|
|
class="flex flex-col"
|
|
:class="message.role === 'user' ? 'max-w-[88%] md:max-w-[74%] items-end' : 'w-full'"
|
|
>
|
|
<div
|
|
v-if="message.role === 'assistant' || hasUserPayload"
|
|
class="text-[15px] leading-relaxed"
|
|
:class="message.role === 'user'
|
|
? 'rounded-2xl rounded-tr-sm bg-brand-600 px-5 py-2.5 text-white shadow-sm shadow-brand-500/15'
|
|
: isContractReviewMessage || isTransferMessage
|
|
? 'w-full'
|
|
: shippingOrderExtractionState
|
|
? 'w-full'
|
|
: 'chat-msg-assistant'"
|
|
>
|
|
<template v-if="message.role === 'user'">
|
|
<ChatMessageAttachmentList
|
|
v-if="message.attachments?.length"
|
|
:attachments="message.attachments"
|
|
:summary-only="attachmentSummaryOnly"
|
|
/>
|
|
<div v-if="hasUserContent" class="whitespace-pre-wrap px-2.5 py-1">{{ message.content }}</div>
|
|
</template>
|
|
<div v-else>
|
|
<ShippingOrderExtractionCard
|
|
v-if="shippingOrderExtractionState"
|
|
:state="shippingOrderExtractionState"
|
|
:run-no="shippingOrderExtractionRunNo"
|
|
:readonly="shippingOrderExtractionReadonly"
|
|
:readonly-reason="shippingOrderExtractionState?.readOnlyReason"
|
|
:retrying="retryingOrderExtraction"
|
|
:refreshing="refreshingOrderExtraction"
|
|
:cancelling="cancellingOrderExtraction"
|
|
@retry="retryShippingOrderExtraction"
|
|
@refresh="refreshShippingOrderExtraction"
|
|
@cancel="cancelShippingOrderExtraction"
|
|
/>
|
|
<LeaveMessageBlock
|
|
v-if="isLeaveMessage"
|
|
:message="message"
|
|
:index="index"
|
|
:handlers="leaveHandlers"
|
|
/>
|
|
<ShippingParseReviewMessage
|
|
v-if="message.type === 'shipping-parse-review' && shippingHandlers.getParseReviewPayload(message)"
|
|
:message="message"
|
|
:handlers="shippingParseReviewHandlers"
|
|
/>
|
|
<ShippingMatchResultCard
|
|
v-else-if="message.type === 'shipping-match-result' && handlers.getShippingMatchResultPayload(message)"
|
|
:task-id="handlers.getShippingMatchResultPayload(message)!.taskId"
|
|
:match-status="handlers.getShippingMatchResultPayload(message)!.match_status"
|
|
:line-results="handlers.getShippingMatchResultPayload(message)!.line_results"
|
|
:shortage-lines="handlers.getShippingMatchResultPayload(message)!.shortage_lines"
|
|
/>
|
|
<MaintenanceDeviceResultCard
|
|
v-else-if="message.type === 'maintenance-device-result'"
|
|
:message="message"
|
|
@edit-record="emit('maintenance-edit-record', $event)"
|
|
@view-record-history="emit('maintenance-view-record-history', $event)"
|
|
@create-record="emit('maintenance-create-record-for-device', $event)"
|
|
/>
|
|
<ContractReviewResultCard
|
|
v-else-if="message.type === 'procurement-contract-review'"
|
|
:message="message"
|
|
/>
|
|
<TransferMessageView
|
|
v-else-if="isTransferMessage"
|
|
:payload="(message.payload as Record<string, unknown> | undefined)"
|
|
/>
|
|
<TrainingExamQuestionMessage
|
|
v-else-if="isTrainingExamMessage && trainingHandlers.getQuestion()"
|
|
:question="trainingHandlers.getQuestion()!"
|
|
:current-question-index="trainingHandlers.getCurrentQuestionIndex()"
|
|
:answered-count="trainingHandlers.getAnsweredCount()"
|
|
:total-count="trainingHandlers.getTotalCount()"
|
|
:pass-score="trainingHandlers.getPassScore()"
|
|
:score="trainingHandlers.getScore()"
|
|
:selected-option-id="trainingHandlers.getSelectedOptionId()"
|
|
:answer-locked="trainingHandlers.getAnswerLocked()"
|
|
:feedback-correct="trainingHandlers.getFeedbackCorrect()"
|
|
:answer-label="trainingHandlers.getAnswerLabel()"
|
|
:latest-exam-feedback="trainingHandlers.getLatestExamFeedback()"
|
|
:is-thinking="isThinking"
|
|
@select="trainingHandlers.onSelect"
|
|
@next="trainingHandlers.onNext"
|
|
/>
|
|
<TrainingResultCard
|
|
v-else-if="isTrainingResultMessage"
|
|
:score="trainingHandlers.getResultScore()"
|
|
:is-passed="trainingHandlers.getResultPassed()"
|
|
:pass-score="trainingHandlers.getPassScore()"
|
|
:correct-count="trainingHandlers.getCorrectCount()"
|
|
:wrong-count="trainingHandlers.getWrongCount()"
|
|
:is-thinking="isThinking"
|
|
@restart="trainingHandlers.onRestartExam"
|
|
/>
|
|
|
|
<div
|
|
v-else-if="renderedMarkdown"
|
|
ref="markdownContainer"
|
|
class="markdown-body chat-markdown min-w-0 break-words text-sm leading-relaxed"
|
|
@click="handlers.onMarkdownClick"
|
|
v-html="renderedMarkdown"
|
|
/>
|
|
|
|
<TrainingVideoMessage
|
|
v-if="isTrainingVideoMessage"
|
|
:is-thinking="isThinking"
|
|
@play="trainingHandlers.onPlayVideo"
|
|
/>
|
|
<TrainingSummaryMessage
|
|
v-if="isTrainingSummaryMessage"
|
|
:summary-points="trainingHandlers.getSummaryPoints()"
|
|
:summary-checklist="trainingHandlers.getSummaryChecklist()"
|
|
:is-thinking="isThinking"
|
|
@start-exam="trainingHandlers.onStartExam"
|
|
/>
|
|
|
|
<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"
|
|
>
|
|
<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="handlers.openQueryPreviewDialog(message)"
|
|
>
|
|
<LayoutGrid class="h-3.5 w-3.5" />
|
|
{{ handlers.getQueryPreviewSummary(message) }}
|
|
</button>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div v-if="showSourceSection" class="mt-2 space-y-2">
|
|
<div v-if="sourceLinks.length > 0" class="flex flex-wrap gap-2">
|
|
<button
|
|
v-for="(file, linkIndex) in sourceLinks"
|
|
:key="`src-link-top-${linkIndex}-${file.url}`"
|
|
type="button"
|
|
class="break-all rounded-lg border border-brand-200 bg-brand-50 px-2.5 py-1.5 text-xs text-brand-700 transition-colors hover:bg-brand-100"
|
|
@click="handlers.openPreview(file)"
|
|
>
|
|
{{ file.name }}
|
|
</button>
|
|
</div>
|
|
|
|
<details
|
|
v-if="retrieverResources.length > 0"
|
|
class="rounded-xl border border-default bg-surface-soft/90 px-4 py-3"
|
|
:open="handlers.shouldExpandSourceDetails(message)"
|
|
>
|
|
<summary class="cursor-pointer text-xs font-semibold uppercase tracking-wide text-secondary">
|
|
{{ $t('chat.sourceDocs') }} ({{ retrieverResources.length }})
|
|
</summary>
|
|
<div class="mt-3 space-y-2">
|
|
<div
|
|
v-for="(doc, docIndex) in retrieverResources"
|
|
:key="`${doc.document_name || 'doc'}-${doc.segment_id || docIndex}`"
|
|
class="rounded-lg border border-default bg-surface p-3"
|
|
>
|
|
<div class="break-all text-sm font-semibold text-primary">{{ handlers.getSourceTitle(doc) }}</div>
|
|
<div v-if="handlers.getSourceMeta(doc)" class="mt-1 text-xs text-muted">{{ handlers.getSourceMeta(doc) }}</div>
|
|
<div v-if="handlers.getSourceBrief(doc)" class="mt-2 whitespace-pre-wrap break-all text-xs text-secondary">
|
|
{{ handlers.getSourceBrief(doc) }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</details>
|
|
|
|
<details
|
|
v-if="message.attribution_parts && message.attribution_parts.length > 0"
|
|
class="rounded-xl border border-default bg-surface-soft/90 px-4 py-3"
|
|
open
|
|
>
|
|
<summary class="cursor-pointer text-xs font-semibold uppercase tracking-wide text-secondary">
|
|
{{ $t('chat.attributionParts') }}
|
|
</summary>
|
|
<ul class="mt-3 space-y-2">
|
|
<li
|
|
v-for="(part, partIndex) in message.attribution_parts"
|
|
:key="`attr-${partIndex}`"
|
|
class="rounded-lg border border-default bg-surface p-3 text-xs text-secondary"
|
|
>
|
|
{{ part }}
|
|
</li>
|
|
</ul>
|
|
</details>
|
|
</div>
|
|
|
|
<div
|
|
v-if="showActions"
|
|
class="mt-1 flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100"
|
|
:class="message.role === 'user' ? 'justify-end text-muted' : 'justify-start text-muted'"
|
|
>
|
|
<button
|
|
type="button"
|
|
class="rounded-md p-1.5 text-xs transition-colors hover-surface-soft"
|
|
:title="$t('chat.actions.copy')"
|
|
@click.stop="emit('copy')"
|
|
>
|
|
<Check v-if="isCopied" class="h-3.5 w-3.5 text-emerald-500" />
|
|
<Copy v-else class="h-3.5 w-3.5" />
|
|
</button>
|
|
|
|
<template v-if="message.role === 'user'">
|
|
<button
|
|
type="button"
|
|
class="rounded-md p-1.5 text-xs transition-colors hover-surface-soft"
|
|
:title="$t('chat.actions.edit')"
|
|
@click.stop="emit('edit', message.content)"
|
|
>
|
|
<Edit2 class="h-3.5 w-3.5" />
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="rounded-md p-1.5 text-xs transition-colors hover-surface-soft"
|
|
:title="$t('chat.actions.resend')"
|
|
@click.stop="emit('resend', message.content)"
|
|
>
|
|
<RotateCw class="h-3.5 w-3.5" />
|
|
</button>
|
|
</template>
|
|
|
|
<template v-else>
|
|
<button
|
|
v-if="isLastMessage && !isThinking"
|
|
type="button"
|
|
class="rounded-md p-1.5 text-xs transition-colors hover-surface-soft"
|
|
:title="$t('chat.actions.regenerate')"
|
|
@click="emit('regenerate')"
|
|
>
|
|
<RotateCw class="h-3.5 w-3.5" />
|
|
</button>
|
|
<button
|
|
v-if="showChatRating && !isThinking && !message.rated"
|
|
type="button"
|
|
class="rounded-md p-1.5 text-xs transition-colors hover-surface-soft"
|
|
:title="$t('chat.rate')"
|
|
@click="emit('open-feedback')"
|
|
>
|
|
<MessageSquareText class="h-3.5 w-3.5" />
|
|
</button>
|
|
</template>
|
|
</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
|
|
v-if="canDownloadActiveInlineFile"
|
|
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="$t('common.close')" @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',
|
|
isInlineHighlightHeader(header) ? 'text-blue-800' : '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"
|
|
>
|
|
<button
|
|
v-if="canOpenInlineAssetHistory(cellIndex, cell)"
|
|
type="button"
|
|
class="whitespace-pre-wrap break-all text-left font-semibold text-blue-700 underline-offset-2 transition hover:text-blue-800 hover:underline"
|
|
@click="openInlineAssetHistory(row, cellIndex)"
|
|
>
|
|
{{ cell || '-' }}
|
|
</button>
|
|
<div v-else 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>
|
|
:deep(.chat-markdown) {
|
|
max-width: 100%;
|
|
}
|
|
|
|
/* ── Markdown 正文排版:标题层级 / 列表序号 / 层级缩进 ─────────────────────
|
|
背景:Tailwind preflight 会把 ul/ol 重置为无序号、无圆点、无缩进,Dify 返回的
|
|
结构化回答(### 标题 + 多级列表 + 有序步骤)会被渲染成平铺文本;
|
|
全局 base 层只恢复了标题字重,这里按聊天回答的高频结构统一补齐排版。 */
|
|
:deep(.chat-markdown h1),
|
|
:deep(.chat-markdown h2),
|
|
:deep(.chat-markdown h3) {
|
|
margin: 1em 0 0.5em;
|
|
font-size: 1.125rem;
|
|
line-height: 1.45;
|
|
}
|
|
|
|
:deep(.chat-markdown h4),
|
|
:deep(.chat-markdown h5),
|
|
:deep(.chat-markdown h6) {
|
|
margin: 0.875em 0 0.375em;
|
|
font-size: 1rem;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
:deep(.chat-markdown p) {
|
|
margin: 0.5em 0;
|
|
}
|
|
|
|
:deep(.chat-markdown strong) {
|
|
font-weight: 600;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
/* 列表缩进与序号:无序列表逐层 disc/circle/square 区分层级;有序列表(操作步骤)
|
|
无论嵌套在第几层都保持 1. 2. 3. 数字序号,与回答里“步骤”的业务语义一致 */
|
|
:deep(.chat-markdown ul),
|
|
:deep(.chat-markdown ol) {
|
|
margin: 0.375rem 0;
|
|
padding-left: 1.375rem;
|
|
}
|
|
|
|
:deep(.chat-markdown ul) {
|
|
list-style-type: disc;
|
|
}
|
|
|
|
:deep(.chat-markdown ol) {
|
|
list-style-type: decimal;
|
|
}
|
|
|
|
:deep(.chat-markdown ul ul) {
|
|
list-style-type: circle;
|
|
}
|
|
|
|
:deep(.chat-markdown ul ul ul) {
|
|
list-style-type: square;
|
|
}
|
|
|
|
:deep(.chat-markdown li) {
|
|
margin: 0.25rem 0;
|
|
}
|
|
|
|
:deep(.chat-markdown li::marker) {
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
:deep(.chat-markdown li > p) {
|
|
margin: 0.25rem 0;
|
|
}
|
|
|
|
:deep(.chat-markdown li > ul),
|
|
:deep(.chat-markdown li > ol) {
|
|
margin: 0.25rem 0;
|
|
}
|
|
|
|
/* 气泡内首尾元素贴边,避免首行/末行出现额外空隙 */
|
|
:deep(.chat-markdown > :first-child) {
|
|
margin-top: 0;
|
|
}
|
|
|
|
:deep(.chat-markdown > :last-child) {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
/* 链接 / 引用 / 分隔线:颜色走主题令牌,暗色由变量自适应 */
|
|
:deep(.chat-markdown a) {
|
|
color: rgb(29 78 216);
|
|
text-decoration: underline;
|
|
text-underline-offset: 2px;
|
|
}
|
|
|
|
:deep(.dark .chat-markdown a) {
|
|
color: rgb(147 197 253);
|
|
}
|
|
|
|
:deep(.chat-markdown blockquote) {
|
|
margin: 0.5em 0;
|
|
padding: 0.125rem 0.875rem;
|
|
border-left: 3px solid var(--border-default);
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
:deep(.chat-markdown hr) {
|
|
margin: 1em 0;
|
|
border: 0;
|
|
border-top: 1px solid var(--border-default);
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-mermaid-diagram) {
|
|
max-width: 100%;
|
|
overflow: auto;
|
|
margin: 1rem 0;
|
|
padding: 1rem;
|
|
border: 1px solid rgb(219 234 254);
|
|
border-radius: 0.75rem;
|
|
background: linear-gradient(135deg, rgb(248 250 252), rgb(239 246 255));
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-mermaid-diagram svg) {
|
|
display: block;
|
|
min-width: 36rem;
|
|
max-width: none;
|
|
height: auto;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-mermaid-error) {
|
|
white-space: pre;
|
|
overflow: auto;
|
|
color: rgb(127 29 29);
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-mermaid-error-tip) {
|
|
margin: 0.75rem 0 0.25rem;
|
|
color: rgb(185 28 28);
|
|
font-size: 0.8125rem;
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-flow-fallback) {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
max-width: 100%;
|
|
overflow-x: auto;
|
|
margin: 1rem 0;
|
|
padding: 1rem;
|
|
border: 1px solid rgb(191 219 254);
|
|
border-radius: 0.75rem;
|
|
background: linear-gradient(135deg, rgb(248 250 252), rgb(239 246 255));
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-flow-fallback-card) {
|
|
flex: 0 0 auto;
|
|
min-width: 8.5rem;
|
|
max-width: 13rem;
|
|
padding: 0.75rem 1rem;
|
|
border: 1px solid rgb(96 165 250);
|
|
border-radius: 0.625rem;
|
|
background: white;
|
|
color: rgb(30 64 175);
|
|
font-weight: 600;
|
|
line-height: 1.45;
|
|
text-align: center;
|
|
box-shadow: 0 2px 8px rgb(59 130 246 / 0.12);
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-flow-fallback-arrow) {
|
|
flex: 0 0 auto;
|
|
color: rgb(37 99 235);
|
|
font-size: 1.5rem;
|
|
font-weight: 700;
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-table-scroll) {
|
|
max-width: 100%;
|
|
overflow-x: auto;
|
|
overflow-y: hidden;
|
|
margin: 0.75rem 0;
|
|
-webkit-overflow-scrolling: touch;
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-table-inner) {
|
|
width: max-content;
|
|
min-width: 100%;
|
|
}
|
|
|
|
:deep(.chat-markdown table) {
|
|
width: max-content;
|
|
min-width: 100%;
|
|
border-collapse: collapse;
|
|
margin: 0;
|
|
font-size: 0.875rem;
|
|
}
|
|
|
|
:deep(.chat-markdown th),
|
|
:deep(.chat-markdown td) {
|
|
border: 1px solid rgb(226 232 240);
|
|
padding: 0.5rem 0.75rem;
|
|
text-align: left;
|
|
vertical-align: top;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
:deep(.chat-markdown th) {
|
|
background: rgb(248 250 252);
|
|
font-weight: 600;
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-fixed-asset-highlight-header) {
|
|
color: rgb(30 64 175);
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-asset-history-link) {
|
|
color: rgb(29 78 216);
|
|
font-weight: 600;
|
|
text-decoration: none;
|
|
}
|
|
|
|
:deep(.chat-markdown .chat-asset-history-link:hover) {
|
|
color: rgb(30 64 175);
|
|
text-decoration: underline;
|
|
}
|
|
|
|
:deep(.dark .chat-markdown th),
|
|
:deep(.dark .chat-markdown td) {
|
|
border-color: rgb(51 65 85);
|
|
}
|
|
|
|
:deep(.dark .chat-markdown th) {
|
|
background: rgb(30 41 59);
|
|
}
|
|
|
|
:deep(.dark .chat-markdown .chat-fixed-asset-highlight-header),
|
|
:deep(.dark .chat-markdown .chat-asset-history-link) {
|
|
color: rgb(147 197 253);
|
|
}
|
|
|
|
:deep(.dark .chat-markdown .chat-asset-history-link:hover) {
|
|
color: rgb(191 219 254);
|
|
}
|
|
|
|
:deep(.chat-markdown details) {
|
|
margin-top: 1rem;
|
|
border: 1px solid rgb(226 232 240);
|
|
border-radius: 0.75rem;
|
|
background: rgb(248 250 252 / 0.9);
|
|
padding: 0.75rem 1rem;
|
|
}
|
|
|
|
:deep(.dark .chat-markdown details) {
|
|
border-color: rgb(51 65 85);
|
|
background: rgb(30 41 59 / 0.65);
|
|
}
|
|
|
|
:deep(.chat-markdown details summary) {
|
|
cursor: pointer;
|
|
font-size: 0.75rem;
|
|
font-weight: 600;
|
|
letter-spacing: 0.08em;
|
|
color: rgb(71 85 105);
|
|
list-style-position: inside;
|
|
}
|
|
|
|
:deep(.dark .chat-markdown details summary) {
|
|
color: rgb(203 213 225);
|
|
}
|
|
|
|
:deep(.chat-markdown details[open] summary) {
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
|
|
:deep(.chat-markdown details pre) {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
:deep(.chat-markdown .leave-action-trigger) {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin: 0 0.2rem;
|
|
padding: 0.1rem 0.6rem;
|
|
border-radius: 9999px;
|
|
border: 1px solid rgb(59 130 246 / 0.28);
|
|
background: rgb(239 246 255);
|
|
color: rgb(29 78 216);
|
|
font-weight: 600;
|
|
text-decoration: none;
|
|
cursor: pointer;
|
|
transition: all 0.2s ease;
|
|
}
|
|
|
|
:deep(.chat-markdown .leave-action-trigger:hover) {
|
|
background: rgb(219 234 254);
|
|
border-color: rgb(59 130 246 / 0.4);
|
|
}
|
|
|
|
:deep(.chat-markdown .leave-intent-highlight) {
|
|
display: inline-block;
|
|
margin: 0 0.2rem;
|
|
padding: 0.05rem 0.4rem;
|
|
border-radius: 0.5rem;
|
|
background: rgb(254 249 195);
|
|
color: rgb(161 98 7);
|
|
font-weight: 600;
|
|
}
|
|
|
|
:deep(.dark .chat-markdown .leave-action-trigger) {
|
|
border-color: rgb(96 165 250 / 0.35);
|
|
background: rgb(30 41 59);
|
|
color: rgb(147 197 253);
|
|
}
|
|
|
|
:deep(.dark .chat-markdown .leave-action-trigger:hover) {
|
|
background: rgb(30 64 175 / 0.25);
|
|
}
|
|
|
|
:deep(.dark .chat-markdown .leave-intent-highlight) {
|
|
background: rgb(113 63 18 / 0.45);
|
|
color: rgb(253 224 71);
|
|
}
|
|
</style>
|