diff --git a/src/components/talk/message/FileMessage.vue b/src/components/talk/message/FileMessage.vue index 7677ac8..6735c14 100644 --- a/src/components/talk/message/FileMessage.vue +++ b/src/components/talk/message/FileMessage.vue @@ -25,33 +25,33 @@ const getFileTypeIMG = computed(() => { let objT = { finishedImg: '', blankImg: '', - progressColor: '' - }; + progressColor: '', + } switch (suffix) { case 'pdf': objT.finishedImg = filePaperPDF objT.blankImg = filePaperPDFBlank objT.progressColor = '#DE4E4E' - break; + break case 'doc': case 'docx': objT.finishedImg = filePaperWord objT.blankImg = filePaperWordBlank objT.progressColor = '#2750B2' - break; + break case 'xls': case 'xlsx': objT.finishedImg = filePaperExcel objT.blankImg = filePaperExcelBlank objT.progressColor = '#3C7F4B' - break; + break case 'ppt': case 'pptx': objT.finishedImg = filePaperPPT objT.blankImg = filePaperPPTBlank objT.progressColor = '#B74B2B' - break; + break default: objT.finishedImg = filePaperOther objT.blankImg = filePaperOtherBlank @@ -60,34 +60,92 @@ const getFileTypeIMG = computed(() => { return objT }) +const previewPDF = () => { + if (typeof plus !== 'undefined') { + downloadAndOpenFile() + } else { + document.addEventListener('plusready', () => { + downloadAndOpenFile() + }) + } +} + +const downloadAndOpenFile = () => { + uni.showLoading({ title: '加载中...', mask: true }) + const downloadUrl = props?.extra?.path + if (!downloadUrl) { + uni.hideLoading() + uni.showToast({ title: '文件路径无效', icon: 'none' }) + return + } + const options = { + filename: '_doc/downloads/', // 保存路径 + } + const dtask = plus.downloader.createDownload(downloadUrl, options, function ( + d, + status, + ) { + if (status === 200) { + uni.hideLoading() + const filePath = d.filename + if (filePath) { + plus.runtime.openFile(filePath, {}, function () {}) + } else { + uni.showToast({ title: '文件路径无效', icon: 'none' }) + } + } else { + uni.hideLoading() + } + }) + dtask.start() +}