From e802371acf9bf5fcb1e623cd88c5c3b9f68bd2d4 Mon Sep 17 00:00:00 2001 From: zyn Date: Thu, 4 Jan 2024 10:56:46 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/preview/index.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/common/preview/index.js b/src/common/preview/index.js index c0e055d41..0fba21c5f 100644 --- a/src/common/preview/index.js +++ b/src/common/preview/index.js @@ -18,38 +18,48 @@ function queryConvertAtt (data) { }) } -async function preview (attId) { - const loading = Loading.service({ - lock: true, - text: '正在加载文件', - spinner: 'el-icon-loading', - }) +async function preview (attId, type) { + let loading; + if (type !== 'getUrl') { + loading = Loading.service({ + lock: true, + text: '正在加载文件', + spinner: 'el-icon-loading', + }) + } const res = await getBusStandFileByAttId({ attId }) if (res.ok && res.data) { const file = res.data + let url = '' if (file.fileSuffix.toLowerCase() === 'pdg') { if (isMobile()) { this.$message.warning('pdg文件,不支持手机端预览') + return } else { - window.open('book://ssreader/e0?url=' + file.downLoadUrl) + url = 'book://ssreader/e0?url=' + file.downLoadUrl } } else if (file.fileSuffix.toLowerCase() === 'pdf') { - window.open('./static/pdf/web/viewer.html?file=' + encodeURIComponent('/api/att/attFile/getFileInfo?fileId=' + file.id)) + url = './static/pdf/web/viewer.html?file=' + encodeURIComponent('/api/att/attFile/getFileInfo?fileId=' + file.id) } else { // onlyoffice在线编辑文件转换为pdf预览 -> kkfileview预览乱码 if (file.onlined && file.onlined === 1) { const res = await queryConvertAtt({ attId }) if (res.ok && res.data) { - window.open('/static/pdf/web/viewer.html?file=' + encodeURIComponent('/api/att/attFile/getFileInfo?fileId=' + res.data.attId)) + url = '/static/pdf/web/viewer.html?file=' + encodeURIComponent('/api/att/attFile/getFileInfo?fileId=' + res.data.attId) } else { this.$message.error('文档未转换成功或本地读取不到该文档') + return } } else { - window.open(kkFileViewUrl + '/onlinePreview?url=' + encodeURIComponent(Base64.encode(file.downLoadUrl)) + '&watermarkTxt=' + encodeURIComponent(store.getters.userInfo.userName)); + url = kkFileViewUrl + '/onlinePreview?url=' + encodeURIComponent(Base64.encode(file.downLoadUrl)) + '&watermarkTxt=' + encodeURIComponent(store.getters.userInfo.userName) } } + if (type === 'getUrl') { + return url + } + window.open(url) } - loading.close() + loading && loading.close() } export default preview;