--添加测试模块
This commit is contained in:
@ -24,6 +24,9 @@ import { notification } from 'ant-design-vue';
|
||||
import { throttle } from 'lodash-es';
|
||||
import useGlobalFlag from '/@/hooks/core/useGlobalFlag';
|
||||
|
||||
import { useLockStore } from '/@/store/modules/lock';
|
||||
|
||||
|
||||
const globSetting = useGlobSetting();
|
||||
const urlPrefix = globSetting.urlPrefix;
|
||||
const { createMessage, createErrorModal } = useMessage();
|
||||
@ -66,7 +69,7 @@ const transform: AxiosTransform = {
|
||||
throw new Error(t('请求出错,请稍候重试'));
|
||||
}
|
||||
// 这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
|
||||
const { code, data, msg } = result;
|
||||
const { code, data, msg, tid } = result;
|
||||
|
||||
// 这里逻辑可以根据项目进行修改
|
||||
const hasSuccess = code === ResultEnum.SUCCESS;
|
||||
@ -83,9 +86,22 @@ const transform: AxiosTransform = {
|
||||
|
||||
const userStore = useUserStoreWithOut();
|
||||
userStore.setToken(undefined);
|
||||
console.log('登录超时,请重新登录!');
|
||||
|
||||
if (!window.location.hash.includes('login')&&!window.location.pathname.includes('login')
|
||||
&&!window.location.hash.includes('tokenLogin')&&!window.location.pathname.includes('tokenLogin')) {
|
||||
userStore.logout(true);
|
||||
if (userStore.getUserInfo.loginConfig?.lockPageReLogin) {
|
||||
console.error('not login page goto lockpage window.location.hash={}, window.location.pathname={}', window.location.hash, window.location.pathname, timeoutMsg);
|
||||
// 触发全局弹层锁屏
|
||||
const lockStore = useLockStore();
|
||||
lockStore.setLockInfo({
|
||||
isLock: true,
|
||||
msg: timeoutMsg
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
userStore.logout(true);
|
||||
}
|
||||
}
|
||||
if (data) {
|
||||
if(data.urlToRedirectTo){
|
||||
@ -98,12 +114,29 @@ const transform: AxiosTransform = {
|
||||
}else{
|
||||
// data 有logout 信息 ,存sessionStorage 给login page 弹框显示
|
||||
if (data.logoutMessage) {
|
||||
console.error('logoutMessage', data.logoutMessage);
|
||||
timeoutMsg = data.logoutMessage;
|
||||
sessionStorage.setItem('logoutInfoData', JSON.stringify({
|
||||
logoutMessage: data.logoutMessage,
|
||||
}));
|
||||
}
|
||||
const go = useGo();
|
||||
go('/login');
|
||||
if (userStore.getUserInfo.loginConfig?.lockPageReLogin) {
|
||||
console.error('go-login', timeoutMsg);
|
||||
// 触发全局弹层锁屏
|
||||
const lockStore = useLockStore();
|
||||
lockStore.setLockInfo({
|
||||
isLock: true,
|
||||
msg: timeoutMsg
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
const go = useGo();
|
||||
if(go) {
|
||||
go('/login');
|
||||
} else {
|
||||
throw new Error(timeoutMsg || t('请求出错,请稍候重试'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -118,6 +151,10 @@ const transform: AxiosTransform = {
|
||||
if (options.ignoreErrorInEditor && isEditorOpen.value) {
|
||||
ajaxError();
|
||||
} else {
|
||||
if (tid) {
|
||||
timeoutMsg = timeoutMsg + '(异常操作号:' + tid + ')';
|
||||
}
|
||||
console.error('异常操作:', timeoutMsg, new Date().toLocaleString());
|
||||
if (options.errorMessageMode === 'modal') {
|
||||
createErrorModal({ title: t('错误提示'), content: timeoutMsg });
|
||||
} else if (options.errorMessageMode === 'message') {
|
||||
@ -252,7 +289,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
|
||||
// authentication schemes,e.g: Bearer
|
||||
// authenticationScheme: 'Bearer',
|
||||
authenticationScheme: 'Bearer',
|
||||
timeout: 600000,
|
||||
timeout: globSetting.requestTimeout||60 * 1000,
|
||||
// 基础接口地址
|
||||
// baseURL: globSetting.apiUrl,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user