H5
引入weixin-js-sdk
npm i weixin-js-sdk
页面引入
// 引入wxjs
import wx from "weixin-js-sdk";
点击按钮触发方法
goweap(id) {
console.log("tiao");
wx.miniProgram.navigateTo({
url: "/packageB/pages/kong/index?fileUrl=" + encodeURIComponent('https://dms-test.futongsmart.cn/File/ExpensesManagement/UploadFile//公告图片//20231226/人员与店铺关系明细数据 (5)(41933).xlsx')
})
},
微信小程序packageB/pages/kong/index
<view class="main">小程序空</view>
onLoad(e:any) {
console.log('kong',e);
this.handleGetMessage(e.fileUrl)
},
// 下载
handleGetMessage(e:any){
console.log('接收到消息',decodeURIComponent(e))
let loadUrl=decodeURIComponent(e)
wx.downloadFile({
url: loadUrl, // 替换为你要下载的文件的 URL
success(res) {
if (res.statusCode === 200) {
wx.showModal({
title: '下载成功',
content: res.tempFilePath,
success (res) {
if (res.confirm) {
console.log('用户点击确定')
wx.navigateBack({delta: 1})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
} else {
console.log('下载失败', res.errMsg);
}
},
fail(err) {
console.log('下载失败', err);
}
});
},