gopdf(e){
let that=this;
let pdfurl=e.currentTarget.dataset.pdfurl;
let file;
let tokenresult = wx.getStorageSync("tokenresult");
console.log(pdfurl);
wx.request({
url:app.globalData.api.fileurl + `api/file/pdf/httppreview?httpfile=${pdfurl}`,
method: "GET",
header: {
"Authorization": tokenresult.token_type + " " + tokenresult.access_token
},
responseType: 'arraybuffer', //此处是请求文件流,必须带入的属性
success: res => {
if (res.statusCode === 200) {
const fs = wx.getFileSystemManager(); //获取全局唯一的文件管理器
fs.writeFile({
filePath: wx.env.USER_DATA_PATH + "/在线文档.pdf", // wx.env.USER_DATA_PATH 指定临时文件存入的路径,后面字符串自定义
data: res.data,
encoding: "binary", //二进制流文件必须是 binary
success (res){
wx.openDocument({ // 打开文档
filePath: wx.env.USER_DATA_PATH + "/在线文档.pdf", //拿上面存入的文件路径
showMenu: true, // 显示右上角菜单
success: function (res) {
setTimeout(()=>{wx.hideLoading()},500)
}
})
}
})
}
}
});
},