//通用下载文件方法
const download = (attachLink) => {
let that = this
uni.downloadFile({
url: attachLink , //下载地址,后端接口获取的链接
success: (data) => {
console.log(data.tempFilePath)
console.log(JSON.stringify(data))
if (data.statusCode === 200) {
uni.saveFile({ //文件保存到本地
tempFilePath: data.tempFilePath, //临时路径
success: function(res) {
console.log("下载成功"+res.savedFilePath)
console.log(JSON.stringify(res))
uni.showToast({
icon: 'none',
mask: true,
title: '文件已保存!',
duration: 3000,
});
uni.openDocument({
//fileType: 'docx',
showMenu:true, //关键点,可以转发到微信
filePath: res.savedFilePath,
success: function(res) {
console.log('打开文档成功');
}
});
}
});
}
},
fail: (err) => {
console.log(err);
uni.showToast({
icon: 'none',
mask: true,
title: '失败请重新下载',
});
},
});
}
先使用下载文件api把文件下载下来,再使用wx.openDocument() 打开文件里面加上showMenu字段,然后就可以看到在打开的文件右上角出现了···,就可以转发了
转载 https://blog.csdn.net/qq_37131884/article/details/123360114