微信小程序 导出Excel 文件

	<view  bindtap="exportData">导出</view>
// 导出
  exportData() {
    const auth = wx.getStorageSync("auth");
    wx.showLoading({
      title: "加载中",
    });
    wx.downloadFile({
      //下载
      url: configAPI.exportPlanList + '?searchParam=' + this.data.inputVal,
      header: {
        "content-type": "application/vnd.ms-excel",
        auth: auth,
      },
      success(res) {
        console.log(res);
        if (res.statusCode === 200) {
          let savePath =
            wx.env.USER_DATA_PATH + "/TESUN_PLAN_" + Date.now() + '.xls';
          wx.getFileSystemManager().saveFile({
            //下载成功后保存到本地
            tempFilePath: res.tempFilePath,
            filePath: savePath,
            success(res) {
              wx.hideLoading();
              console.log(res);
              let savePath = res.savedFilePath;
              wx.showModal({
                title: "下载成功",
                content: "是否打开?",
                confirmColor: "#0bc183",
                confirmText: "打开",
                success(res) {
                  if (res.confirm) {
                    wx.openDocument({
                      //打开
                      filePath: savePath,
                      showMenu: true,
                      success(res) {
                        console.log(res);
                      },
                    });
                  } else if (res.cancel) {}
                },
              });
            },
            fail(err) {
              wx.hideLoading();
              wx.showModal({
                title: '提示',
                content: "文件下载失败",
                showCancel: false, //是否显示取消按钮
                success: function (result) {}
              })
            },
          });
        } else {
          wx.hideLoading();
          wx.showModal({
            title: '提示',
            content: "文件下载失败",
            showCancel: false, //是否显示取消按钮
            success: function (result) {}
          })
        }
      },
      fail(err) {
        wx.hideLoading();
        wx.showModal({
          title: '提示',
          content: "文件下载失败",
          showCancel: false, //是否显示取消按钮
          success: function (result) {}
        })
      }
    });
  },
上一篇:Python操作ES


下一篇:Kong 基础认证插件 ( Basic auth )