fix: 统一预览方式

This commit is contained in:
zyn
2023-12-19 13:35:56 +08:00
parent 51a792c8ae
commit 456875cc34
+79 -28
View File
@@ -1,35 +1,86 @@
/**
* 文件预览
*/
import { onlyOfficeUrl,kkFileViewUrl } from '@/sysConfig'
import { onlyOfficeUrl, kkFileViewUrl } from '@/sysConfig'
import { getBusStandFileByAttId } from 'api/process'
let Base64 = require('js-base64').Base64;
const Base64 = require('js-base64').Base64;
import store from '@/store'
import { Loading } from "element-ui";
import { Loading } from 'element-ui';
import axios from '@/common/axiosV2'
export default attId => {
const loading = Loading.service({
lock: true,
text: '正在加载文件',
spinner: 'el-icon-loading',
})
getBusStandFileByAttId({
attId
}).then(res => {
if(res){
const editFileInfo = res.data
if(editFileInfo.fileSuffix.toLowerCase() === 'pdg'){
window.open('book://ssreader/e0?url='+editFileInfo.downLoadUrl)
}else if(editFileInfo.fileSuffix.toLowerCase() === 'pdf'){
window.open('./static/pdf/web/viewer.html?file=' + encodeURIComponent('/api/att/attFile/getFileInfo?fileId=' + editFileInfo.id))
}else {
const nowTime = new Date().getTime()
// window.open(onlyOfficeUrl+'/onlyOffice?oldFileName=' + editFileInfo.oldFileName + '&fileType=' + editFileInfo.fileSuffix + '&attId=' + editFileInfo.id + '&fileUrl=' + editFileInfo.downLoadUrl + '&key=' + editFileInfo.id + nowTime+'&filePath='+editFileInfo.filePath+'&fileName='+editFileInfo.fileName)
window.open(kkFileViewUrl+'/onlinePreview?url='+encodeURIComponent(Base64.encode(editFileInfo.downLoadUrl)) + '&watermarkTxt=' + encodeURIComponent(store.getters.userInfo.userName));
}
}
}).finally(() => {
loading.close()
})
// 获取转换为pdf的文件
function queryConvertAtt (data) {
return axios({
url: 'api/lawss/sarLawsFile/queryConvertAtt',
method: 'get',
params: data
})
}
async function preview (attId) {
const loading = Loading.service({
lock: true,
text: '正在加载文件',
spinner: 'el-icon-loading',
})
const res = await getBusStandFileByAttId({ attId })
if (res.ok && res.data) {
const file = res.data
if (file.fileSuffix.toLowerCase() === 'pdg') {
window.open('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))
} 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))
} else {
this.$message.error('文档未转换成功或本地读取不到该文档')
}
} else {
window.open(kkFileViewUrl + '/onlinePreview?url=' + encodeURIComponent(Base64.encode(file.downLoadUrl)) + '&watermarkTxt=' + encodeURIComponent(store.getters.userInfo.userName));
}
}
}
loading.close()
}
export default preview;
// export default (attId) => {
// const loading = Loading.service({
// lock: true,
// text: '正在加载文件',
// spinner: 'el-icon-loading',
// })
// getBusStandFileByAttId({
// attId
// }).then(res => {
// if(res) {
// const editFileInfo = res.data
// if(editFileInfo.fileSuffix.toLowerCase() === 'pdg') {
// window.open('book://ssreader/e0?url=' + editFileInfo.downLoadUrl)
// }else if(editFileInfo.fileSuffix.toLowerCase() === 'pdf') {
// window.open('./static/pdf/web/viewer.html?file=' + encodeURIComponent('/api/att/attFile/getFileInfo?fileId=' + editFileInfo.id))
// }else {
// // const nowTime = new Date().getTime()
// // window.open(onlyOfficeUrl+'/onlyOffice?oldFileName=' + editFileInfo.oldFileName + '&fileType=' + editFileInfo.fileSuffix + '&attId=' + editFileInfo.id + '&fileUrl=' + editFileInfo.downLoadUrl + '&key=' + editFileInfo.id + nowTime+'&filePath='+editFileInfo.filePath+'&fileName='+editFileInfo.fileName)
// if (res.data && res.data.onlined === 1) {
// queryConvertAtt({ attId }).then(res => {
// if (res.ok && res.data) {
// window.open('/static/pdf/web/viewer.html?file=' + encodeURIComponent('/api/att/attFile/getFileInfo?fileId=' + res.data.attId))
// } else {
// this.$message.error('文档未转换成功或本地读取不到该文档')
// }
// }).catch(() => {
// this.$message.error('文档未转换成功或本地读取不到该文档')
// })
// }
// window.open(kkFileViewUrl + '/onlinePreview?url=' + encodeURIComponent(Base64.encode(editFileInfo.downLoadUrl)) + '&watermarkTxt=' + encodeURIComponent(store.getters.userInfo.userName));
// }
// }
// }).finally(() => {
// loading.close()
// })
// }