From 61a2db936dcbc3d5aebe8ff850bcaab76e3b3785 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期一, 15 六月 2026 11:09:18 +0800
Subject: [PATCH] 合并恢复

---
 src/utils/permission.ts |   40 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/utils/permission.ts b/src/utils/permission.ts
index 68d3b84..3d6c5cd 100644
--- a/src/utils/permission.ts
+++ b/src/utils/permission.ts
@@ -1,10 +1,28 @@
+import useUserStore from '@/store/modules/user'
+
 /**
  * 瀛楃鏉冮檺鏍¢獙
  * @param {Array} value 鏍¢獙鍊�
  * @returns {Boolean}
  */
 export function checkPermi(value:Array<string>) {
-  return true
+  if (value && value instanceof Array && value.length > 0) {
+    const permissions:Array<string> = useUserStore().permissions
+    const permissionDatas = value
+    const all_permission = "*:*:*"
+
+    const hasPermission = permissions.some(permission => {
+      return all_permission === permission || permissionDatas.includes(permission)
+    })
+
+    if (!hasPermission) {
+      return false
+    }
+    return true
+  } else {
+    console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
+    return false
+  }
 }
 
 /**
@@ -13,5 +31,21 @@
  * @returns {Boolean}
  */
 export function checkRole(value:Array<string>) {
-  return true
-}
+  if (value && value instanceof Array && value.length > 0) {
+    const roles:Array<string> = useUserStore().roles
+    const permissionRoles = value
+    const super_admin = "admin"
+
+    const hasRole = roles.some(role => {
+      return super_admin === role || permissionRoles.includes(role)
+    })
+
+    if (!hasRole) {
+      return false
+    }
+    return true
+  } else {
+    console.error(`need roles! Like checkRole="['admin','editor']"`)
+    return false
+  }
+}
\ No newline at end of file

--
Gitblit v1.9.3