|
@@ -8,7 +8,7 @@ export function hasPermi(app: App<Element>) {
|
|
|
const { wsCache } = useCache()
|
|
|
const { value } = binding
|
|
|
const all_permission = '*:*:*'
|
|
|
- const permissions = wsCache.get(CACHE_KEY.USER).permissions
|
|
|
+ const permissions = wsCache.get(CACHE_KEY.USER)?.permissions ? wsCache.get(CACHE_KEY.USER)?.permissions : []
|
|
|
|
|
|
if (value && value instanceof Array && value.length > 0) {
|
|
|
const permissionFlag = value
|
|
@@ -25,3 +25,24 @@ export function hasPermi(app: App<Element>) {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+export function hasPermiEvery(app: App<Element>) {
|
|
|
+ app.directive('hasPermiEvery', (el, binding) => {
|
|
|
+ const { wsCache } = useCache()
|
|
|
+ const { value } = binding
|
|
|
+ const all_permission = '*:*:*'
|
|
|
+ const permissions = wsCache.get(CACHE_KEY.USER)?.permissions ? wsCache.get(CACHE_KEY.USER)?.permissions : []
|
|
|
+ if (value && value instanceof Array && value.length > 0) {
|
|
|
+ const permissionFlag = value
|
|
|
+ const hasPermissions = permissionFlag.every((permission: string) => {
|
|
|
+ return all_permission === permission || permissions.includes(permission)
|
|
|
+ })
|
|
|
+
|
|
|
+ if (!hasPermissions) {
|
|
|
+ el.parentNode && el.parentNode.removeChild(el)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Error(t('permission.hasPermission'))
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|