Add permission control to element
This commit is contained in:
@@ -121,6 +121,12 @@ export const getUsername = async () => {
|
||||
return user.username
|
||||
}
|
||||
|
||||
export const getUserId = async () => {
|
||||
const user = await getUserInfo()
|
||||
|
||||
return user.id
|
||||
}
|
||||
|
||||
export const getCaptchaSrc = () => {
|
||||
captcha = getCaptcha(300, 150, 4)
|
||||
return captcha.base64Src
|
||||
@@ -227,3 +233,41 @@ const parentToTree = (data: _DataNode[]): _DataNode[] => {
|
||||
|
||||
return parents
|
||||
}
|
||||
|
||||
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 getPermission = (): string[] => {
|
||||
const s = getLocalStorage(STORAGE_USER_INFO_KEY)
|
||||
if (s === null) {
|
||||
return []
|
||||
}
|
||||
|
||||
const user = JSON.parse(s) as UserWithPowerInfoVo
|
||||
const operationCodes: string[] = []
|
||||
user.operations.forEach((operation) => {
|
||||
operationCodes.push(operation.code)
|
||||
})
|
||||
|
||||
return operationCodes
|
||||
}
|
||||
|
||||
export const hasPermission = (operationCode: string) => {
|
||||
return getPermission().indexOf(operationCode) !== -1
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user