燕山石化溯源三维电子沙盘-【前端】-Web
WX
2023-08-15 299011f4f2f151d0550065c1ee89420379a653c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * @Description:
 * @Author: 王旭
 * @Date: 2022-03-03 15:10:54
 * @LastEditTime: 2022-04-13 15:19:08
 * @LastEditors: 王旭
 */
import axios from "axios";
const instance = axios.create({
  baseURL: BASE_URL, // api的base_url
  timeout: 1200000, // 请求超时时间
  // headers: { "content-type": "application/json;charset=UTF-8" },
  // withCredentials: true,
  responseType: "blob",
});
// 拦截请求
// instance.interceptors.request.use(
//   //  可以在此处添加 token
//   (config) => {
//     // var token = window.sessionStorage.getItem("token");
//     // // 临时
//     // var token = sessionStorage.token;
//     // config.headers["X-Access-Token"] = token;
//     return config;
//   },
//   (error) => {
//     return Promise.reject(error);
//   }
// );
// 导出Excel公用方法
export function exportMethod(data) {
  instance
    .get(data.url, { params: data.params })
    .then((res) => {
      const link = document.createElement("a");
      let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
      link.style.display = "none";
      link.href = URL.createObjectURL(blob);
 
      // link.download = res.headers['content-disposition'] //下载后文件名
      link.download = data.fileName; // 下载的文件名
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    })
    .catch((error) => {
      console.log(error);
    });
}