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:
@ -1,4 +1,3 @@
|
|||||||
import { useRoute } from 'vue-router';
|
|
||||||
import type { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
import type { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
||||||
import { BACKEND_ERROR_CODE, REQUEST_CANCELED_CODE, createFlatRequest } from '@sa/axios';
|
import { BACKEND_ERROR_CODE, REQUEST_CANCELED_CODE, createFlatRequest } from '@sa/axios';
|
||||||
import { useAuthStore } from '@/store/modules/auth';
|
import { useAuthStore } from '@/store/modules/auth';
|
||||||
@ -52,7 +51,6 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
|
|||||||
return String(response.data.code) === import.meta.env.VITE_SERVICE_SUCCESS_CODE;
|
return String(response.data.code) === import.meta.env.VITE_SERVICE_SUCCESS_CODE;
|
||||||
},
|
},
|
||||||
async onBackendFail(response, instance) {
|
async onBackendFail(response, instance) {
|
||||||
const route = useRoute();
|
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
const responseCode = String(response.data.code);
|
const responseCode = String(response.data.code);
|
||||||
|
|
||||||
@ -68,10 +66,6 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
if (route.name === 'login') {
|
|
||||||
handleLogout();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// 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)) {
|
||||||
// handleLogout();
|
// handleLogout();
|
||||||
@ -86,19 +80,21 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
|
|||||||
// prevent the user from refreshing the page
|
// prevent the user from refreshing the page
|
||||||
window.addEventListener('beforeunload', handleLogout);
|
window.addEventListener('beforeunload', handleLogout);
|
||||||
|
|
||||||
window.$dialog?.warning({
|
if (!window.location.pathname?.startsWith('/login')) {
|
||||||
title: '系统提示',
|
window.$dialog?.warning({
|
||||||
content: '登录状态已过期,您可以继续留在该页面,或者重新登录',
|
title: '系统提示',
|
||||||
positiveText: '重新登录',
|
content: '登录状态已过期,您可以继续留在该页面,或者重新登录',
|
||||||
negativeText: '取消',
|
positiveText: '重新登录',
|
||||||
maskClosable: false,
|
negativeText: '取消',
|
||||||
closeOnEsc: false,
|
maskClosable: false,
|
||||||
onPositiveClick() {
|
closeOnEsc: false,
|
||||||
logoutAndCleanup();
|
onPositiveClick() {
|
||||||
}
|
logoutAndCleanup();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
request.cancelAllRequest();
|
request.cancelAllRequest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// when the backend response code is in `expiredTokenCodes`, it means the token is expired, and refresh token
|
// when the backend response code is in `expiredTokenCodes`, it means the token is expired, and refresh token
|
||||||
|
Reference in New Issue
Block a user