File tree Expand file tree Collapse file tree 2 files changed +26
-13
lines changed
Expand file tree Collapse file tree 2 files changed +26
-13
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -2,25 +2,31 @@ import type { RouteRecordRaw } from 'vue-router'
22const modules : any = import . meta. glob ( './modules/*.ts' , { eager : true } )
33import { hasPermission , set_next_route } from '@/utils/permission/index'
44const 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
618export 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' ,
You can’t perform that action at this time.
0 commit comments