微信小程序下载zip文件

  wx.showLoading({title: '下载中'});
  wx.downloadFile({
    url: zipUrl,
    success: (res) => {
      wx.hideLoading();
      // res.tempFilePath = 沙箱临时zip文件
      const tempPath = res.tempFilePath;
      // 打开预览整包
      wx.openDocument({
        filePath: tempPath,
        fileType: 'zip',
        showMenu: true, // 必须开启右上角菜单,才能保存
        success: () => {
          // 弹窗引导用户手动保存
          wx.showModal({
            title: '保存压缩包',
            content: '点击页面右上角 ... ,即可保存完整ZIP到手机',
            showCancel: false
          })
        }
      })
    },
    fail: () => {
      wx.hideLoading();
      wx.showToast({title: '下载失败',icon:'none'})
    }
})

  

posted @ 2026-07-29 22:19  热心市民~菜先生  阅读(48)  评论(0)    收藏  举报