mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-23 23:39:47 +08:00
fix(projects): 修复刷新时跳转至登录页问题
This commit is contained in:
@ -65,22 +65,29 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
|
|||||||
request.state.errMsgStack = request.state.errMsgStack.filter(msg => msg !== response.data.msg);
|
request.state.errMsgStack = request.state.errMsgStack.filter(msg => msg !== response.data.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isLogin = Boolean(localStg.get('token'));
|
||||||
|
|
||||||
// when the backend response code is in `logoutCodes`, it means the user will be logged out and redirected to login page
|
// when the backend response code is in `logoutCodes`, it means the user will be logged out and redirected to login page
|
||||||
// const logoutCodes = import.meta.env.VITE_SERVICE_LOGOUT_CODES?.split(',') || [];
|
const logoutCodes = import.meta.env.VITE_SERVICE_LOGOUT_CODES?.split(',') || [];
|
||||||
// if (logoutCodes.includes(responseCode)) {
|
if (logoutCodes.includes(responseCode) && !isLogin) {
|
||||||
// handleLogout();
|
logoutAndCleanup();
|
||||||
// return null;
|
return null;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// when the backend response code is in `modalLogoutCodes`, it means the user will be logged out by displaying a modal
|
// when the backend response code is in `modalLogoutCodes`, it means the user will be logged out by displaying a modal
|
||||||
const modalLogoutCodes = import.meta.env.VITE_SERVICE_MODAL_LOGOUT_CODES?.split(',') || [];
|
const modalLogoutCodes = import.meta.env.VITE_SERVICE_MODAL_LOGOUT_CODES?.split(',') || [];
|
||||||
if (modalLogoutCodes.includes(responseCode)) {
|
if (modalLogoutCodes.includes(responseCode) && isLogin) {
|
||||||
request.state.errMsgStack = [...(request.state.errMsgStack || []), response.data.msg];
|
const isExist = request.state.errMsgStack.includes(response.data.msg);
|
||||||
|
if (isExist) {
|
||||||
// prevent the user from refreshing the page
|
return null;
|
||||||
window.addEventListener('beforeunload', handleLogout);
|
}
|
||||||
|
|
||||||
if (!window.location.pathname?.startsWith('/login')) {
|
if (!window.location.pathname?.startsWith('/login')) {
|
||||||
|
request.state.errMsgStack = [...(request.state.errMsgStack || []), response.data.msg];
|
||||||
|
|
||||||
|
// prevent the user from refreshing the page
|
||||||
|
window.addEventListener('beforeunload', handleLogout);
|
||||||
|
|
||||||
window.$dialog?.warning({
|
window.$dialog?.warning({
|
||||||
title: '系统提示',
|
title: '系统提示',
|
||||||
content: '登录状态已过期,您可以继续留在该页面,或者重新登录',
|
content: '登录状态已过期,您可以继续留在该页面,或者重新登录',
|
||||||
@ -90,12 +97,16 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
|
|||||||
closeOnEsc: false,
|
closeOnEsc: false,
|
||||||
onPositiveClick() {
|
onPositiveClick() {
|
||||||
logoutAndCleanup();
|
logoutAndCleanup();
|
||||||
|
},
|
||||||
|
onClose() {
|
||||||
|
window.removeEventListener('beforeunload', handleLogout);
|
||||||
|
request.state.errMsgStack = request.state.errMsgStack.filter(msg => msg !== response.data.msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
request.cancelAllRequest();
|
request.cancelAllRequest();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
logoutAndCleanup();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user