Menu permission control
This commit is contained in:
10
src/global.d.ts
vendored
10
src/global.d.ts
vendored
@@ -16,6 +16,7 @@ type RouteJsonObject = {
|
||||
id?: string
|
||||
element?: React.JSX.Element
|
||||
component?: React.ComponentType
|
||||
children?: RouteJsonObject[]
|
||||
name?: string
|
||||
titlePrefix?: string
|
||||
title?: string
|
||||
@@ -23,18 +24,21 @@ type RouteJsonObject = {
|
||||
icon?: IconComponent
|
||||
menu?: boolean
|
||||
auth?: boolean
|
||||
children?: RouteJsonObject[]
|
||||
permission?: boolean
|
||||
autoHide?: boolean
|
||||
}
|
||||
|
||||
type RouteHandle = {
|
||||
absolutePath: string
|
||||
name?: string
|
||||
menu?: boolean
|
||||
auth?: boolean
|
||||
titlePrefix?: string
|
||||
title?: string
|
||||
titlePostfix?: string
|
||||
icon?: IconComponent
|
||||
menu?: boolean
|
||||
auth?: boolean
|
||||
permission?: boolean
|
||||
autoHide?: boolean
|
||||
}
|
||||
|
||||
type _Response<T> = {
|
||||
|
||||
@@ -5,6 +5,7 @@ import FitFullScreen from '@/components/common/FitFullScreen'
|
||||
import Sidebar from '@/components/common/sidebar'
|
||||
import SidebarItemList from '@/components/common/sidebar/SidebarItemList'
|
||||
import SidebarItem from '@/components/common/sidebar/SidebarItem'
|
||||
import { hasPathPermission } from '@/utils/auth.ts'
|
||||
|
||||
const ToolsFramework: React.FC = () => {
|
||||
return (
|
||||
@@ -14,13 +15,15 @@ const ToolsFramework: React.FC = () => {
|
||||
<Sidebar
|
||||
title={'个人中心'}
|
||||
bottomFixed={
|
||||
<SidebarItemList>
|
||||
<SidebarItem
|
||||
path={'/system'}
|
||||
icon={IconFatwebSetting}
|
||||
text={'系统设置'}
|
||||
/>
|
||||
</SidebarItemList>
|
||||
hasPathPermission('/system') ? (
|
||||
<SidebarItemList>
|
||||
<SidebarItem
|
||||
path={'/system'}
|
||||
icon={IconFatwebSetting}
|
||||
text={'系统设置'}
|
||||
/>
|
||||
</SidebarItemList>
|
||||
) : undefined
|
||||
}
|
||||
>
|
||||
<SidebarItemList>
|
||||
|
||||
@@ -11,13 +11,16 @@ const mapJsonToRoute = (jsonObject: RouteJsonObject[]): RouteObject[] => {
|
||||
element: value.element,
|
||||
Component: value.component,
|
||||
handle: {
|
||||
absolutePath: value.absolutePath,
|
||||
name: value.name,
|
||||
titlePrefix: value.titlePrefix,
|
||||
title: value.title,
|
||||
titlePostfix: value.titlePostfix,
|
||||
icon: value.icon,
|
||||
menu: value.menu,
|
||||
auth: value.auth
|
||||
auth: value.auth,
|
||||
permission: value.permission,
|
||||
autoHide: value.autoHide
|
||||
},
|
||||
children: value.children && mapJsonToRoute(value.children)
|
||||
}))
|
||||
|
||||
@@ -75,16 +75,21 @@ export const getPermissionPath = (): string[] => {
|
||||
const user = JSON.parse(s) as UserWithInfoVo
|
||||
const paths: string[] = []
|
||||
user.menus.forEach((menu) => {
|
||||
paths.join(menu.url)
|
||||
paths.push(menu.url)
|
||||
})
|
||||
|
||||
return paths
|
||||
}
|
||||
|
||||
export const hasPathPermission = (path: string) => {
|
||||
return getPermissionPath().indexOf(path) !== -1
|
||||
}
|
||||
|
||||
/*
|
||||
export const getAuthRoute = (route: RouteJsonObject[]): RouteJsonObject[] => {
|
||||
return route.map((value) => {
|
||||
if (value.auth) {
|
||||
value.path
|
||||
if (value.absolutePath) {
|
||||
value.absolutePath
|
||||
}
|
||||
if (value.children) {
|
||||
value.children = getAuthRoute(value.children)
|
||||
@@ -92,6 +97,7 @@ export const getAuthRoute = (route: RouteJsonObject[]): RouteJsonObject[] => {
|
||||
return value
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
export const getCaptchaSrc = () => {
|
||||
captcha = getCaptcha(300, 150, 4)
|
||||
|
||||
Reference in New Issue
Block a user