//resume是一个json,suffix是后缀名,src是文件服务器地址
<image v-if="resume.suffix === 'pdf'" mode="aspectFill" class="uni-uploader__img" src="/static/img/approval/pdf.png" :data-src="resume.url" @tap="previewDocument"></image>
<image v-else-if="resume.suffix === 'doc' || resume.suffix === 'docx'" mode="aspectFill" class="uni-uploader__img" src="/static/img/approval/word.png" :data-src="resume.url" @tap="previewDocument"></image>
<image v-else-if="resume.suffix === 'xls' || resume.suffix === 'xlsx'" mode="aspectFill" class="uni-uploader__img" src="/static/img/approval/excel.png" :data-src="resume.url" @tap="previewDocument"></image>
<image v-else-if="resume.suffix === 'ppt' || resume.suffix === 'pptx'" mode="aspectFill" class="uni-uploader__img" src="/static/img/approval/ppt.png" :data-src="resume.url" @tap="previewDocument"></image>
<image v-else mode="aspectFill" class="uni-uploader__img" src="/static/img/work/record.png" :data-src="resume.url" @tap="downloadFile"></image>
js:
previewDocument: function(e) {
var current = e.target.dataset.src
uni.showLoading({
title: '正在加载文件...',
mask: true
})
uni.downloadFile({
url: current,
success: function(res) {
uni.hideLoading()
let filePath = res.tempFilePath
uni.openDocument({
filePath: filePath,
success: function(res) {
console.log('打开文档成功')
},
});
},
fail() {
uni.hideLoading()
}
});
},
downloadFile: function(e) {
uni.showToast({
title: '该类型附件不支持查看',
icon: 'none',
mask: true,
duration: 3000
})
},