Add permission control to element

This commit is contained in:
2023-12-01 16:20:30 +08:00
parent 0bcadab98c
commit 406c362f84
9 changed files with 211 additions and 123 deletions

View File

@@ -1,5 +1,5 @@
import { getLocalStorage } from '@/util/browser.tsx'
import { STORAGE_USER_INFO_KEY } from '@/constants/common.constants.ts'
import { RouteObject } from 'react-router'
import { hasPathPermission } from '@/util/auth'
export const getRedirectUrl = (path: string, redirectUrl: string): string => {
return `${path}?redirect=${encodeURIComponent(redirectUrl)}`
@@ -15,25 +15,6 @@ export const getFullTitle = (data: _DataNode, preTitle?: string) => {
return data
}
export const getPermissionPath = (): string[] => {
const s = getLocalStorage(STORAGE_USER_INFO_KEY)
if (s === null) {
return []
}
const user = JSON.parse(s) as UserWithPowerInfoVo
const paths: string[] = []
user.menus.forEach((menu) => {
paths.push(menu.url)
})
return paths
}
export const hasPathPermission = (path: string) => {
return getPermissionPath().indexOf(path) !== -1
}
export const getAuthRoute = (
route: RouteJsonObject[],
parentPermission: boolean = false