perf: 优化上传方法

This commit is contained in:
zyn
2024-01-04 10:56:46 +08:00
parent 01700b8030
commit e802371acf
+21 -11
View File
@@ -18,38 +18,48 @@ function queryConvertAtt (data) {
}) })
} }
async function preview (attId) { async function preview (attId, type) {
const loading = Loading.service({ let loading;
lock: true, if (type !== 'getUrl') {
text: '正在加载文件', loading = Loading.service({
spinner: 'el-icon-loading', lock: true,
}) text: '正在加载文件',
spinner: 'el-icon-loading',
})
}
const res = await getBusStandFileByAttId({ attId }) const res = await getBusStandFileByAttId({ attId })
if (res.ok && res.data) { if (res.ok && res.data) {
const file = res.data const file = res.data
let url = ''
if (file.fileSuffix.toLowerCase() === 'pdg') { if (file.fileSuffix.toLowerCase() === 'pdg') {
if (isMobile()) { if (isMobile()) {
this.$message.warning('pdg文件,不支持手机端预览') this.$message.warning('pdg文件,不支持手机端预览')
return
} else { } else {
window.open('book://ssreader/e0?url=' + file.downLoadUrl) url = 'book://ssreader/e0?url=' + file.downLoadUrl
} }
} else if (file.fileSuffix.toLowerCase() === 'pdf') { } 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 { } else {
// onlyoffice在线编辑文件转换为pdf预览 -> kkfileview预览乱码 // onlyoffice在线编辑文件转换为pdf预览 -> kkfileview预览乱码
if (file.onlined && file.onlined === 1) { if (file.onlined && file.onlined === 1) {
const res = await queryConvertAtt({ attId }) const res = await queryConvertAtt({ attId })
if (res.ok && res.data) { 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 { } else {
this.$message.error('文档未转换成功或本地读取不到该文档') this.$message.error('文档未转换成功或本地读取不到该文档')
return
} }
} else { } 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; export default preview;