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);
|
||||
}
|
||||
|
||||
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
|
||||
// const logoutCodes = import.meta.env.VITE_SERVICE_LOGOUT_CODES?.split(',') || [];
|
||||
// if (logoutCodes.includes(responseCode)) {
|
||||
// handleLogout();
|
||||
// return null;
|
||||
// }
|
||||
const logoutCodes = import.meta.env.VITE_SERVICE_LOGOUT_CODES?.split(',') || [];
|
||||
if (logoutCodes.includes(responseCode) && !isLogin) {
|
||||
logoutAndCleanup();
|
||||
return null;
|
||||
}
|
||||
|
||||
// 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(',') || [];
|
||||
if (modalLogoutCodes.includes(responseCode)) {
|
||||
if (modalLogoutCodes.includes(responseCode) && isLogin) {
|
||||
const isExist = request.state.errMsgStack.includes(response.data.msg);
|
||||
if (isExist) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!window.location.pathname?.startsWith('/login')) {
|
||||
window.$dialog?.warning({
|
||||
title: '系统提示',
|
||||
content: '登录状态已过期,您可以继续留在该页面,或者重新登录',
|
||||
@ -90,12 +97,16 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
|
||||
closeOnEsc: false,
|
||||
onPositiveClick() {
|
||||
logoutAndCleanup();
|
||||
},
|
||||
onClose() {
|
||||
window.removeEventListener('beforeunload', handleLogout);
|
||||
request.state.errMsgStack = request.state.errMsgStack.filter(msg => msg !== response.data.msg);
|
||||
}
|
||||
});
|
||||
|
||||
request.cancelAllRequest();
|
||||
return null;
|
||||
}
|
||||
|
||||
logoutAndCleanup();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user