目前1.4库支持打开'doc','docx','xls','xlsx','ppt','pptx','pdf'等文件
api: openDocument、downloadFile
open(index) {
let attachments = this.attachments[index];
let fileUrl = attachments.fileUrl;
let fileName = attachments.fileName;
let fileType = attachments.fileType.toLowerCase();
let fileTypes = ['doc','docx','xls','xlsx','ppt','pptx','pdf']; //openDocument fileType目前只支持范围
if(!fileTypes.includes(fileType)){
util.showMsg(`目前仅支持打开${fileTypes.join(',')}类型的文件` );
return
}
wx.showLoading({
title: '下载请求中,请耐心等待..'
});
wx.downloadFile({
url: fileUrl,
//filePath: filePath, // 指定文件下载后存储的路径
header: {
'Authorization': "Bearer " + wx.getStorageSync("TOKEN")
},
success: function (res) {
console.log(res)
wx.hideLoading()
wx.openDocument({ //打开文件
filePath: res.tempFilePath,
fileType:fileType,
showMenu: true, // 是否显示右上角菜单按钮 默认为false(看自身需求,可要可不要。后期涉及到右上角分享功能)
success: function () {
console.log(`打开文件成功`)
},
fail: function (err) {
console.log(err)
}
});
},
fail: function (res) {
console.log(res)
},
complete: function (res) {
}
})
}
网友评论