import b from "axios";
import { ElMessage as f } from "element-plus";
async function x(d, l = "This is a default download file url", e, o, p) {
  try {
    const a = await (p || b).post(l, d, {
      responseType: "blob",
      // 设置响应类型为 'blob'
      timeout: 0,
      // 设置为0表示永不超时(当是网络不确定的情况下,比如下载大文件时,可以设置为0,不然会报错)
      // 添加下载进度回调
      onDownloadProgress: (n) => {
        if (n.total) {
          const u = Math.round(n.loaded / n.total * 100);
          e == null || e(u);
        }
      }
    }), m = a.data, c = a.headers["content-disposition"], r = c ? decodeURIComponent(c.split("fileName=")[1].replace(/"/g, "")) : "没有提供文件名,使用默认的文件名", s = window.URL.createObjectURL(m), t = document.createElement("a");
    t.href = s, t.setAttribute("download", r), document.body.appendChild(t), t.click(), document.body.removeChild(t), window.URL.revokeObjectURL(s);
  } catch (i) {
    console.error("Axios-POST: 下载文件时出错:", i), o == null || o(i), f.error("下载文件失败，请稍后重试");
  }
}
export {
  x as downloadFileWithAxios
};
