/*
|
* @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);
|
});
|
}
|