Skip to content

Commit bba7a60

Browse files
authored
feat: route permission (#3379)
1 parent be6dd24 commit bba7a60

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

ui/src/router/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ router.beforeEach(
4747
if (to.meta.permission ? hasPermission(to.meta.permission as any, 'OR') : true) {
4848
next()
4949
} else {
50+
console.log('s')
51+
if (to.meta.get_permission_route) {
52+
const t = to.meta.get_permission_route()
53+
console.log(t)
54+
next(t)
55+
return
56+
}
5057
// 如果没有权限则直接取404页面
5158
next({ path: '/no-permission' })
5259
}

ui/src/router/routes.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@ import type { RouteRecordRaw } from 'vue-router'
22
const modules: any = import.meta.glob('./modules/*.ts', { eager: true })
33
import { hasPermission, set_next_route } from '@/utils/permission/index'
44
const rolesRoutes: RouteRecordRaw[] = [...Object.keys(modules).map((key) => modules[key].default)]
5+
const get_workspace_permission_route = () => {
6+
const route = rolesRoutes.find((route: any) => {
7+
return (
8+
route.meta?.menu &&
9+
(route.meta.permission ? hasPermission(route.meta.permission as any, 'OR') : true)
10+
)
11+
})
12+
if (route?.name) {
13+
return { name: route?.name }
14+
}
15+
return { name: 'noPermission' }
16+
}
517

618
export const routes: Array<RouteRecordRaw> = [
719
{
820
path: '/',
921
name: 'home',
10-
redirect: (to: any) => {
11-
const route = rolesRoutes.find((route: any) => {
12-
return (
13-
route.meta?.menu &&
14-
(route.meta.permission ? hasPermission(route.meta.permission as any, 'OR') : true)
15-
)
16-
})
17-
if (route?.name) {
18-
return { name: route?.name }
19-
}
20-
return { name: 'noPermission' }
21-
},
22+
redirect: '/application',
2223
children: [
23-
...rolesRoutes,
24+
...rolesRoutes.map((r) => {
25+
if (r.meta) {
26+
r.meta.get_permission_route = get_workspace_permission_route
27+
}
28+
return r
29+
}),
2430
{
2531
path: '/no-permission',
2632
name: 'noPermission',

0 commit comments

Comments
 (0)