From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/directives/permission/hasPermi.ts | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/src/directives/permission/hasPermi.ts b/src/directives/permission/hasPermi.ts
new file mode 100644
index 0000000..90cd025
--- /dev/null
+++ b/src/directives/permission/hasPermi.ts
@@ -0,0 +1,31 @@
+import type { App } from 'vue'
+import { useUserStore } from '@/store/modules/user'
+
+const { t } = useI18n() // 鍥介檯鍖�
+
+/** 鍒ゆ柇鏉冮檺鐨勬寚浠� directive */
+export function hasPermi(app: App<Element>) {
+ app.directive('hasPermi', (el, binding) => {
+ const { value } = binding
+
+ if (value && value instanceof Array && value.length > 0) {
+ const hasPermissions = hasPermission(value)
+
+ if (!hasPermissions) {
+ el.parentNode && el.parentNode.removeChild(el)
+ }
+ } else {
+ throw new Error(t('permission.hasPermission'))
+ }
+ })
+}
+
+/** 鍒ゆ柇鏉冮檺鐨勬柟娉� function */
+const userStore = useUserStore()
+const all_permission = '*:*:*'
+export const hasPermission = (permission: string[]) => {
+ return (
+ userStore.permissions.has(all_permission) ||
+ permission.some((permission) => userStore.permissions.has(permission))
+ )
+}
--
Gitblit v1.8.0