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;