feat(ui): 无权限判断

This commit is contained in:
廖彦棋 2024-03-14 17:19:39 +08:00
parent ac5e67ea73
commit f01c764589
3 changed files with 20 additions and 13 deletions

View File

@ -5,13 +5,5 @@ declare module "*.vue" {
const component: DefineComponent<{}, {}, any>; const component: DefineComponent<{}, {}, any>;
export default component; export default component;
} }
import 'vue-router'
declare module 'vue-router' {
interface RouteMeta {
title?: string
icon?: any
permission?: boolean | string | string[]
}
}
declare const __AUTH_KEY: string; declare const __AUTH_KEY: string;

View File

@ -17,10 +17,17 @@ instance.interceptors.request.use((config) => {
instance.interceptors.response.use( instance.interceptors.response.use(
(response) => { (response) => {
const { data }: { data: BaseResponse<unknown> } = response const { data }: { data: BaseResponse<unknown> } = response
if (data && typeof data === "object" && data.code !== 0) { if (data && typeof data === "object" && data.code > 0) {
if (data.code === 400) { switch (data.code) {
localStorage.removeItem(__AUTH_KEY); case 400: {
router.push({ name: "Login" }) localStorage.removeItem(__AUTH_KEY);
router.push({ name: "Login" })
break;
}
case 403: {
router.replace({ name: "403" })
break;
}
} }
Notification.error(data.message ?? '未知错误') Notification.error(data.message ?? '未知错误')
} }

View File

@ -0,0 +1,8 @@
import 'vue-router'
declare module 'vue-router' {
interface RouteMeta {
title?: string
icon?: any
permission?: boolean | string | string[]
}
}