diff --git a/src/directives/permission/hasPermi.ts b/src/directives/permission/hasPermi.ts index 931f44b3..02e2fbc7 100644 --- a/src/directives/permission/hasPermi.ts +++ b/src/directives/permission/hasPermi.ts @@ -5,18 +5,10 @@ const { t } = useI18n() // 国际化 export function hasPermi(app: App) { 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) @@ -26,3 +18,14 @@ export function hasPermi(app: App) { } }) } + +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) + }) +} \ No newline at end of file diff --git a/src/views/system/area/index.vue b/src/views/system/area/index.vue index 72cbcad2..339ecefb 100644 --- a/src/views/system/area/index.vue +++ b/src/views/system/area/index.vue @@ -16,6 +16,7 @@ - - \ No newline at end of file