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