//下载xlsx、pdf.word
async downloadCalc() {
const res = await this.$api.evaluationDownload(this.ruleForm.id) //该方法为请求文件地址的接口,如果过有现成url可以省略这一步
let that = this
if (res.code == 200) {
uni.showLoading({
title: '加载中...'
})
//此处调用微信api下载文件,使用这个必须要到微信开发者后台进行域名配置
wx.downloadFile({
url: res.data.fileUrl, //文件地址地址 例如:http://**.*****.***/ceshi/demo.pdf
filePath: wx.env.USER_DATA_PATH + '/' + res.data.projectNo + '_' + res.data.projectName + '.xlsx',//这一步主要对下载的文件重命名,为后续显示保存都为此名
success(rs) {
if (rs.statusCode === 200) {
let data = rs.filePath;
//此步为打开下载好得到文件
wx.openDocument({
filePath: data,
showMenu: true,
success: function(r) {
uni.hideLoading()
},
fail(e) {
uni.hideLoading()
}
})
} else {
uni.hideLoading()
console.log('报错了', rs);
}
},
fail(rsE) {
uni.hideLoading()
console.log('报错了', rsE);
}
})
} else {
console.log('其他信息');
}
},
关于微信小程序打开/保存excel、pdf、word文档
最新推荐文章于 2025-02-27 16:32:06 发布