feat(chat-fixed-assets): 支持资产履历直达预览并优化 Excel 预览体验

This commit is contained in:
runny committed 2026-07-03 18:59:27 +08:00
1 parent 1164ae2e3c
commit 56b6ea06a8
14 files changed
+1051 -48

No files matched your search

@@ -0,0 +1,91 @@
<script setup lang="ts">
/**
* features/chat/components/ChatAssetHistoryDialog.vue
* 用途:展示固定资产履历候选文件列表,并复用既有文件预览弹窗打开具体履历。
* 依赖:聊天页 useChatPage 提供的查询状态与打开预览回调。
* 逻辑:用户点击资产编号后打开;先显示检索状态,再列出共享盘匹配文件,点击单条文件进入预览。
*/
import { computed } from 'vue';
import { ExternalLink, FileText, Loader2, X } from 'lucide-vue-next';
import type { AssetHistoryFileItem } from '../types/chat.types';
const open = defineModel<boolean>('open', { required: true });
const props = defineProps<{
loading: boolean;
error: string;
assetId: string;
assetName: string;
items: AssetHistoryFileItem[];
}>();
const emit = defineEmits<{
close: [];
openPreview: [item: AssetHistoryFileItem];
}>();
const titleText = computed(() => props.assetId || props.assetName || '资产履历');
</script>
<template>
<div
v-if="open"
class="dialog-overlay z-[120] items-center"
@click.self="emit('close')"
>
<div class="dialog-panel flex max-h-[88vh] w-[min(96vw,900px)] max-w-[900px] flex-col">
<div class="dialog-header">
<div>
<h3 class="section-title">资产履历</h3>
<p class="section-desc mt-1">当前资产:{{ titleText }}</p>
</div>
<button type="button" class="btn-icon-ds" aria-label="关闭" @click="emit('close')">
<X class="h-5 w-5" />
</button>
</div>
<div class="dialog-body flex min-h-0 flex-1 flex-col gap-4 border-t-0 pt-4">
<div v-if="loading" class="flex h-56 items-center justify-center text-sm text-muted">
<Loader2 class="mr-2 h-5 w-5 animate-spin text-brand-500" />
正在检索共享盘履历文件...
</div>
<div v-else-if="error" class="rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">
{{ error }}
</div>
<div
v-else-if="items.length === 0"
class="flex h-56 items-center justify-center rounded-2xl border border-dashed border-default bg-surface-soft text-sm text-muted"
>
未找到匹配的履历文件
</div>
<div v-else class="min-h-0 flex-1 overflow-auto rounded-2xl border border-default bg-surface">
<div
v-for="item in items"
:key="item.path"
class="flex items-start justify-between gap-3 border-b border-default px-4 py-4 last:border-b-0"
>
<div class="min-w-0 flex-1">
<div class="flex items-center gap-2 text-sm font-semibold text-primary">
<FileText class="h-4 w-4 shrink-0 text-brand-500" />
<span class="truncate">{{ item.name }}</span>
</div>
<div class="mt-1 break-all text-xs text-secondary">{{ item.relative_path }}</div>
<div class="mt-2 flex flex-wrap gap-3 text-xs text-muted">
<span v-if="item.modified_at">修改时间:{{ item.modified_at }}</span>
<span v-if="item.size_bytes">大小:{{ Math.max(1, Math.round(item.size_bytes / 1024)) }} KB</span>
<span v-if="item.match_reason">匹配方式:{{ item.match_reason }}</span>
</div>
</div>
<button
type="button"
class="inline-flex shrink-0 items-center gap-1 rounded-xl border border-default px-3 py-2 text-sm font-medium text-brand-600 transition hover:bg-brand-50"
@click="emit('openPreview', item)"
>
<ExternalLink class="h-4 w-4" />
查看履历
</button>
</div>
</div>
</div>
</div>
</div>
</template>
@@ -18,11 +18,29 @@ const props = defineProps<{
const emit = defineEmits<{
close: [];
'change-page': [delta: number];
'open-asset-history': [payload: { assetId: string; assetName: string }];
}>();
const totalPages = computed(() =>
Math.max(1, Math.ceil((props.state.total || 0) / (props.state.pageSize || 100))),
);
const assetIdColumnIndex = computed(() => props.state.columns.findIndex((column) => column === '资产编号'));
const assetNameColumnIndex = computed(() => props.state.columns.findIndex((column) => column === '资产名称'));
function normalizeCellText(cell: unknown): string {
return String(cell ?? '').trim();
}
function canOpenAssetHistory(row: unknown[], cellIndex: number): boolean {
return cellIndex === assetIdColumnIndex.value && !!normalizeCellText(row[cellIndex]);
}
function emitAssetHistory(row: unknown[]): void {
const assetId = normalizeCellText(row[assetIdColumnIndex.value]);
const assetName = assetNameColumnIndex.value >= 0 ? normalizeCellText(row[assetNameColumnIndex.value]) : '';
if (!assetId) return;
emit('open-asset-history', { assetId, assetName });
}
</script>
<template>
@@ -96,7 +114,15 @@ const totalPages = computed(() =>
:key="`query-preview-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>
<button
v-if="canOpenAssetHistory(row, cellIndex)"
type="button"
class="whitespace-pre-wrap break-all text-left font-medium text-brand-600 underline-offset-2 transition hover:underline"
@click="emitAssetHistory(row)"
>
{{ cell ?? '-' }}
</button>
<div v-else class="whitespace-pre-wrap break-all">{{ cell ?? '-' }}</div>
</td>
</tr>
</tbody>
@@ -1,6 +1,6 @@
/**
/**
* features/chat/components/ChatViewOverlays.vue
* 对话页全局弹窗:文件预览、反馈、查询预览、请假 OA、删除确认、学习之窗。
* 对话页全局弹窗与浮层:文件预览、反馈、查询预览、履历检索提示、请假 OA、删除确认、学习之窗。
*/
<script setup lang="ts">
import FilePreviewModal from '@/shared/components/FilePreviewModal.vue';
@@ -10,6 +10,7 @@ import ChatQueryPreviewDialog from '@/features/chat/components/ChatQueryPreviewD
import ChatLeaveAgentDialog from '@/features/chat/components/ChatLeaveAgentDialog.vue';
import ChatOALoginDialog from '@/features/chat/components/ChatOALoginDialog.vue';
import ChatGuideModal from '@/features/chat/components/ChatGuideModal.vue';
import { Loader2 } from 'lucide-vue-next';
import { useChatPageContext } from '@/features/chat/composables/chat.context';
import { getAuthHeaders } from '@/shared/utils/auth';
@@ -45,7 +46,17 @@ function onFeedbackSubmitted() {
:state="page.queryPreviewState"
@close="page.queryPreview.close"
@change-page="page.queryPreview.changePage"
@open-asset-history="({ assetId, assetName }) => page.assetHistory.openHistory(assetId, assetName)"
/>
<div
v-if="page.assetHistory.loading"
class="pointer-events-none fixed inset-x-0 top-20 z-[145] flex justify-center px-4"
>
<div class="flex items-center gap-2 rounded-full border border-brand-200 bg-white/95 px-4 py-2 text-sm text-brand-700 shadow-lg backdrop-blur">
<Loader2 class="h-4 w-4 animate-spin text-brand-500" />
<span>正在搜索该资产的履历资料,请耐心等待...</span>
</div>
</div>
<ChatLeaveAgentDialog
v-model:open="page.showLeaveAgentDialog"
v-model:keyword="page.leaveAgentKeyword"
@@ -21,6 +21,7 @@ import type { ShippingInventoryMappingFormPayload, ShippingMatchResultPayload }
export interface ChatMessageBubbleHandlers {
renderMarkdown: (text: string) => string;
onMarkdownClick: (event: MouseEvent) => void;
openAssetHistory: (assetId: string, assetName?: string) => void;
getInlineDownloadFiles: (text: string) => { cleanedText: string; files: InlineDownloadFile[] };
downloadInlineFile: (file: InlineDownloadFile) => void;
getShippingInventoryMappingPayload: (msg: ChatMessage) => ShippingInventoryMappingFormPayload | null;
@@ -431,10 +432,11 @@ const inlineDialogPage = ref(1);
const activeInlineFilterIndexes = computed(() => {
const table = activeInlineDialogEntry.value?.table;
if (!table) {
return { assetId: -1, custodianPerson: -1, custodianDept: -1 };
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']),
};
@@ -521,6 +523,19 @@ 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();
return cellIndex === activeInlineFilterIndexes.value.assetId && !!normalizedValue && normalizedValue !== '-';
}
function openInlineAssetHistory(row: string[]): 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;
handlers.openAssetHistory(assetId, assetName === '-' ? '' : assetName);
}
/**
* 响应聊天消息里的内嵌文件下载按钮点击。
* 核心逻辑:复用页面层 handlers 生成 Blob 下载,组件层只负责把当前文件对象回传出去。
@@ -617,6 +632,7 @@ function handleInlineDownload(file: InlineDownloadFile): void {
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"
/>
@@ -885,7 +901,15 @@ function handleInlineDownload(file: InlineDownloadFile): void {
: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>
<button
v-if="canOpenInlineAssetHistory(cellIndex, cell)"
type="button"
class="whitespace-pre-wrap break-all text-left font-medium text-brand-600 underline-offset-2 transition hover:underline"
@click="openInlineAssetHistory(row)"
>
{{ cell || '-' }}
</button>
<div v-else class="whitespace-pre-wrap break-all">{{ cell || '-' }}</div>
</td>
</tr>
</tbody>