🐛 add interface access permissions
This commit is contained in:
@@ -35,13 +35,13 @@ const {onAuthRequired, onResponseRefreshToken} = createServerTokenAuthentication
|
||||
} else {
|
||||
message.error(i18n.global.t('error.loginExpired'));
|
||||
localStorage.removeItem('user');
|
||||
await router.push('/login');
|
||||
router.push('/login').then();
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
message.error(i18n.global.t('error.loginExpired'));
|
||||
localStorage.removeItem('user');
|
||||
await router.push('/login');
|
||||
router.push('/login').then();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,27 +68,33 @@ export const service = createAlova({
|
||||
}
|
||||
const lang = useStore().lang;
|
||||
method.config.headers['Accept-Language'] = lang.lang || 'zh';
|
||||
const client = useStore().client;
|
||||
method.config.headers['X-Request-Id'] = client.getClientId() || '';
|
||||
}),
|
||||
// 响应拦截器
|
||||
responded: onResponseRefreshToken({
|
||||
onSuccess: async (response: AxiosResponse, _method: any) => {
|
||||
if (response.data instanceof Blob) {
|
||||
return response;
|
||||
} else {
|
||||
if (response.data.code === 403) {
|
||||
notification.error({
|
||||
placement: 'topRight',
|
||||
message: i18n.global.t('error.loginExpired'),
|
||||
description: i18n.global.t('error.loginExpiredDesc'),
|
||||
onClose: () => {
|
||||
localStorage.removeItem('user');
|
||||
router.push('/login');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
const {code} = response.data;
|
||||
if (code === 403) {
|
||||
notification.error({
|
||||
placement: 'topRight',
|
||||
duration: 5,
|
||||
message: i18n.global.t('error.loginExpired'),
|
||||
description: i18n.global.t('error.loginExpiredDesc'),
|
||||
onClose: () => {
|
||||
localStorage.removeItem('user');
|
||||
router.push('/login').then();
|
||||
}
|
||||
});
|
||||
|
||||
throw new Error('Authentication Expired');
|
||||
} else {
|
||||
return response.data;
|
||||
}
|
||||
|
||||
},
|
||||
onError:
|
||||
(error: AxiosError, _method: any) => {
|
||||
|
@@ -6,6 +6,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.400"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -14,6 +15,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.401"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -22,6 +24,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.403"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -30,6 +33,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.404"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -38,6 +42,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.408"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -46,6 +51,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.500"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -54,6 +60,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.501"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -62,6 +69,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.502"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -70,6 +78,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.503"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -78,6 +87,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.504"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -86,6 +96,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.505"),
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
@@ -94,6 +105,7 @@ export function handleCode(code: number): void {
|
||||
message
|
||||
.open({
|
||||
content: i18n.global.t("error.other") + `(${code})`,
|
||||
duration: 5,
|
||||
type: "error",
|
||||
})
|
||||
.then();
|
||||
|
Reference in New Issue
Block a user