Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 95b6bcce
authored
Jul 10, 2024
by
vince
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: can also see the menu without permission, but jump to 403
1 parent
46743802
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
6 deletions
apps/web-antd/src/locales/langs/en-US.json
apps/web-antd/src/locales/langs/zh-CN.json
apps/web-antd/src/router/routes/modules/demos.ts
apps/web-antd/src/views/demos/access/frontend/menu-visible-403.vue
packages/business/access/src/generate-menu-and-routes/generate-routes-frontend.ts
apps/web-antd/src/locales/langs/en-US.json
View file @
95b6bcc
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
"backendControl"
:
"Backend Control"
,
"backendControl"
:
"Backend Control"
,
"pageAccess"
:
"Page Access"
,
"pageAccess"
:
"Page Access"
,
"buttonControl"
:
"Button Control"
,
"buttonControl"
:
"Button Control"
,
"menuVisible403"
:
"Menu Visible(403)"
,
"superVisible"
:
"Visible to Super"
,
"superVisible"
:
"Visible to Super"
,
"adminVisible"
:
"Visible to Admin"
,
"adminVisible"
:
"Visible to Admin"
,
"userVisible"
:
"Visible to User"
"userVisible"
:
"Visible to User"
...
...
apps/web-antd/src/locales/langs/zh-CN.json
View file @
95b6bcc
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
"backendControl"
:
"后端控制"
,
"backendControl"
:
"后端控制"
,
"pageAccess"
:
"页面访问"
,
"pageAccess"
:
"页面访问"
,
"buttonControl"
:
"按钮控制"
,
"buttonControl"
:
"按钮控制"
,
"menuVisible403"
:
"菜单可见(403)"
,
"superVisible"
:
"Super 可见"
,
"superVisible"
:
"Super 可见"
,
"adminVisible"
:
"Admin 可见"
,
"adminVisible"
:
"Admin 可见"
,
"userVisible"
:
"User 可见"
"userVisible"
:
"User 可见"
...
...
apps/web-antd/src/router/routes/modules/demos.ts
View file @
95b6bcc
...
@@ -55,6 +55,19 @@ const routes: RouteRecordRaw[] = [
...
@@ -55,6 +55,19 @@ const routes: RouteRecordRaw[] = [
},
},
},
},
{
{
name
:
'AccessFrontendMenuVisible403'
,
path
:
'menu-visible-403'
,
component
:
()
=>
import
(
'#/views/demos/access/frontend/menu-visible-403.vue'
),
meta
:
{
authority
:
[
'no-body'
],
icon
:
'mdi:button-cursor'
,
menuVisibleWithForbidden
:
true
,
title
:
$t
(
'page.demos.access.menuVisible403'
),
},
},
{
name
:
'AccessFrontendSuperVisible'
,
name
:
'AccessFrontendSuperVisible'
,
path
:
'super-visible'
,
path
:
'super-visible'
,
component
:
()
=>
component
:
()
=>
...
...
apps/web-antd/src/views/demos/access/frontend/menu-visible-403.vue
0 → 100644
View file @
95b6bcc
<
script
lang=
"ts"
setup
>
import
{
Fallback
}
from
'@vben/universal-ui'
;
defineOptions
({
name
:
'AccessFrontendAccessTest2'
});
</
script
>
<
template
>
<Fallback
description=
"当前页面用户不可见,会被重定向到403页面"
status=
"comming-soon"
title=
"页面访问测试"
/>
</
template
>
packages/business/access/src/generate-menu-and-routes/generate-routes-frontend.ts
View file @
95b6bcc
...
@@ -34,14 +34,12 @@ async function generateRoutesByFrontend(
...
@@ -34,14 +34,12 @@ async function generateRoutesByFrontend(
*/
*/
function
hasAuthority
(
route
:
RouteRecordRaw
,
access
:
string
[])
{
function
hasAuthority
(
route
:
RouteRecordRaw
,
access
:
string
[])
{
const
authority
=
route
.
meta
?.
authority
;
const
authority
=
route
.
meta
?.
authority
;
if
(
!
authority
)
{
if
(
!
authority
)
{
return
true
;
return
true
;
}
}
return
(
const
canAccess
=
access
.
some
((
value
)
=>
authority
.
includes
(
value
));
access
.
some
((
value
)
=>
authority
.
includes
(
value
))
||
menuHasVisibleWithForbidden
(
route
)
return
canAccess
||
(
!
canAccess
&&
menuHasVisibleWithForbidden
(
route
));
);
}
}
/**
/**
...
@@ -57,7 +55,11 @@ function hasVisible(route?: RouteRecordRaw) {
...
@@ -57,7 +55,11 @@ function hasVisible(route?: RouteRecordRaw) {
* @param route
* @param route
*/
*/
function
menuHasVisibleWithForbidden
(
route
:
RouteRecordRaw
)
{
function
menuHasVisibleWithForbidden
(
route
:
RouteRecordRaw
)
{
return
!!
route
.
meta
?.
menuVisibleWithForbidden
;
return
(
!!
route
.
meta
?.
authority
&&
Reflect
.
has
(
route
.
meta
||
{},
'menuVisibleWithForbidden'
)
&&
!!
route
.
meta
?.
menuVisibleWithForbidden
);
}
}
export
{
generateRoutesByFrontend
,
hasAuthority
,
hasVisible
};
export
{
generateRoutesByFrontend
,
hasAuthority
,
hasVisible
};
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment