From 3295c155cd4b0df7daa039ca81924ef49eec7907 Mon Sep 17 00:00:00 2001 From: zhaoxiao Date: Tue, 7 Mar 2023 12:01:05 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=20bug=E3=80=9166408=20=E3=80=90?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E3=80=91=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=BB=84=E4=BB=B6JUpload=E9=A2=84=E8=A7=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jero-web/src/components/jero/JUpload.vue | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/jero-web/src/components/jero/JUpload.vue b/jero-web/src/components/jero/JUpload.vue index dd14b9da..3d71f01f 100644 --- a/jero-web/src/components/jero/JUpload.vue +++ b/jero-web/src/components/jero/JUpload.vue @@ -51,8 +51,12 @@ const uidGenerator = () => { return '-' + parseInt(Math.random() * 10000 + 1 + '', 10) } +const Base64 = require('js-base64').Base64 + // 支持预览的文件类型 const CAN_PREVIEW_FILE_TYPE = ['pdf', 'image'] +// 支持预览的文件后缀 +const CAN_PREVIEW_FILE_SUFFIX = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'mp3', 'mp4', 'flv'] export default { name: 'JUpload', @@ -298,7 +302,9 @@ export default { return } const fileType = file.type - const canPreview = CAN_PREVIEW_FILE_TYPE.some(tt => fileType.indexOf(tt) !== -1) + // 截取文件后缀名 + const fileSuffix = file.name ? file.name.split('.')[file.name.split('.').length - 1] : '' + const canPreview = CAN_PREVIEW_FILE_TYPE.some(tt => fileType.indexOf(tt) !== -1) || CAN_PREVIEW_FILE_SUFFIX.some(tt => fileSuffix === tt) // 判断是否为可预览格式的文件 if (!canPreview) { this.$message.loading('该文件类型不支持预览,正在为您准备下载...').then(() => { @@ -313,7 +319,13 @@ export default { return } // pdf预览 - const url = `/pdfjs/web/viewer.html?file=${encodeURIComponent(fileFullUrl)}` + if (fileType.indexOf('pdf') !== -1) { + const url = `/pdfjs/web/viewer.html?file=${encodeURIComponent(fileFullUrl)}` + window.open(url) + return + } + // 其余可预览文件仍使用KKFile进行预览 + const url = `${window._CONFIG.onlinePreviewDomainURL}?url=${encodeURIComponent(Base64.encode(fileFullUrl))}` window.open(url) }, handleDownload (file) {