|
@@ -9,12 +9,13 @@ import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
|
|
|
import type { MessageHandler } from 'element-plus';
|
|
|
import { initSyncTime, fetchTime } from '../utils/syncServerTime';
|
|
|
import { getAuthorization } from '../utils/crypto';
|
|
|
-import { DEVICE_ID, PLATFORM } from '../constants/app';
|
|
|
+// import { DEVICE_ID, PLATFORM } from '../constants/app';
|
|
|
import { objTypeOf } from '../utils/utils';
|
|
|
import { useUserStore } from '../store';
|
|
|
|
|
|
axios.defaults.timeout = 60 * 1000;
|
|
|
-
|
|
|
+axios.defaults.headers.post['Content-Type'] =
|
|
|
+ 'application/x-www-form-urlencoded';
|
|
|
let load: MessageHandler | null = null;
|
|
|
// 同一时间有多个请求时,会形成队列。在第一个请求创建loading,在最后一个响应关闭loading
|
|
|
const queue: Array<string | undefined> = [];
|
|
@@ -25,16 +26,14 @@ const modifyConfig = (config: AxiosRequestConfig): void => {
|
|
|
const userStore = useUserStore();
|
|
|
if (!config.headers) config.headers = {};
|
|
|
|
|
|
- if (userStore.token) {
|
|
|
- config.headers.userId = String(userStore.id);
|
|
|
-
|
|
|
+ if (userStore.accessToken) {
|
|
|
// 新版鉴权
|
|
|
const timestamp = fetchTime();
|
|
|
const Authorization = getAuthorization(
|
|
|
{
|
|
|
- token: userStore.token,
|
|
|
+ token: userStore.accessToken,
|
|
|
timestamp,
|
|
|
- account: userStore.sessionId,
|
|
|
+ account: userStore.loginName,
|
|
|
uri: config.url?.split('?')[0] || '',
|
|
|
method: config.method as string,
|
|
|
},
|
|
@@ -43,9 +42,9 @@ const modifyConfig = (config: AxiosRequestConfig): void => {
|
|
|
config.headers.Authorization = Authorization;
|
|
|
config.headers.time = String(timestamp);
|
|
|
}
|
|
|
- config.headers.deviceId = DEVICE_ID;
|
|
|
- config.headers.platform = PLATFORM;
|
|
|
- config.headers.domain = window.location.origin;
|
|
|
+ // config.headers.deviceId = DEVICE_ID;
|
|
|
+ // config.headers.platform = PLATFORM;
|
|
|
+ // config.headers.domain = window.location.origin;
|
|
|
};
|
|
|
|
|
|
axios.interceptors.request.use(
|
|
@@ -61,7 +60,7 @@ axios.interceptors.request.use(
|
|
|
}
|
|
|
queue.push(config.url);
|
|
|
|
|
|
- modifyConfig(config as AxiosRequestConfig); // Cast to AxiosRequestConfig if modifyConfig expects that
|
|
|
+ modifyConfig(config as AxiosRequestConfig);
|
|
|
return config;
|
|
|
},
|
|
|
(error) => {
|
|
@@ -94,6 +93,8 @@ axios.interceptors.response.use(
|
|
|
return response.data;
|
|
|
},
|
|
|
(error) => {
|
|
|
+ console.log(error);
|
|
|
+
|
|
|
// 关闭loading提示
|
|
|
setTimeout(() => {
|
|
|
queue.shift();
|
|
@@ -154,7 +155,7 @@ axios.interceptors.response.use(
|
|
|
ElMessageBox.confirm(message, '重新登陆?', {
|
|
|
confirmButtonText: '确定',
|
|
|
showCancelButton: false,
|
|
|
- type: 'warning',
|
|
|
+ type: 'error',
|
|
|
autofocus: false,
|
|
|
closeOnClickModal: false,
|
|
|
closeOnPressEscape: false,
|
|
@@ -163,7 +164,7 @@ axios.interceptors.response.use(
|
|
|
.then(() => {
|
|
|
unauthMsgBoxIsShow = false;
|
|
|
const userStore = useUserStore();
|
|
|
- userStore.logout();
|
|
|
+ userStore.logout(false);
|
|
|
})
|
|
|
.catch(() => {
|
|
|
// 用户点击了关闭按钮或者按了 ESC,理论上不会发生,因为 showClose 和 closeOnPressEscape 都是 false
|