收藏
回答

在微信调试中,wx.downloadFile有一定几率预览不了,为啥?

如下我下载预览附件的代码,为什么在微信中调试,点击10次,有1-2次会预览不了,控制台每次点击都是success的,为啥呢?

(使用PDF、XLS、DOC文件测试)

openDoc: function (e) {
    console.log(e)
    let filename = e.currentTarget.dataset.filename;
    let index = filename.lastIndexOf(".");
    let suffix = filename.substr(index + 1);
    console.log(suffix);
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    console.log(e)
    wx.downloadFile({
      url: app.globalData.rooturl +'accessory/download?id='+e.currentTarget.dataset.id,
      success: function (res) {
        var filePath = res.tempFilePath
        wx.openDocument({
          filePath: filePath,
          fileType: suffix,
          success: function (res) {
            console.log(filePath)
            console.log(res)
            console.log('打开文档成功')
            wx.hideLoading();
          },
          fail: function (res) {
            console.log(res);
            wx.hideLoading();
            wx.showModal({
              title: '信息',
              content: res.errMsg,
              showCancel: false,
              success(res) {
                if (res.confirm) {
                  console.log('F')
                }
              }
            })
          },
          complete: function (res) {
            console.log('完成操作')
          }
        })
      }
    })
  },


最后一次编辑于  09-06
回答关注问题邀请回答
收藏

1 个回答

问题标签