Skip to content

Commit

Permalink
feat: 401自动跳转到登录,403提示权限不足
Browse files Browse the repository at this point in the history
  • Loading branch information
WangJunZzz committed Jun 9, 2023
1 parent 26ca784 commit c42a798
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions vben28/src/locales/lang/en/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ export default {
default: 'Default',
name: 'Name',
value: 'Value',
parameterValidationFailure: 'Parameter Validation Failure',
permissionDenied: 'Permission Denied',
};
2 changes: 2 additions & 0 deletions vben28/src/locales/lang/zh-CN/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ export default {
default: '默认',
name: '名称',
value: '值',
parameterValidationFailure: '参数验证失败',
permissionDenied: '权限不足',
};
8 changes: 5 additions & 3 deletions vben28/src/services/ServiceProxyBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ export class ServiceProxyBase {
): Promise<any> {
const { t } = useI18n();

if (response.status == 401 || response.status == 403 || response.status == 302) {
if (response.status == 401) {
message.error(t('common.authorityText'));
router.replace(PageEnum.BASE_LOGIN);
} else if (response.status == 403) {
message.error(t('common.permissionDenied'));
} else if (response.status == 400) {
Modal.error({
title: '验证失败',
title: t('common.parameterValidationFailure'),
content: response.data.error.validationErrors[0].message,
});
} else if (response.status >= 500) {
Modal.error({
title: '请求异常',
title: t('common.systemErrorText'),
content: response.data.error.message,
});
}
Expand Down

0 comments on commit c42a798

Please sign in to comment.