Skip to content

Commit 95b6bcc

Browse files
committed
feat: can also see the menu without permission, but jump to 403
1 parent 4674380 commit 95b6bcc

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

apps/web-antd/src/locales/langs/en-US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"backendControl": "Backend Control",
99
"pageAccess": "Page Access",
1010
"buttonControl": "Button Control",
11+
"menuVisible403": "Menu Visible(403)",
1112
"superVisible": "Visible to Super",
1213
"adminVisible": "Visible to Admin",
1314
"userVisible": "Visible to User"

apps/web-antd/src/locales/langs/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"backendControl": "后端控制",
99
"pageAccess": "页面访问",
1010
"buttonControl": "按钮控制",
11+
"menuVisible403": "菜单可见(403)",
1112
"superVisible": "Super 可见",
1213
"adminVisible": "Admin 可见",
1314
"userVisible": "User 可见"

apps/web-antd/src/router/routes/modules/demos.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ const routes: RouteRecordRaw[] = [
5454
title: $t('page.demos.access.buttonControl'),
5555
},
5656
},
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+
5770
{
5871
name: 'AccessFrontendSuperVisible',
5972
path: 'super-visible',
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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>

packages/business/access/src/generate-menu-and-routes/generate-routes-frontend.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ async function generateRoutesByFrontend(
3434
*/
3535
function hasAuthority(route: RouteRecordRaw, access: string[]) {
3636
const authority = route.meta?.authority;
37-
3837
if (!authority) {
3938
return true;
4039
}
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));
4543
}
4644

4745
/**
@@ -57,7 +55,11 @@ function hasVisible(route?: RouteRecordRaw) {
5755
* @param route
5856
*/
5957
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+
);
6163
}
6264

6365
export { generateRoutesByFrontend, hasAuthority, hasVisible };

0 commit comments

Comments
 (0)