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) {
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;