|
@@ -2,6 +2,23 @@ import axios, { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
|
import utils from '@/utils/index';
|
|
|
import router from '@/router';
|
|
|
|
|
|
+function jumpTo(){
|
|
|
+ //清空缓存
|
|
|
+ // localStorage.clear();
|
|
|
+ localStorage.removeItem('token');
|
|
|
+ localStorage.removeItem('userInfo');
|
|
|
+ let loginType = localStorage.getItem('loginType');
|
|
|
+ if(!['/login','/login/qrcode','/login/sunshineRun'].includes(router.currentRoute.value.path)){
|
|
|
+ if (loginType == "3") {
|
|
|
+ router.push('/login/sunshineRun?auto=1');
|
|
|
+ } else if (loginType == "2") {
|
|
|
+ router.push('/login/qrcode?auto=1');
|
|
|
+ } else {
|
|
|
+ router.push('/login?auto=1');
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
|
|
|
axios.defaults.headers['auth'] = true;
|
|
|
// 创建 axios 实例
|
|
@@ -21,18 +38,7 @@ service.interceptors.request.use(
|
|
|
if (!token && Boolean(config.headers['auth']) == true) {
|
|
|
delete config.headers['auth'];
|
|
|
const message = '缺少凭证,请重新登录!';
|
|
|
- let deviceid = localStorage.getItem('deviceid');
|
|
|
- if (router.currentRoute.value.path == '/gesture' || (deviceid && router.currentRoute.value.path != '/login/qrcode')) {
|
|
|
- router.push('/login/qrcode');
|
|
|
- } else if (router.currentRoute.value.path == '/sunshineRun') {
|
|
|
- router.push('/login/sunshineRun');
|
|
|
- } else {
|
|
|
- router.push('/login');
|
|
|
- }
|
|
|
- //清空缓存
|
|
|
- // localStorage.clear();
|
|
|
- localStorage.removeItem('token');
|
|
|
- localStorage.removeItem('userInfo');
|
|
|
+ jumpTo();
|
|
|
ElMessage({ message: message, type: 'error', duration: 5 * 1000 });
|
|
|
return Promise.reject(message);
|
|
|
}
|
|
@@ -67,21 +73,11 @@ service.interceptors.response.use(
|
|
|
const status = res.data.status;
|
|
|
const message = res.data.message;
|
|
|
if (code === 401) {
|
|
|
- let deviceid = localStorage.getItem('deviceid');
|
|
|
- if (router.currentRoute.value.path == '/gesture' || (deviceid && router.currentRoute.value.path != '/login/qrcode')) {
|
|
|
- router.push('/login/qrcode');
|
|
|
- } else if (router.currentRoute.value.path == '/sunshineRun') {
|
|
|
- router.push('/login/sunshineRun');
|
|
|
- } else {
|
|
|
- router.push('/login');
|
|
|
- }
|
|
|
- //清空缓存
|
|
|
- // localStorage.clear();
|
|
|
- localStorage.removeItem('token');
|
|
|
- localStorage.removeItem('userInfo');
|
|
|
+ jumpTo();
|
|
|
ElMessage({ message: message, type: 'error', duration: 5 * 1000 });
|
|
|
return Promise.reject('凭证已过期,请重新登录!');
|
|
|
} else if (status == 500) {
|
|
|
+ ElMessage({ message: message, type: 'error', duration: 5 * 1000 });
|
|
|
return Promise.reject(message);
|
|
|
} else {
|
|
|
return Promise.resolve(res.data);
|
|
@@ -94,23 +90,7 @@ service.interceptors.response.use(
|
|
|
} else if (message.includes('timeout')) {
|
|
|
message = '请求超时';
|
|
|
} else if (response.status == 401) {
|
|
|
- //清空缓存
|
|
|
- // localStorage.clear();
|
|
|
- localStorage.removeItem('token');
|
|
|
- localStorage.removeItem('userInfo');
|
|
|
- let deviceid = localStorage.getItem('deviceid');
|
|
|
- if (deviceid && router.currentRoute.value.path != '/login/qrcode') {
|
|
|
- router.push('/login/qrcode');
|
|
|
- }
|
|
|
- if (deviceid == undefined && router.currentRoute.value.path != '/login' && router.currentRoute.value.path != '/sunshineRun') {
|
|
|
- router.push('/login');
|
|
|
- }
|
|
|
- if (deviceid == undefined && router.currentRoute.value.path == '/gesture') {
|
|
|
- router.push('/login/qrcode');
|
|
|
- }
|
|
|
- if (deviceid == undefined && router.currentRoute.value.path == '/sunshineRun') {
|
|
|
- router.push('/login/sunshineRun');
|
|
|
- }
|
|
|
+ jumpTo();
|
|
|
ElMessage({ message: '请重新登录', type: 'error', duration: 5 * 1000 });
|
|
|
return Promise.reject('凭证已过期,请重新登录!');
|
|
|
} else if (message.includes('Request failed with status code')) {
|