mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-27 21:56:42 +08:00
feat(projects): Add handling for no permission codes in the backend request (#508)
This commit is contained in:
parent
a13251efd0
commit
f9efd7dfc4
3
.env
3
.env
@ -29,6 +29,9 @@ VITE_ROUTER_HISTORY_MODE=history
|
|||||||
# success code of backend service, when the code is received, the request is successful
|
# success code of backend service, when the code is received, the request is successful
|
||||||
VITE_SERVICE_SUCCESS_CODE=0000
|
VITE_SERVICE_SUCCESS_CODE=0000
|
||||||
|
|
||||||
|
# no permission codes of backend service, when the code is received, it will displaying a warning message
|
||||||
|
VITE_SERVICE_NO_PERMISSION_CODES=4444,4445
|
||||||
|
|
||||||
# logout codes of backend service, when the code is received, the user will be logged out and redirected to login page
|
# logout codes of backend service, when the code is received, the user will be logged out and redirected to login page
|
||||||
VITE_SERVICE_LOGOUT_CODES=8888,8889
|
VITE_SERVICE_LOGOUT_CODES=8888,8889
|
||||||
|
|
||||||
|
@ -60,7 +60,8 @@ const local: App.I18n.Schema = {
|
|||||||
logoutWithModal: 'Pop up modal after request failed and then log out user',
|
logoutWithModal: 'Pop up modal after request failed and then log out user',
|
||||||
logoutWithModalMsg: 'User status is invalid, please log in again',
|
logoutWithModalMsg: 'User status is invalid, please log in again',
|
||||||
refreshToken: 'The requested token has expired, refresh the token',
|
refreshToken: 'The requested token has expired, refresh the token',
|
||||||
tokenExpired: 'The requested token has expired'
|
tokenExpired: 'The requested token has expired',
|
||||||
|
noPermission: 'The request has no permission'
|
||||||
},
|
},
|
||||||
theme: {
|
theme: {
|
||||||
themeSchema: {
|
themeSchema: {
|
||||||
|
@ -60,7 +60,8 @@ const local: App.I18n.Schema = {
|
|||||||
logoutWithModal: '请求失败后弹出模态框再登出用户',
|
logoutWithModal: '请求失败后弹出模态框再登出用户',
|
||||||
logoutWithModalMsg: '用户状态失效,请重新登录',
|
logoutWithModalMsg: '用户状态失效,请重新登录',
|
||||||
refreshToken: '请求的token已过期,刷新token',
|
refreshToken: '请求的token已过期,刷新token',
|
||||||
tokenExpired: 'token已过期'
|
tokenExpired: 'token已过期',
|
||||||
|
noPermission: '无接口访问权限'
|
||||||
},
|
},
|
||||||
theme: {
|
theme: {
|
||||||
themeSchema: {
|
themeSchema: {
|
||||||
|
@ -50,6 +50,13 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
|
|||||||
await handleLogout();
|
await handleLogout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when the backend response code is in 'noPermissionCodes', displaying warning message.
|
||||||
|
const noPermissionCodes = import.meta.env.VITE_SERVICE_NO_PERMISSION_CODES?.split(',');
|
||||||
|
if (noPermissionCodes?.includes(response.data.code)) {
|
||||||
|
window.$message?.warning(response.data.msg || $t('request.noPermission'));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// 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(response.data.code)) {
|
if (logoutCodes?.includes(response.data.code)) {
|
||||||
|
1
src/typings/app.d.ts
vendored
1
src/typings/app.d.ts
vendored
@ -311,6 +311,7 @@ declare namespace App {
|
|||||||
logoutWithModalMsg: string;
|
logoutWithModalMsg: string;
|
||||||
refreshToken: string;
|
refreshToken: string;
|
||||||
tokenExpired: string;
|
tokenExpired: string;
|
||||||
|
noPermission: string;
|
||||||
};
|
};
|
||||||
theme: {
|
theme: {
|
||||||
themeSchema: { title: string } & Record<UnionKey.ThemeScheme, string>;
|
themeSchema: { title: string } & Record<UnionKey.ThemeScheme, string>;
|
||||||
|
8
src/typings/env.d.ts
vendored
8
src/typings/env.d.ts
vendored
@ -33,6 +33,14 @@ declare namespace Env {
|
|||||||
* when the code is received, the request is successful
|
* when the code is received, the request is successful
|
||||||
*/
|
*/
|
||||||
readonly VITE_SERVICE_SUCCESS_CODE: string;
|
readonly VITE_SERVICE_SUCCESS_CODE: string;
|
||||||
|
/**
|
||||||
|
* no permission codes of backend service
|
||||||
|
*
|
||||||
|
* when the code is received, it will displaying a warning message
|
||||||
|
*
|
||||||
|
* use "," to separate multiple codes
|
||||||
|
*/
|
||||||
|
readonly VITE_SERVICE_NO_PERMISSION_CODES: string;
|
||||||
/**
|
/**
|
||||||
* logout codes of backend service
|
* logout codes of backend service
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user