[update] 修改预览调公用方法不止word文件,其他能预览的都调

This commit is contained in:
lideqin
2024-01-04 15:58:22 +08:00
parent 2a2af242d4
commit 881bad1d51
7 changed files with 42 additions and 52 deletions
@@ -128,6 +128,8 @@ import { kkFilePreview } from '@/utils/kkFilePreview'
const FILE_TYPE_IMGS = ['jpg', 'jpeg', 'png', 'raw']
const FILE_TYPE_PDF = 'pdf'
// 支持预览的文件后缀
const CAN_PREVIEW_FILE_SUFFIX = ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx']
export default {
name: 'QuestionAnswerList',
@@ -224,6 +226,14 @@ export default {
// 截取文件后缀名
const fileSuffix = record.declareFileName ? record.declareFileName.split('.')[record.declareFileName.split('.').length - 1] : ''
const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${record.declareFile}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${record.declareFileName}`
const canPreview = CAN_PREVIEW_FILE_SUFFIX.some(tt => fileSuffix === tt)
// 判断是否为可预览格式的文件
if (!canPreview) {
this.$message.loading(this.$t('uploadFile.cannotPreview')).then(() => {
this.handleDownload(record.declareFile, record.declareFileName)
})
return
}
// 图片预览,使用自己添加的组件
if (FILE_TYPE_IMGS.includes(fileSuffix)) {
this.imageUrl = getFileAccessHttpUrl(record.declareFile)
@@ -240,13 +250,12 @@ export default {
window.open(url)
return
}
// word用KKfile预览
if (fileSuffix === 'doc' || fileSuffix === 'docx') {
kkFilePreview(fileFullUrl)
return
}
// 如果都不能预览就下载
downloadFile(`/sys/common/download/${record.declareFile}`, record.declareFileName)
// 其余可预览文件仍使用KKFile进行预览
kkFilePreview(fileFullUrl)
},
handleDownload (id, name) {
// 下载文件
downloadFile(`/sys/common/download/${id}`, name)
},
// 查看
handleDetail (record) {