106 lines
4.0 KiB
JavaScript
106 lines
4.0 KiB
JavaScript
/**
|
|
* 文件预览
|
|
*/
|
|
import { onlyOfficeUrl, kkFileViewUrl } from '@/sysConfig'
|
|
import { getBusStandFileByAttId } from 'api/process'
|
|
const Base64 = require('js-base64').Base64;
|
|
import store from '@/store'
|
|
import { Loading } from 'element-ui';
|
|
import axios from '@/common/axiosV2'
|
|
import isMobile from '@/store/isMobile'
|
|
|
|
// 获取转换为pdf的文件
|
|
function queryConvertAtt (data) {
|
|
return axios({
|
|
url: 'api/lawss/sarBussStandFile/queryConvertAtt',
|
|
method: 'get',
|
|
params: data
|
|
})
|
|
}
|
|
|
|
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 {
|
|
url = 'book://ssreader/e0?url=' + file.downLoadUrl
|
|
}
|
|
} else if (file.fileSuffix.toLowerCase() === 'pdf') {
|
|
let viewer = '/static/pdf/web/viewer.html?file='
|
|
if (isMobile()) {
|
|
viewer = '/static/pdf_old/web/viewer.html?file='
|
|
}
|
|
url = viewer + 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) {
|
|
url = '/static/pdf/web/viewer.html?file=' + encodeURIComponent('/api/att/attFile/getFileInfo?fileId=' + res.data.attId)
|
|
} else {
|
|
this.$message.error('文档未转换成功或本地读取不到该文档')
|
|
return
|
|
}
|
|
} else {
|
|
url = kkFileViewUrl + '/onlinePreview?url=' + encodeURIComponent(Base64.encode(file.downLoadUrl)) + '&watermarkTxt=' + encodeURIComponent(store.getters.userInfo.userName)
|
|
}
|
|
}
|
|
if (type === 'getUrl') {
|
|
return url
|
|
}
|
|
window.open(url)
|
|
}
|
|
loading && 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()
|
|
// })
|
|
// }
|