From 2021fb575db9a19548a361f820e1256c6370999d Mon Sep 17 00:00:00 2001
From: chenghongxing <1126263215@qq.com>
Date: 星期三, 26 八月 2020 21:53:38 +0800
Subject: [PATCH] fix: problem that can't set roles array for route's authority; :bug: 修复:路由权限认证无法设置角色数组的问题;

---
 src/utils/routerUtil.js |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/src/utils/routerUtil.js b/src/utils/routerUtil.js
index d6a5172..39355a1 100644
--- a/src/utils/routerUtil.js
+++ b/src/utils/routerUtil.js
@@ -156,7 +156,25 @@
   if (typeof authority === 'object') {
     required = authority.role
   }
-  return authority === '*' || (required && roles && roles.findIndex(item => item === required || item.id === required) !== -1)
+  return authority === '*' || hasAnyRole(required, roles)
+}
+
+/**
+ * 鍒ゆ柇鏄惁鏈夐渶瑕佺殑浠绘剰涓�涓鑹�
+ * @param required {String | Array[String]} 闇�瑕佺殑瑙掕壊锛屽彲浠ユ槸鍗曚釜瑙掕壊鎴栬�呬竴涓鑹叉暟缁�
+ * @param roles 鎷ユ湁鐨勮鑹�
+ * @returns {boolean}
+ */
+function hasAnyRole(required, roles) {
+  if (!required) {
+    return false
+  } else if(Array.isArray(required)) {
+    return roles.findIndex(role => {
+      return required.findIndex(item => item === role || item === role.id) !== -1
+    }) !== -1
+  } else {
+    return roles.findIndex(role => role === required || role.id === required) !== -1
+  }
 }
 
 /**
@@ -174,6 +192,10 @@
         authority.permission = meta.authority
       } else if (typeof meta.authority === 'object') {
         authority = meta.authority
+        const {role} = authority
+        if (typeof role === 'string') {
+          authority.role = [role]
+        }
       } else {
         console.log(typeof meta.authority)
       }

--
Gitblit v1.9.1