Explorar el Código

所有菜单下的所有按钮

wufeng hace 2 años
padre
commit
25d946dde1

+ 37 - 5
app/admin/controller/Action.php

@@ -4,6 +4,8 @@ namespace app\admin\controller;
 
 use app\BaseController;
 use app\admin\logic\ActionLogic;
+use app\model\ActionModel;
+use app\model\AdminMenuModel;
 use app\model\CommonModel;
 use think\exception\ValidateException;
 use think\facade\Config;
@@ -13,7 +15,7 @@ use think\facade\Validate;
 class Action extends BaseController
 {
     //获取权限列表
-    public function List()
+    public function list()
     {
         $menuid = $this->request->post('menuid', 0);
 
@@ -21,7 +23,7 @@ class Action extends BaseController
     }
 
     //添加权限
-    public function Add()
+    public function add()
     {
         $param = $this->request->only(['menuid', 'action_code', 'status' => CommonModel::$status_normal], 'post');
 
@@ -41,7 +43,7 @@ class Action extends BaseController
 //    }
 
     //编辑权限
-    public function Edit()
+    public function edit()
     {
         $param = $this->request->only(['id', 'action_code'], 'post');
 
@@ -56,7 +58,7 @@ class Action extends BaseController
     }
 
     //删除权限
-    public function Delete()
+    public function delete()
     {
         $id = $this->request->post('id/d', 0);
 
@@ -64,7 +66,7 @@ class Action extends BaseController
     }
 
     //启禁用权限
-    public function Status()
+    public function status()
     {
         $param = $this->request->only(['id', 'status'], 'post');
 
@@ -75,4 +77,34 @@ class Action extends BaseController
         return ActionLogic::Status($param);
     }
 
+    //获取所有菜单下的所有按钮
+    public function index()
+    {
+        $list = AdminMenuModel::field('id,menu_name,menu_type,menu_img,menu_route,menu_url,status,weight,addtime,is_private private')
+            ->where(['pid' => 0, 'is_show' => AdminMenuModel::$show])
+            ->append(['child'])
+            ->withAttr('child', function ($val, $data) {
+                return AdminMenuModel::field('id,menu_name,menu_type,menu_img,menu_route,menu_url,status,weight,addtime,is_private private,pid')
+                    ->where(['pid' => $data['id'], 'is_show' => AdminMenuModel::$show])
+                    ->append(['action'])
+                    ->withAttr('action', function ($v, $d) {
+                        return ActionModel::alias('a')
+                            ->leftJoin('action_list l', 'a.action_code=l.action_code')
+                            ->field('a.*,action_name')
+                            ->where(['a.menuid' => $d['id'], 'a.status' => CommonModel::$status_normal])
+                            ->select()
+                            ->toArray();
+                    })
+                    ->order('weight', 'desc')
+                    ->select()
+                    ->toArray();
+            })
+            ->order('weight', 'desc')
+            ->select()
+            ->toArray();
+
+        return json_show(CommonModel::$success, '获取成功', $list);
+    }
+
+
 }

+ 6 - 6
app/admin/controller/Menu.php

@@ -14,19 +14,19 @@ class Menu extends BaseController
 {
 
     //获取用户菜单列表
-    public function List()
+    public function list()
     {
         return MenuLogic::List();
     }
 
     //获取全部菜单
-    public function All()
+    public function all()
     {
         return MenuLogic::All();
     }
 
     //添加菜单
-    public function Add()
+    public function add()
     {
         $param = $this->request->only([
             'menu_name',
@@ -47,7 +47,7 @@ class Menu extends BaseController
     }
 
     //编辑菜单
-    public function Edit()
+    public function edit()
     {
 
         $param = $this->request->only([
@@ -70,7 +70,7 @@ class Menu extends BaseController
     }
 
     //删除菜单
-    public function Delete()
+    public function delete()
     {
         $id = $this->request->post('id/d', 0);
 
@@ -78,7 +78,7 @@ class Menu extends BaseController
     }
 
     //启禁用菜单
-    public function Status()
+    public function status()
     {
         $param = $this->request->only(['id', 'status'], 'post');
 

+ 12 - 11
app/admin/route/app.php

@@ -12,17 +12,18 @@ Route::rule('versionList', 'Admin/Version/getList');//版本列表
 Route::rule('versionAdd', 'Admin/Version/create');//新建版本
 
 //【菜单】
-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/Delete');//删除菜单
-Route::rule('menuStatus', 'admin/Menu/Status');//启禁用菜单
-Route::rule('menuActionAdd', 'admin/Action/Add');//给菜单添加按钮
-Route::rule('menuActionList', 'admin/Action/List');//获取菜单下按钮列表
-Route::rule('menuActionStatus', 'admin/Action/Status');//菜单下按钮启禁用
-Route::rule('menuActionSave', 'admin/Action/Edit');//修改菜单下按钮
-Route::rule('menuActionDel', 'admin/Action/Delete');//删除菜单下按钮
+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/delete');//删除菜单
+Route::rule('menuStatus', 'admin/Menu/status');//启禁用菜单
+Route::rule('menuActionAdd', 'admin/Action/add');//给菜单添加按钮
+Route::rule('menuAction', 'admin/Action/list');//获取菜单下按钮列表
+Route::rule('menuActionStatus', 'admin/Action/status');//菜单下按钮启禁用
+Route::rule('menuActionSave', 'admin/Action/edit');//修改菜单下按钮
+Route::rule('menuActionDel', 'admin/Action/delete');//删除菜单下按钮
+Route::rule('menuActionlist', 'admin/Action/index');//获取所有菜单下的所有按钮
 
 //【角色】
 Route::rule('roleList', 'admin/Role/List');//获取角色列表

BIN
public/storage/topic/20220908/456_20220908163806.png