Explorar el Código

获取全部菜单

wufeng hace 2 años
padre
commit
2d10dedfa7
Se han modificado 3 ficheros con 29 adiciones y 3 borrados
  1. 7 1
      app/admin/controller/Menu.php
  2. 20 1
      app/admin/logic/MenuLogic.php
  3. 2 1
      app/admin/route/app.php

+ 7 - 1
app/admin/controller/Menu.php

@@ -13,12 +13,18 @@ use think\facade\Validate;
 class Menu extends BaseController
 {
 
-    //获取菜单列表
+    //获取用户菜单列表
     public function List()
     {
         return MenuLogic::List();
     }
 
+    //获取全部菜单
+    public function All()
+    {
+        return MenuLogic::All();
+    }
+
     //添加菜单
     public function Add()
     {

+ 20 - 1
app/admin/logic/MenuLogic.php

@@ -10,7 +10,7 @@ use think\response\Json;
 class MenuLogic extends BaseLogic
 {
 
-    //获取菜单列表
+    //获取用户菜单列表
     public static function List(): Json
     {
         //menu_action是一个视图
@@ -45,6 +45,25 @@ class MenuLogic extends BaseLogic
 
     }
 
+    //获取全部菜单
+    public static function All(): Json
+    {
+        $list = AdminMenuModel::field('id,menu_name,menu_img,menu_route,status')
+            ->where('pid', 0)
+            ->append(['child'])
+            ->withAttr('child', function ($val, $data) {
+                return AdminMenuModel::field('id,menu_name,menu_img,menu_route,status')
+                    ->where('pid', $data['id'])
+                    ->select()
+                    ->toArray();
+            })
+            ->select()
+            ->toArray();
+
+        return json_show(CommonModel::$success, '获取成功', $list);
+
+    }
+
     //添加菜单
     public static function Add(array $data = []): Json
     {

+ 2 - 1
app/admin/route/app.php

@@ -11,7 +11,8 @@ Route::rule('versionList','Admin/Version/getList');//版本列表
 Route::rule('versionAdd','Admin/Version/create');//新建版本
 
 //【菜单】
-Route::rule('menuList', 'admin/Menu/List');//获取菜单列表
+Route::rule('menuList', 'admin/Menu/List');//获取用户菜单列表
+Route::rule('menuAll', 'admin/Menu/All');//获取全部菜单
 Route::rule('menuAdd', 'admin/Menu/Add');//添加菜单
 Route::rule('menuSave', 'admin/Menu/Edit');//编辑菜单
 Route::rule('menuDel', 'admin/Menu/Del');//删除菜单