|
@@ -43,13 +43,19 @@ axios.defaults.headers.common['Authorization'] = "";
|
|
|
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
axios.defaults.timeout = 30000;
|
|
|
axios.defaults.withCredentials = true;
|
|
|
+let isInvalid1 = false
|
|
|
+let isInvalid2 = false
|
|
|
|
|
|
|
|
|
axios.interceptors.request.use(function (config) {
|
|
|
|
|
|
|
|
|
config.headers.common['Authorization'] = localStorage.getItem('Authorization');
|
|
|
- showFullScreenLoading();
|
|
|
+ if(config.noLoading===true){
|
|
|
+
|
|
|
+ }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);
|
|
|
+
|
|
|
+ if(error.response.data.error == 'invalid_token'){
|
|
|
+
|
|
|
+ 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'){
|
|
|
+ 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;
|
|
|
+
|
|
|
+
|