import axios from "axios";
function downloadBlobFile(url, data, name, type) {
  return new Promise((resolve, reject) => {
    axios({
      method: type,
      url,
      responseType: "blob",
      data,
    })
      .then((res) => {
        let blob = new Blob([res.data], {
          type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8",
        });
        let downloadElement = document.createElement("a");
        let href = window.URL.createObjectURL(blob); // 创建下载的链接
        downloadElement.href = href;
        downloadElement.download = name; // 下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); // 点击下载
        document.body.removeChild(downloadElement); // 下载完成移除元素
        window.URL.revokeObjectURL(href); // 释放掉blob对象
        resolve({
          status: 0,
        });
      })
      .catch((e) => {
        reject({
          status: 1,
        });
      });
  });
}
export default downloadBlobFile;
