【fix bug】66408 【前端】文件上传组件JUpload预览问题
This commit is contained in:
@@ -51,8 +51,12 @@ const uidGenerator = () => {
|
||||
return '-' + parseInt(Math.random() * 10000 + 1 + '', 10)
|
||||
}
|
||||
|
||||
const Base64 = require('js-base64').Base64
|
||||
|
||||
// 支持预览的文件类型
|
||||
const CAN_PREVIEW_FILE_TYPE = ['pdf', 'image']
|
||||
// 支持预览的文件后缀
|
||||
const CAN_PREVIEW_FILE_SUFFIX = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'mp3', 'mp4', 'flv']
|
||||
|
||||
export default {
|
||||
name: 'JUpload',
|
||||
@@ -298,7 +302,9 @@ export default {
|
||||
return
|
||||
}
|
||||
const fileType = file.type
|
||||
const canPreview = CAN_PREVIEW_FILE_TYPE.some(tt => fileType.indexOf(tt) !== -1)
|
||||
// 截取文件后缀名
|
||||
const fileSuffix = file.name ? file.name.split('.')[file.name.split('.').length - 1] : ''
|
||||
const canPreview = CAN_PREVIEW_FILE_TYPE.some(tt => fileType.indexOf(tt) !== -1) || CAN_PREVIEW_FILE_SUFFIX.some(tt => fileSuffix === tt)
|
||||
// 判断是否为可预览格式的文件
|
||||
if (!canPreview) {
|
||||
this.$message.loading('该文件类型不支持预览,正在为您准备下载...').then(() => {
|
||||
@@ -313,7 +319,13 @@ export default {
|
||||
return
|
||||
}
|
||||
// pdf预览
|
||||
const url = `/pdfjs/web/viewer.html?file=${encodeURIComponent(fileFullUrl)}`
|
||||
if (fileType.indexOf('pdf') !== -1) {
|
||||
const url = `/pdfjs/web/viewer.html?file=${encodeURIComponent(fileFullUrl)}`
|
||||
window.open(url)
|
||||
return
|
||||
}
|
||||
// 其余可预览文件仍使用KKFile进行预览
|
||||
const url = `${window._CONFIG.onlinePreviewDomainURL}?url=${encodeURIComponent(Base64.encode(fileFullUrl))}`
|
||||
window.open(url)
|
||||
},
|
||||
handleDownload (file) {
|
||||
|
||||
Reference in New Issue
Block a user