liaofei hace 2 años
padre
commit
1fb61f9eb6

+ 14 - 0
crmeb/app/adminapi/controller/v1/setting/SystemCrud.php

@@ -16,6 +16,7 @@ namespace app\adminapi\controller\v1\setting;
 
 use app\adminapi\controller\AuthController;
 use app\services\system\SystemCrudServices;
+use app\services\system\SystemMenusServices;
 use think\facade\App;
 use think\helper\Str;
 
@@ -110,6 +111,19 @@ class SystemCrud extends AuthController
         return app('json')->success($makePath);
     }
 
+    /**
+     * 获取tree菜单
+     * @return \think\Response
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/4/11
+     */
+    public function getMenus()
+    {
+        return app('json')->success(app()->make(SystemMenusServices::class)
+            ->getList(['auth_type' => 1], ['pid', 'id', 'menu_name as label', 'id as value']));
+    }
+
     /**
      * 获取创建表数据类型
      * @return \think\Response

+ 2 - 0
crmeb/app/adminapi/route/system.php

@@ -133,6 +133,8 @@ Route::group('system', function () {
     ]);
     //获取CRUD列表
     Route::get('crud/column_type', 'v1.setting.SystemCrud/columnType')->option(['real_name' => '获取CRUD列表']);
+    //获取菜单TREE形数据
+    Route::get('crud/menus', 'v1.setting.SystemCrud/getMenus')->option(['real_name' => '获取菜单TREE形数据']);
     //获取CRUD文件存放
     Route::post('crud/file_path', 'v1.setting.SystemCrud/getFilePath')->option(['real_name' => '获取CRUD文件存放']);
     //删除CRUD

+ 2 - 2
crmeb/app/dao/system/SystemMenusDao.php

@@ -76,10 +76,10 @@ class SystemMenusDao extends BaseDao
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function getMenusList(array $where)
+    public function getMenusList(array $where, array $field = ['*'])
     {
         $where = array_merge($where, ['is_del' => 0]);
-        return $this->search($where)->order('sort DESC,id ASC')->select();
+        return $this->search($where)->field($field)->order('sort DESC,id ASC')->select();
     }
 
     /**

+ 2 - 2
crmeb/app/services/system/SystemMenusServices.php

@@ -89,9 +89,9 @@ class SystemMenusServices extends BaseServices
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function getList(array $where)
+    public function getList(array $where, array $field = ['*'])
     {
-        $menusList = $this->dao->getMenusList($where);
+        $menusList = $this->dao->getMenusList($where, $field);
         $menusList = $this->getMenusData($menusList);
         return get_tree_children($menusList);
     }