// 导出报表  接收url 、参数 返回二进制文件流
export function exportExcel(url, data) {
  return new Promise(resolve => {
    request({
      url: url,
      method: 'post',
      responseType: 'blob',
      data
    }).then(res => {
        //str是后台返回的文件名称 放在了response header里
      let str = res.headers['content-disposition'];
      let fileName = decodeURI(str.substr(str.indexOf('%')))
      let blob = new Blob([res.data], {
        type:
          "application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      });
      if (window.navigator.msSaveOrOpenBlob) {
        navigator.msSaveBlob(blob);
      } else {
        let elink = document.createElement("a");
        elink.download = fileName;
        elink.style.display = "none";
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        document.body.removeChild(elink);
      }
      resolve('导出报表成功!')
    })
  })
}

Logo

前往低代码交流专区

更多推荐