|
@@ -43,13 +43,19 @@ axios.defaults.headers.common['Authorization'] = ""; //请求token信息配置
|
|
|
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; //请求type设置
|
|
|
axios.defaults.timeout = 30000; //在超时前,所有请求都会等待30秒
|
|
|
axios.defaults.withCredentials = true;
|
|
|
+let isInvalid1 = false //用于控制登录信息过期后弹窗时间的截流,截流时间为5s
|
|
|
+let isInvalid2 = false
|
|
|
|
|
|
// 添加请求拦截器
|
|
|
axios.interceptors.request.use(function (config) {
|
|
|
// 在发送请求之前处理
|
|
|
// 判断token在前台session中是否存在
|
|
|
config.headers.common['Authorization'] = localStorage.getItem('Authorization');
|
|
|
- showFullScreenLoading();
|
|
|
+ if(config.noLoading===true){ //如果noLoading为true,不加载loading画面
|
|
|
+
|
|
|
+ }else{
|
|
|
+ showFullScreenLoading();
|
|
|
+ }
|
|
|
return config;
|
|
|
}, function (error) {
|
|
|
// 对请求错误做处理
|
|
@@ -72,17 +78,29 @@ axios.interceptors.response.use(function (response) {
|
|
|
return response;
|
|
|
}, function (error) {
|
|
|
tryHideFullScreenLoading();
|
|
|
- console.log('网络异常');
|
|
|
- ElementUI.Message.error("网络异常");
|
|
|
- return Promise.reject(error);
|
|
|
+ //console.log(error)
|
|
|
+ if(error.response.data.error == 'invalid_token'){ //token失效,弹框提示确认返回login
|
|
|
+ //ElementUI.Message.error("用户信息过期,请重新登录");
|
|
|
+ if(isInvalid1 == false){
|
|
|
+ isInvalid1 = true
|
|
|
+ ElementUI.MessageBox.alert('用户信息过期,请重新登陆','提示',{
|
|
|
+ confirmButtonText:'确定',
|
|
|
+ callback: action => {
|
|
|
+ let loginUrl = window.location.origin + '/login'
|
|
|
+ window.location.href = loginUrl
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setTimeout(()=>{isInvalid1 = false}, 5000)
|
|
|
+ }
|
|
|
+ return Promise.reject(error);
|
|
|
+ }else{
|
|
|
+ ElementUI.Message.error("网络异常");
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
Vue.prototype.$axios = axios; //定义调用方式
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// 针对上传大文件
|
|
|
const instance = axios.create({
|
|
|
baseURL: '',
|
|
@@ -121,9 +139,26 @@ instance.interceptors.response.use(function (response) {
|
|
|
}, function (error) {
|
|
|
tryHideFullScreenLoading();
|
|
|
console.log('网络异常');
|
|
|
- ElementUI.Message.error("网络异常");
|
|
|
- return Promise.reject(error);
|
|
|
+ if(error.response.data.error == 'invalid_token'){ //token失效,弹框提示确认返回login
|
|
|
+ if(isInvalid2 == false){
|
|
|
+ isInvalid2 = true
|
|
|
+ ElementUI.MessageBox.alert('用户信息过期,请重新登陆','提示',{
|
|
|
+ confirmButtonText:'确定',
|
|
|
+ callback: action => {
|
|
|
+ let loginUrl = window.location.origin + '/login'
|
|
|
+ window.location.href = loginUrl
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setTimeout(()=>{isInvalid2 = false}, 5000)
|
|
|
+ }
|
|
|
+ return Promise.reject(error);
|
|
|
+ }else{
|
|
|
+ ElementUI.Message.error("网络异常");
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
Vue.use(VueAxios, instance);
|
|
|
-Vue.prototype.$instance = instance; //定义调用方式
|
|
|
+Vue.prototype.$instance = instance; //定义调用方式
|
|
|
+
|
|
|
+//针对不需要loading画面的实例
|