Просмотр исходного кода

调整添加权限是权限规则自动生成

liaofei 2 лет назад
Родитель
Сommit
0840443190

+ 32 - 1
crmeb/app/adminapi/controller/v1/setting/SystemMenus.php

@@ -130,14 +130,45 @@ class SystemMenus extends AuthController
         }
         $data = [];
 
+        $uniqueAuthAll = $this->services->getColumn(['is_del' => 0, 'is_show' => 1], 'unique_auth');
+        $uniqueAuthAll = array_filter($uniqueAuthAll, function ($item) {
+            return !!$item;
+        });
+        $uniqueAuthAll = array_unique($uniqueAuthAll);
+
+        $uniqueFn = function ($path) use ($uniqueAuthAll) {
+            $attPath = explode('/', $path);
+            $uniqueAuth = '';
+            if ($attPath) {
+                $pathData = [];
+                foreach ($attPath as $vv) {
+                    if (strstr($vv, '<') === false || strstr($vv, '?>') === false) {
+                        $pathData[] = $vv;
+                    }
+                }
+                $uniqueAuth = implode('-', $pathData);
+            }
+
+            if (in_array($uniqueAuth, $uniqueAuthAll)) {
+                $uniqueAuth .= '-' . uniqid();
+            }
+
+            array_push($uniqueAuthAll, $uniqueAuth);
+
+            return $uniqueAuth;
+        };
+
         foreach ($menus as $menu) {
             if (empty($menu['menu_name'])) {
                 return app('json')->fail(400198);
             }
+            if (isset($menu['unique_auth']) && $menu['unique_auth']) {
+                $menu['unique_auth'] = explode('/', $menu['api_url']);
+            }
             $data[] = [
                 'methods' => $menu['method'],
                 'menu_name' => $menu['menu_name'],
-                'unique_auth' => $menu['unique_auth'] ?? '',
+                'unique_auth' => !empty($menu['unique_auth']) ? $menu['unique_auth'] : $uniqueFn($menu['api_url']),
                 'api_url' => $menu['api_url'],
                 'pid' => $menu['path'],
                 'auth_type' => 2,

+ 1 - 2
crmeb/app/model/system/SystemCrud.php

@@ -56,8 +56,7 @@ class SystemCrud extends BaseModel
         return json_decode($value, true);
     }
 
-
-    public function getRoutesIdAttr($value)
+    public function getRouteIdsAttr($value)
     {
         return json_decode($value, true);
     }

+ 0 - 1
crmeb/app/services/system/SystemCrudServices.php

@@ -29,7 +29,6 @@ use crmeb\services\crud\ViewPages;
 use crmeb\services\crud\ViewRouter;
 use crmeb\services\FileService;
 use Phinx\Db\Adapter\AdapterFactory;
-use think\exception\ValidateException;
 use think\facade\Db;
 use think\helper\Str;
 use think\migration\db\Table;