feat(chat): 完善固资预览与下载权限
This commit is contained in:
1 parent
6ce0942fef
commit
bf18a7ef1d
19 files changed
+1163
-86
No files matched your search
@@ -5,8 +5,9 @@
|
||||
* 逻辑:由 ChatMessageList 按消息逐条挂载;正文渲染与特殊交互委托 useChatPageMarkdown 等页面编排层提供的 handlers。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
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 MaintenanceDeviceResultCard from './MaintenanceDeviceResultCard.vue';
|
||||
import ShippingInventoryMappingMessage, { type ShippingMappingHandlers } from './ShippingInventoryMappingMessage.vue';
|
||||
@@ -23,6 +24,7 @@ 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;
|
||||
getShippingInventoryMappingPayload: (msg: ChatMessage) => ShippingInventoryMappingFormPayload | null;
|
||||
@@ -76,6 +78,10 @@ const emit = defineEmits<{
|
||||
'open-feedback': [];
|
||||
}>();
|
||||
|
||||
const authStore = useAuthStore();
|
||||
const INLINE_DOWNLOAD_ALLOWED_EMPLOYEE_ID = '17070141';
|
||||
const RESTRICTED_INLINE_DOWNLOAD_FILE_NAME = '资产明细全量导出表.csv';
|
||||
|
||||
const isLeaveMessage = computed(() =>
|
||||
message.type === 'leave-form'
|
||||
|| message.type === 'leave-confirmation'
|
||||
@@ -185,6 +191,8 @@ const FIXED_ASSET_HEADER_LABELS: Record<string, string> = {
|
||||
custodian_name: '保管人',
|
||||
custodian_dept: '保管部门',
|
||||
department_name: '保管部门',
|
||||
image: '图片',
|
||||
picture: '图片',
|
||||
storage_location: '存放位置名称',
|
||||
location_name: '存放位置名称',
|
||||
asset_status: '资产状态',
|
||||
@@ -209,16 +217,17 @@ const FIXED_ASSET_HEADER_LABELS: Record<string, string> = {
|
||||
snapshot_time: '快照时间',
|
||||
};
|
||||
const FIXED_ASSET_CANONICAL_COLUMNS = [
|
||||
{ key: 'id', label: '序号', aliases: ['id'] },
|
||||
{ key: 'asset_id', label: '资产编号', aliases: ['asset_id', 'asset_no'] },
|
||||
{ key: 'asset_name', label: '资产名称', aliases: ['asset_name'] },
|
||||
{ key: 'custodian_person', label: '保管人', aliases: ['custodian_person', 'custodian_name'] },
|
||||
{ key: 'custodian_dept', label: '保管部门', aliases: ['custodian_dept', 'department_name'] },
|
||||
{ key: 'account_period', label: '账套', aliases: ['account_period', 'operating_center_code'] },
|
||||
{ key: 'supplier', label: '供应商', aliases: ['supplier', 'vendor_name'] },
|
||||
{ key: 'asset_status', label: '资产状态', aliases: ['asset_status'] },
|
||||
{ key: 'quantity', label: '数量', aliases: ['quantity'] },
|
||||
{ key: 'acquisition_date', label: '取得时间', aliases: ['acquisition_date', 'acquired_date'] },
|
||||
{ key: 'id', label: '序号', aliases: ['id', '序号'] },
|
||||
{ key: 'asset_id', label: '资产编号', aliases: ['asset_id', 'asset_no', '资产编号'] },
|
||||
{ key: 'asset_name', label: '资产名称', aliases: ['asset_name', '资产名称'] },
|
||||
{ key: 'custodian_person', label: '保管人', aliases: ['custodian_person', 'custodian_name', '保管人', '保管人姓名'] },
|
||||
{ key: 'custodian_dept', label: '保管部门', aliases: ['custodian_dept', 'department_name', '保管部门', '保管部门名称'] },
|
||||
{ key: 'image', label: '图片', aliases: ['image', 'picture', '图片'] },
|
||||
{ key: 'account_period', label: '账套', aliases: ['account_period', 'operating_center_code', '账套'] },
|
||||
{ key: 'supplier', label: '供应商', aliases: ['supplier', 'vendor_name', '供应商', '供应厂商'] },
|
||||
{ key: 'asset_status', label: '资产状态', aliases: ['asset_status', '资产状态'] },
|
||||
{ key: 'quantity', label: '数量', aliases: ['quantity', '数量'] },
|
||||
{ key: 'acquisition_date', label: '取得时间', aliases: ['acquisition_date', 'acquired_date', '取得时间', '取得日期'] },
|
||||
] as const;
|
||||
const INLINE_DIALOG_PAGE_SIZE = 15;
|
||||
|
||||
@@ -362,6 +371,18 @@ function buildFixedAssetInlineTable(rawHeaders: string[], dataRows: string[][]):
|
||||
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 ? '查看' : '无';
|
||||
}
|
||||
const columnIndex = findInlineTableHeaderIndex(rawHeaders, [...column.aliases]);
|
||||
const rawValue = columnIndex >= 0 ? row[columnIndex] ?? '' : '';
|
||||
const normalizedValue = column.key === 'acquisition_date'
|
||||
@@ -488,6 +509,33 @@ const activeInlinePageRows = computed(() => {
|
||||
});
|
||||
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) {
|
||||
@@ -543,14 +591,32 @@ function changeInlineDialogPage(nextPage: number): void {
|
||||
|
||||
function canOpenInlineAssetHistory(cellIndex: number, cellValue: string): boolean {
|
||||
const normalizedValue = String(cellValue || '').trim();
|
||||
return cellIndex === activeInlineFilterIndexes.value.assetId && !!normalizedValue && normalizedValue !== '-';
|
||||
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 openInlineAssetHistory(row: string[]): void {
|
||||
function isInlineHighlightHeader(header: string): boolean {
|
||||
return 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);
|
||||
}
|
||||
|
||||
@@ -560,6 +626,9 @@ function openInlineAssetHistory(row: string[]): void {
|
||||
* @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);
|
||||
@@ -854,6 +923,7 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
</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)"
|
||||
@@ -909,7 +979,10 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
<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"
|
||||
:class="[
|
||||
'border border-slate-200 px-3 py-2 text-left font-semibold',
|
||||
isInlineHighlightHeader(header) ? 'text-blue-800' : 'text-primary',
|
||||
]"
|
||||
>
|
||||
{{ header || '-' }}
|
||||
</th>
|
||||
@@ -929,8 +1002,8 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
<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)"
|
||||
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>
|
||||
@@ -1030,6 +1103,21 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
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);
|
||||
@@ -1039,6 +1127,15 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user