.wxml文件
<view data-url="https://XXX/upload/zang." data-type="excel" catchtap=‘downloadFile‘>888</view>
.js文件
downloadFile: function (e) {
console.log(e);
let type = e.currentTarget.dataset.type;
let url = e.currentTarget.dataset.url;
switch (type) {
case "pdf":
url += ‘pdf‘;
break;
case "word":
url += ‘docx‘;
break;
case "excel":
url += ‘xlsx‘;
break;
default:
url += ‘pptx‘;
break;
}
// console.log(url);
// exit;
wx.downloadFile({
url: url,
header: {},
success: function (res) {
var filePath = res.tempFilePath;
console.log(filePath);
wx.openDocument({
filePath: filePath,
success: function (res) {
console.log(‘打开文档成功‘)
},
fail: function (res) {
console.log(res);
},
complete: function (res) {
console.log(res);
}
})
},
fail: function (res) {
console.log(‘文件下载失败‘);
},
complete: function (res) { },
})
}