liaofei 2 лет назад
Родитель
Сommit
a2d51bd87d
1 измененных файлов с 18 добавлено и 4 удалено
  1. 18 4
      crmeb/app/services/system/SystemRouteServices.php

+ 18 - 4
crmeb/app/services/system/SystemRouteServices.php

@@ -121,16 +121,30 @@ class SystemRouteServices extends BaseServices
         $route = $this->app->route->getRuleList();
         $action_arr = ['index', 'read', 'create', 'save', 'edit', 'update', 'delete'];
 
-        foreach ($route as &$item) {
+
+        foreach ($route as $key => $item) {
             $real_name = $item['option']['real_name'] ?? '';
             if (is_array($real_name)) {
-                foreach ($action_arr as $action) {
-                    if (Str::contains($item['route'], $action)) {
-                        $real_name = $real_name[$action] ?? '';
+                foreach ($action_arr as $a) {
+                    if (Str::contains($item['route'], $a)) {
+                        $real_name = $real_name[$a] ?? '';
                     }
                 }
             }
             $item['option']['real_name'] = $real_name;
+            $route[$key] = $item;
+            $except = $item['option']['except'] ?? [];
+
+            $router = is_string($item['route']) ? explode('/', $item['route']) : [];
+            $action = $router[count($router) - 1] ?? null;
+            //去除不需要的路由
+            if ($except && $action && in_array($action, $except)) {
+                unset($route[$key]);
+            }
+            $only = $item['option']['only'] ?? [];
+            if ($only && $action && !in_array($action, $only)) {
+                unset($route[$key]);
+            }
         }
 
         return $route;