From f033eda45b91f1b525a25ab4e5b46c8694da6fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=9C=84?= Date: Thu, 11 Jan 2024 09:39:46 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=96=87=E4=BB=B6=E9=A2=84=E8=A7=88token?= =?UTF-8?q?=E6=94=B9=E4=B8=BAat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/FileEcho.vue | 2 +- src/components/UploadFile.vue | 2 +- src/components/jero/JUpload.vue | 2 +- src/utils/previewPdf.js | 2 +- src/utils/util.js | 37 +++++++++++++++++++ .../modules/BasisDescriptionModal.vue | 4 +- .../commonPage/StandardDetailPage.vue | 2 +- .../modules/ConsultationModal.vue | 4 +- 8 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/components/FileEcho.vue b/src/components/FileEcho.vue index f070926e..7f52e248 100644 --- a/src/components/FileEcho.vue +++ b/src/components/FileEcho.vue @@ -103,7 +103,7 @@ export default { }) return } - const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.fileName}` + const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.id}?at=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.fileName}` // 图片预览,使用自己添加的组件 if (canPreview && FILE_TYPE_IMGS.includes(fileSuffix.toLowerCase())) { this.imageUrl = getFileAccessHttpUrl(file.id) diff --git a/src/components/UploadFile.vue b/src/components/UploadFile.vue index 3033f413..8abfbbf7 100644 --- a/src/components/UploadFile.vue +++ b/src/components/UploadFile.vue @@ -309,7 +309,7 @@ export default { }) return } - const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.response.result.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.name}` + const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.response.result.id}?at=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.name}` console.log(fileSuffix) // 图片预览,使用自己添加的组件 if (FILE_TYPE_IMGS.includes(fileSuffix)) { diff --git a/src/components/jero/JUpload.vue b/src/components/jero/JUpload.vue index 8b0346de..71e60633 100644 --- a/src/components/jero/JUpload.vue +++ b/src/components/jero/JUpload.vue @@ -441,7 +441,7 @@ export default { }) return } - const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.response.result.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.name}` + const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.response.result.id}?at=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.name}` console.log(fileSuffix) // 图片预览,使用自己添加的组件 if (FILE_TYPE_IMGS.includes(fileSuffix)) { diff --git a/src/utils/previewPdf.js b/src/utils/previewPdf.js index 63088d98..8a923440 100644 --- a/src/utils/previewPdf.js +++ b/src/utils/previewPdf.js @@ -5,7 +5,7 @@ const getToken = () => Vue.ls.get(ACCESS_TOKEN) // 预览pdf const previewPdf = (id) => { - const url = `${window._CONFIG.domianURL}/sys/common/view/${id}?type=view&token=${getToken()}` + const url = `${window._CONFIG.domianURL}/sys/common/view/${id}?type=view&at=${getToken()}` return `${process.env.BASE_URL}pdfjs/web/viewer.html?file=` + encodeURIComponent(url) + '&.pdf' } diff --git a/src/utils/util.js b/src/utils/util.js index 7061ef4e..107cbda6 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -2,6 +2,9 @@ import Vue from 'vue' import * as api from '@/api/api' import { isURL } from '@/utils/validate' import { ACCESS_TOKEN } from '@/store/mutation-types' +import { getFileInfo } from '@/api/api' +import { dealUrl, kkFilePreview } from './kkFilePreview' +import { previewPdf } from './previewPdf' // import onlineCommons from '@/components/onlineForm/onlineForm' // @@ -678,3 +681,37 @@ export function getConfusionCode (tableName, fieldName) { } return '' } + +/** + * 通过文件id在当前窗口预览文件 + * @param fileId + */ +export function previewFileCurrentWindowByFileId (fileId) { + return new Promise((resolve, reject) => { + getFileInfo({ id: fileId }).then(res => { + if (res.success) { + const file = res.result || {} + // 支持预览的文件后缀 + const CAN_PREVIEW_FILE_SUFFIX = ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'] + const fileSuffix = file.fileName ? file.fileName.split('.')[file.fileName.split('.').length - 1] : '' + const canPreview = CAN_PREVIEW_FILE_SUFFIX.some(tt => fileSuffix.toLowerCase() === tt) + // 判断是否为可预览格式的文件 + if (!canPreview) { + reject('该文件类型不支持预览') + } + const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.id}?at=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.fileName}` + const FILE_TYPE_IMGS = ['jpg', 'jpeg', 'png', 'raw'] + const FILE_TYPE_PDF = 'pdf' + // pdf预览 + if (canPreview && FILE_TYPE_PDF.includes(fileSuffix)) { + const url = previewPdf(file.id) + window.open(url, '_self') + return + } + // 其余可预览文件仍使用KKFile进行预览 + const kkFileUrl = dealUrl(fileFullUrl) + window.open(kkFileUrl, '_self') + } + }) + }) +} diff --git a/src/views/projectLibrary/specialProjectLibrary/modules/BasisDescriptionModal.vue b/src/views/projectLibrary/specialProjectLibrary/modules/BasisDescriptionModal.vue index 6c8c6480..884d8034 100644 --- a/src/views/projectLibrary/specialProjectLibrary/modules/BasisDescriptionModal.vue +++ b/src/views/projectLibrary/specialProjectLibrary/modules/BasisDescriptionModal.vue @@ -199,7 +199,7 @@ export default { }) return } - const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.fileName}` + const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.id}?at=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.fileName}` // 图片预览,使用自己添加的组件 if (canPreview && FILE_TYPE_IMGS.includes(fileSuffix.toLowerCase())) { this.imageUrl = getFileAccessHttpUrl(file.id) @@ -236,4 +236,4 @@ export default { .basis-description { } - \ No newline at end of file + diff --git a/src/views/standardRegulationLibrary/commonPage/StandardDetailPage.vue b/src/views/standardRegulationLibrary/commonPage/StandardDetailPage.vue index 774ce289..15b49dfd 100644 --- a/src/views/standardRegulationLibrary/commonPage/StandardDetailPage.vue +++ b/src/views/standardRegulationLibrary/commonPage/StandardDetailPage.vue @@ -378,7 +378,7 @@ export default { }) return } - const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.fileName}` + const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.id}?at=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.fileName}` console.log(fileFullUrl) // 图片预览,使用自己添加的组件 if (canPreview && FILE_TYPE_IMGS.includes(fileSuffix.toLowerCase())) { diff --git a/src/views/workCenter/standardConsultationProcess/modules/ConsultationModal.vue b/src/views/workCenter/standardConsultationProcess/modules/ConsultationModal.vue index 5a9476d1..cad26c21 100644 --- a/src/views/workCenter/standardConsultationProcess/modules/ConsultationModal.vue +++ b/src/views/workCenter/standardConsultationProcess/modules/ConsultationModal.vue @@ -158,7 +158,7 @@ export default { getFileInfo({ id: fileId }).then(res => { if (res.success) { const fileInfo = res.result || {} - const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${fileInfo.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${fileInfo.fileName}` + const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${fileInfo.id}?at=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${fileInfo.fileName}` // 截取文件后缀名 const fileSuffix = (fileInfo.fileName ? fileInfo.fileName.split('.')[fileInfo.fileName.split('.').length - 1] : '').toLowerCase() switch (fileSuffix) { @@ -261,4 +261,4 @@ export default { justify-content: center; height: 100%; } - \ No newline at end of file +