From 55a23e672d37869342ef19b12c25f8e548a42aa6 Mon Sep 17 00:00:00 2001 From: b2894lxlx <517289602@qq.com> Date: Fri, 12 Jun 2026 17:58:54 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=B2=BE=E7=AE=80=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E5=AD=97=E6=AE=B5=202=E3=80=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9pdf=E5=9C=A8=E7=BA=BF=E6=9F=A5=E7=9C=8B=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pwlProject/components/reportContent.vue | 141 +++++++-- src/views/pwl/pwlProject/index.vue | 274 ++---------------- src/views/pwl/pwlProjectLibrary/index.vue | 274 ++---------------- 3 files changed, 151 insertions(+), 538 deletions(-) diff --git a/src/views/pwl/pwlProject/components/reportContent.vue b/src/views/pwl/pwlProject/components/reportContent.vue index c4ce0ac..2aeeb81 100644 --- a/src/views/pwl/pwlProject/components/reportContent.vue +++ b/src/views/pwl/pwlProject/components/reportContent.vue @@ -320,12 +320,11 @@ " >
- {{ fileItem.fileName || '未命名文件' }} + {{ getFileInfo(fileItem).name || '未命名文件' }} - - {{ fileItem.fileName || fileItem || '未命名文件' }} + + {{ getFileInfo(fileItem).name || '未命名文件' }}
@@ -2011,12 +2014,89 @@ }); }; - const openDoc = (fileItem) => { - console.log(fileItem); - // window.open( - // `http://view.officeapps.live.com/op/view.aspx?src=文件地址`, - // '_blank' - // ); + const getFileInfo = (fileItem: any) => { + if (typeof fileItem === 'string') { + const [fileId = '', fileName = '', fileUrl = ''] = fileItem.split('||'); + return { + id: fileId, + name: fileName || fileItem, + url: fileUrl, + ext: getFileExt(fileName || fileUrl || fileItem) + }; + } + + if (fileItem && typeof fileItem === 'object') { + const name = + fileItem.fileName || fileItem.file_name || fileItem.name || ''; + const url = fileItem.fileUrl || fileItem.url || ''; + const ext = + fileItem.fileExt || + fileItem.fileType || + getFileExt(name || url || ''); + + return { + id: fileItem.fileId || fileItem.file_id || '', + name: name || '未命名文件', + url, + ext: String(ext || '').toLowerCase().replace(/^\./, '') + }; + } + + return { + id: '', + name: '未命名文件', + url: '', + ext: '' + }; + }; + + const getFileExt = (value: string) => { + const cleanValue = String(value || '').split('?')[0].trim(); + if (!cleanValue) return ''; + const ext = cleanValue.includes('.') ? cleanValue.split('.').pop() : ''; + return String(ext || '').toLowerCase().replace(/^\./, ''); + }; + + const buildFileIconDataUri = (label: string, color: string) => { + const svg = ` + + + ${label} + + `; + return `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(svg)}`; + }; + + const getFileIcon = (fileItem: any) => { + const ext = getFileInfo(fileItem).ext; + + if (ext === 'pdf') { + return buildFileIconDataUri('PDF', '#e53935'); + } + if (['doc', 'docx'].includes(ext)) { + return buildFileIconDataUri('DOC', '#2f6fed'); + } + if (['xls', 'xlsx', 'csv'].includes(ext)) { + return buildFileIconDataUri('XLS', '#2e7d32'); + } + if (['ppt', 'pptx'].includes(ext)) { + return buildFileIconDataUri('PPT', '#ef6c00'); + } + if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'].includes(ext)) { + return buildFileIconDataUri('IMG', '#8e24aa'); + } + if (['txt', 'md'].includes(ext)) { + return buildFileIconDataUri('TXT', '#546e7a'); + } + return buildFileIconDataUri('FILE', '#607d8b'); + }; + + const openDoc = (fileItem: any) => { + const file = getFileInfo(fileItem); + if (!file.url) { + return; + } + window.open(file.url, '_blank', 'noopener,noreferrer'); }; /* 键盘快捷键处理 */ @@ -2168,18 +2248,31 @@ } ); - const handleFilePreview = (file) => { - console.log( - file.fileUrl, - `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent( - file.fileUrl - )}` - ); - window.open( - `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent( - file.fileUrl - )}` - ); + const handleFilePreview = (fileItem: any) => { + const file = getFileInfo(fileItem); + if (!file.url) { + message.warning('该文件暂无可访问地址'); + return; + } + + if (file.ext === 'pdf') { + window.open(file.url, '_blank', 'noopener,noreferrer'); + return; + } + + const officePreviewExts = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx']; + if (officePreviewExts.includes(file.ext)) { + window.open( + `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent( + file.url + )}`, + '_blank', + 'noopener,noreferrer' + ); + return; + } + + window.open(file.url, '_blank', 'noopener,noreferrer'); }; diff --git a/src/views/pwl/pwlProject/index.vue b/src/views/pwl/pwlProject/index.vue index 1184cda..691973a 100644 --- a/src/views/pwl/pwlProject/index.vue +++ b/src/views/pwl/pwlProject/index.vue @@ -261,19 +261,21 @@ :loading="docLoading" :row-selection="docRowSelection" rowKey="id" - :scroll="{ x: 2600, y: 500 }" + :scroll="{ x: 980, y: 500 }" :pagination="pagination" @change="handleTableChange" size="middle" >