feat: can also see the menu without permission, but jump to 403
parent
4674380266
commit
95b6bcce6a
|
@ -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"
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"backendControl": "后端控制",
|
"backendControl": "后端控制",
|
||||||
"pageAccess": "页面访问",
|
"pageAccess": "页面访问",
|
||||||
"buttonControl": "按钮控制",
|
"buttonControl": "按钮控制",
|
||||||
|
"menuVisible403": "菜单可见(403)",
|
||||||
"superVisible": "Super 可见",
|
"superVisible": "Super 可见",
|
||||||
"adminVisible": "Admin 可见",
|
"adminVisible": "Admin 可见",
|
||||||
"userVisible": "User 可见"
|
"userVisible": "User 可见"
|
||||||
|
|
|
@ -54,6 +54,19 @@ const routes: RouteRecordRaw[] = [
|
||||||
title: $t('page.demos.access.buttonControl'),
|
title: $t('page.demos.access.buttonControl'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
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',
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { Fallback } from '@vben/universal-ui';
|
||||||
|
|
||||||
|
defineOptions({ name: 'AccessFrontendAccessTest2' });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Fallback
|
||||||
|
description="当前页面用户不可见,会被重定向到403页面"
|
||||||
|
status="comming-soon"
|
||||||
|
title="页面访问测试"
|
||||||
|
/>
|
||||||
|
</template>
|
|
@ -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) {
|
||||||
* @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 };
|
||||||
|
|
Loading…
Reference in New Issue