| | |
| | | |
| | | export function hasPermi(app: App<Element>) { |
| | | app.directive('hasPermi', (el, binding) => { |
| | | const { wsCache } = useCache() |
| | | const { value } = binding |
| | | const all_permission = '*:*:*' |
| | | const userInfo = wsCache.get(CACHE_KEY.USER) |
| | | const permissions = userInfo?.permissions || [] |
| | | |
| | | if (value && value instanceof Array && value.length > 0) { |
| | | const permissionFlag = value |
| | | |
| | | const hasPermissions = permissions.some((permission: string) => { |
| | | return all_permission === permission || permissionFlag.includes(permission) |
| | | }) |
| | | const hasPermissions = hasPermission(value) |
| | | |
| | | if (!hasPermissions) { |
| | | el.parentNode && el.parentNode.removeChild(el) |
| | |
| | | } |
| | | }) |
| | | } |
| | | |
| | | export const hasPermission = (permission: string[]) => { |
| | | const { wsCache } = useCache() |
| | | const all_permission = '*:*:*' |
| | | const userInfo = wsCache.get(CACHE_KEY.USER) |
| | | const permissions = userInfo?.permissions || [] |
| | | |
| | | return permissions.some((p: string) => { |
| | | return all_permission === p || permission.includes(p) |
| | | }) |
| | | } |