File tree Expand file tree Collapse file tree 5 files changed +36
-6
lines changed
views/demos/access/frontend
packages/business/access/src/generate-menu-and-routes Expand file tree Collapse file tree 5 files changed +36
-6
lines changed Original file line number Diff line number Diff line change 8
8
"backendControl" : " Backend Control" ,
9
9
"pageAccess" : " Page Access" ,
10
10
"buttonControl" : " Button Control" ,
11
+ "menuVisible403" : " Menu Visible(403)" ,
11
12
"superVisible" : " Visible to Super" ,
12
13
"adminVisible" : " Visible to Admin" ,
13
14
"userVisible" : " Visible to User"
Original file line number Diff line number Diff line change 8
8
"backendControl" : " 后端控制" ,
9
9
"pageAccess" : " 页面访问" ,
10
10
"buttonControl" : " 按钮控制" ,
11
+ "menuVisible403" : " 菜单可见(403)" ,
11
12
"superVisible" : " Super 可见" ,
12
13
"adminVisible" : " Admin 可见" ,
13
14
"userVisible" : " User 可见"
Original file line number Diff line number Diff line change @@ -54,6 +54,19 @@ const routes: RouteRecordRaw[] = [
54
54
title : $t ( 'page.demos.access.buttonControl' ) ,
55
55
} ,
56
56
} ,
57
+ {
58
+ name : 'AccessFrontendMenuVisible403' ,
59
+ path : 'menu-visible-403' ,
60
+ component : ( ) =>
61
+ import ( '#/views/demos/access/frontend/menu-visible-403.vue' ) ,
62
+ meta : {
63
+ authority : [ 'no-body' ] ,
64
+ icon : 'mdi:button-cursor' ,
65
+ menuVisibleWithForbidden : true ,
66
+ title : $t ( 'page.demos.access.menuVisible403' ) ,
67
+ } ,
68
+ } ,
69
+
57
70
{
58
71
name : 'AccessFrontendSuperVisible' ,
59
72
path : 'super-visible' ,
Original file line number Diff line number Diff line change
1
+ <script lang="ts" setup>
2
+ import { Fallback } from ' @vben/universal-ui' ;
3
+
4
+ defineOptions ({ name: ' AccessFrontendAccessTest2' });
5
+ </script >
6
+
7
+ <template >
8
+ <Fallback
9
+ description =" 当前页面用户不可见,会被重定向到403页面"
10
+ status =" comming-soon"
11
+ title =" 页面访问测试"
12
+ />
13
+ </template >
Original file line number Diff line number Diff line change @@ -34,14 +34,12 @@ async function generateRoutesByFrontend(
34
34
*/
35
35
function hasAuthority ( route : RouteRecordRaw , access : string [ ] ) {
36
36
const authority = route . meta ?. authority ;
37
-
38
37
if ( ! authority ) {
39
38
return true ;
40
39
}
41
- return (
42
- access . some ( ( value ) => authority . includes ( value ) ) ||
43
- menuHasVisibleWithForbidden ( route )
44
- ) ;
40
+ const canAccess = access . some ( ( value ) => authority . includes ( value ) ) ;
41
+
42
+ return canAccess || ( ! canAccess && menuHasVisibleWithForbidden ( route ) ) ;
45
43
}
46
44
47
45
/**
@@ -57,7 +55,11 @@ function hasVisible(route?: RouteRecordRaw) {
57
55
* @param route
58
56
*/
59
57
function menuHasVisibleWithForbidden ( route : RouteRecordRaw ) {
60
- return ! ! route . meta ?. menuVisibleWithForbidden ;
58
+ return (
59
+ ! ! route . meta ?. authority &&
60
+ Reflect . has ( route . meta || { } , 'menuVisibleWithForbidden' ) &&
61
+ ! ! route . meta ?. menuVisibleWithForbidden
62
+ ) ;
61
63
}
62
64
63
65
export { generateRoutesByFrontend , hasAuthority , hasVisible } ;
You can’t perform that action at this time.
0 commit comments