diff --git a/ui/src/router/index.ts b/ui/src/router/index.ts index fc1a70614..052001acf 100644 --- a/ui/src/router/index.ts +++ b/ui/src/router/index.ts @@ -47,6 +47,13 @@ router.beforeEach( if (to.meta.permission ? hasPermission(to.meta.permission as any, 'OR') : true) { next() } else { + console.log('s') + if (to.meta.get_permission_route) { + const t = to.meta.get_permission_route() + console.log(t) + next(t) + return + } // 如果没有权限则直接取404页面 next({ path: '/no-permission' }) } diff --git a/ui/src/router/routes.ts b/ui/src/router/routes.ts index fc99718a2..9496591c0 100644 --- a/ui/src/router/routes.ts +++ b/ui/src/router/routes.ts @@ -2,25 +2,31 @@ import type { RouteRecordRaw } from 'vue-router' const modules: any = import.meta.glob('./modules/*.ts', { eager: true }) import { hasPermission, set_next_route } from '@/utils/permission/index' const rolesRoutes: RouteRecordRaw[] = [...Object.keys(modules).map((key) => modules[key].default)] +const get_workspace_permission_route = () => { + const route = rolesRoutes.find((route: any) => { + return ( + route.meta?.menu && + (route.meta.permission ? hasPermission(route.meta.permission as any, 'OR') : true) + ) + }) + if (route?.name) { + return { name: route?.name } + } + return { name: 'noPermission' } +} export const routes: Array = [ { path: '/', name: 'home', - redirect: (to: any) => { - const route = rolesRoutes.find((route: any) => { - return ( - route.meta?.menu && - (route.meta.permission ? hasPermission(route.meta.permission as any, 'OR') : true) - ) - }) - if (route?.name) { - return { name: route?.name } - } - return { name: 'noPermission' } - }, + redirect: '/application', children: [ - ...rolesRoutes, + ...rolesRoutes.map((r) => { + if (r.meta) { + r.meta.get_permission_route = get_workspace_permission_route + } + return r + }), { path: '/no-permission', name: 'noPermission',