1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//下载PDF文件 
function downLoadFile(){
wx.showModal({
title: '温馨提示',
content: '确认要打开此PDF文件吗?',
showCancel: true,
cancelText: '取消',
confirmText: '确定',
success: (result) => {
if (result.confirm) {
wx.downloadFile({
url: 'https://XXXX.com/pdf', //实际获取文件的url地址
success: function (resinfo) {
console.log("pdf文件下载成功啦")
let path = resinfo.tempFilePath;
console.log(path, resinfo)
wx.openDocument({
filePath: path, // 文件的网络路径
fileType: 'pdf',
success: function (rest) {
console.log('打开文件成功')
console.log(rest);
},
fail: function (error) {
wx.showToast({
icon: 'none',
title: '打开文件失败'
});
},
})
},
fail: function (err) {
wx.showToast({
icon: 'none',
title: '下载文件失败'
});
}
})
}
},
fail: () => {},
complete: () => {}
})
}