/*
|
* @Author: shuishen 1109946754@qq.com
|
* @Date: 2022-07-29 15:19:13
|
* @LastEditors: shuishen 1109946754@qq.com
|
* @LastEditTime: 2023-04-21 10:16:58
|
* @FilePath: \web\bigScreen\src\router\axios.js
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
*/
|
/**
|
* 全站http配置
|
*
|
* axios参数说明
|
* isSerialize是否开启form表单提交
|
* isToken是否需要token
|
*/
|
import axios from "axios";
|
import { getToken } from "@/utils/auth.js";
|
import Vue from "vue";
|
import Vant from "vant";
|
import router from "../router/page";
|
import "vant/lib/index.css";
|
import store from "../store/index";
|
import { Loginto } from "@/api/hfiveget/index.js";
|
Vue.use(Vant);
|
|
// 调用后台管理的
|
const service = axios.create({
|
timeout: 600000, // request timeout
|
});
|
|
// 返回其他状态码
|
service.defaults.validateStatus = function (status) {
|
return status >= 200 && status <= 500;
|
};
|
// 跨域请求,允许保存cookie
|
// service.defaults.withCredentials = true
|
|
// http request拦截
|
service.interceptors.request.use(
|
(config) => {
|
if (!config.data) {
|
config.data = true // 解决请求没有参数时添加不上Content-Type问题
|
}
|
store.commit('updateoverlayshow');
|
if (config.apiKey) {
|
config.headers["Authorization"] = "Basic c2FiZXI6c2FiZXJfc2VjcmV0";
|
if (getToken() != undefined) {
|
config.headers["Blade-Auth"] = "bearer " + getToken();
|
}
|
}
|
config.cancelToken = new axios.CancelToken((cancel) => {
|
window._axiosPromiseArr.push({ cancel });
|
});
|
return config;
|
},
|
(error) => {
|
return Promise.reject(error);
|
}
|
);
|
|
// http response 拦截
|
service.interceptors.response.use(
|
(res) => {
|
store.commit('reoverlayshow');
|
if (res.data.code == 401) {
|
Vue.prototype.$toast.fail(res.data.msg)
|
localStorage.clear()
|
setTimeout(() => {
|
router.push("/discrimination");
|
}, 1000);
|
}
|
return res;
|
},
|
(error) => {
|
return Promise.reject(new Error(error));
|
}
|
);
|
|
export default service;
|