|
@@ -2,11 +2,13 @@ import axios, { AxiosRequestConfig } from 'axios';
|
|
import qs from 'querystring';
|
|
import qs from 'querystring';
|
|
import { ElMessage } from 'element-plus';
|
|
import { ElMessage } from 'element-plus';
|
|
import useMainStore from '@/store/useMainStore';
|
|
import useMainStore from '@/store/useMainStore';
|
|
|
|
+import { LOGIN_URL,BASE_URL} from "@/utils/constant"
|
|
|
|
+import { indexOf } from 'lodash';
|
|
|
|
|
|
const baseURL =
|
|
const baseURL =
|
|
process.env.NODE_ENV === 'production'
|
|
process.env.NODE_ENV === 'production'
|
|
? // ? 'http://api.xt.wenhq.top:8083/mock/43/zhdd'
|
|
? // ? 'http://api.xt.wenhq.top:8083/mock/43/zhdd'
|
|
- 'http://sqpcbg.xt.wenhq.top:8083/api'
|
|
|
|
|
|
+ BASE_URL
|
|
: '/api';
|
|
: '/api';
|
|
|
|
|
|
const CancelToken = axios.CancelToken;
|
|
const CancelToken = axios.CancelToken;
|
|
@@ -31,6 +33,10 @@ axios.interceptors.response.use(
|
|
// message: `401. 没有权限访问该接口: ${res.config.url}`,
|
|
// message: `401. 没有权限访问该接口: ${res.config.url}`,
|
|
message: `401. 没有权限访问该接口`,
|
|
message: `401. 没有权限访问该接口`,
|
|
});
|
|
});
|
|
|
|
+ if (res.data.data.indexOf('Jwt expired') != -1) {
|
|
|
|
+ window.localStorage.removeItem('userdata');
|
|
|
|
+ window.location.href = LOGIN_URL;
|
|
|
|
+ }
|
|
throw Error(res.statusText);
|
|
throw Error(res.statusText);
|
|
}
|
|
}
|
|
if (res.data?.code === 404) {
|
|
if (res.data?.code === 404) {
|
|
@@ -38,7 +44,13 @@ axios.interceptors.response.use(
|
|
throw Error(res.statusText);
|
|
throw Error(res.statusText);
|
|
}
|
|
}
|
|
if (res.data?.code >= 500) {
|
|
if (res.data?.code >= 500) {
|
|
- ElMessage.error({ message: res.data?.msg ?? '系统异常, 请稍后重试!' });
|
|
|
|
|
|
+ if (res.data?.message == 'invalid ticket') {
|
|
|
|
+ window.localStorage.removeItem('userdata');
|
|
|
|
+ window.location.href = LOGIN_URL;
|
|
|
|
+ }
|
|
|
|
+ ElMessage.error({
|
|
|
|
+ message: res.data?.msg ?? '系统异常, 请稍后重试!',
|
|
|
|
+ });
|
|
throw Error(res.statusText);
|
|
throw Error(res.statusText);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -46,6 +58,7 @@ axios.interceptors.response.use(
|
|
ElMessage.error({
|
|
ElMessage.error({
|
|
message: `401. 没有权限访问该接口: ${res.config.url}`,
|
|
message: `401. 没有权限访问该接口: ${res.config.url}`,
|
|
});
|
|
});
|
|
|
|
+
|
|
throw Error(res.statusText);
|
|
throw Error(res.statusText);
|
|
}
|
|
}
|
|
if (res.status === 404) {
|
|
if (res.status === 404) {
|
|
@@ -68,14 +81,19 @@ export default function request<T>(
|
|
method: AxiosRequestConfig['method'] = 'GET',
|
|
method: AxiosRequestConfig['method'] = 'GET',
|
|
confifg: AxiosRequestConfig & {},
|
|
confifg: AxiosRequestConfig & {},
|
|
): Promise<T> {
|
|
): Promise<T> {
|
|
|
|
+ var tokenkjson = window.localStorage.getItem('userdata');
|
|
|
|
+ tokenkjson = tokenkjson == null ? "{}" : tokenkjson;
|
|
|
|
+ tokenkjson = tokenkjson == undefined ? "{}" : tokenkjson;
|
|
|
|
+ tokenkjson = JSON.parse(tokenkjson);
|
|
return axios.request({
|
|
return axios.request({
|
|
method,
|
|
method,
|
|
baseURL,
|
|
baseURL,
|
|
...confifg,
|
|
...confifg,
|
|
headers: {
|
|
headers: {
|
|
Accept: 'application/json',
|
|
Accept: 'application/json',
|
|
|
|
+ AppId: '3bcb760743ea456faba29a1dfb247bf4',
|
|
|
|
+ Authorization: 'Bearer ' + (tokenkjson["accessToken"]),
|
|
'Content-Type': 'application/json',
|
|
'Content-Type': 'application/json',
|
|
- Authorization: 'asdd',
|
|
|
|
...confifg.headers,
|
|
...confifg.headers,
|
|
},
|
|
},
|
|
});
|
|
});
|