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

Merge branch 'v5.0.0dev' of https://gitee.com/ZhongBangKeJi/CRMEB into v5.0.0dev

evoxwht 2 лет назад
Родитель
Сommit
4de56866dc

+ 15 - 53
crmeb/app/adminapi/controller/v1/setting/SystemRoute.php

@@ -50,6 +50,7 @@ class SystemRoute extends AuthController
     public function syncRoute(string $appName = 'adminapi')
     {
         $this->services->syncRoute($appName);
+
         return app('json')->success();
     }
 
@@ -87,17 +88,6 @@ class SystemRoute extends AuthController
         return app('json')->success($this->services->getTreeList($where));
     }
 
-    /**
-     * 创建
-     * @return \think\Response
-     * @author 等风来
-     * @email 136327134@qq.com
-     * @date 2023/4/7
-     */
-    public function create()
-    {
-        return app('json')->success($this->services->getFrom(0, $this->request->get('app_name', 'adminapi')));
-    }
 
     /**
      * @return \think\Response
@@ -105,7 +95,7 @@ class SystemRoute extends AuthController
      * @email 136327134@qq.com
      * @date 2023/4/7
      */
-    public function save()
+    public function save($id = 0)
     {
         $data = $this->request->getMore([
             ['cate_id', 0],
@@ -114,6 +104,11 @@ class SystemRoute extends AuthController
             ['method', ''],
             ['type', 0],
             ['app_name', ''],
+            ['request', []],
+            ['response', []],
+            ['request_example', []],
+            ['response_example', []],
+            ['describe', ''],
         ]);
 
         if (!$data['name']) {
@@ -128,22 +123,13 @@ class SystemRoute extends AuthController
         if (!$data['app_name']) {
             return app('json')->fail('缺少应用名参数');
         }
+        if ($id) {
+            $this->services->update($id, $data);
+        } else {
+            $this->services->save($data);
+        }
 
-        $this->services->save($data);
-
-        return app('json')->success('添加成功');
-    }
-
-    /**
-     * @param $id
-     * @return \think\Response
-     * @author 等风来
-     * @email 136327134@qq.com
-     * @date 2023/4/7
-     */
-    public function edit($id)
-    {
-        return app('json')->success($this->services->getFrom($id, $this->request->get('app_name', 'adminapi')));
+        return app('json')->success($id ? '修改成功' : '添加成功');
     }
 
     /**
@@ -153,33 +139,9 @@ class SystemRoute extends AuthController
      * @email 136327134@qq.com
      * @date 2023/4/7
      */
-    public function update($id)
+    public function read($id)
     {
-        $data = $this->request->getMore([
-            ['cate_id', 0],
-            ['name', ''],
-            ['path', ''],
-            ['method', ''],
-            ['type', 0],
-            ['app_name', ''],
-        ]);
-
-        if (!$data['name']) {
-            return app('json')->fail('请输入路由名称');
-        }
-        if (!$data['path']) {
-            return app('json')->fail('请输入路由路径');
-        }
-        if (!$data['method']) {
-            return app('json')->fail('请选择路由请求方式');
-        }
-        if (!$data['app_name']) {
-            return app('json')->fail('缺少应用名参数');
-        }
-
-        $this->services->update($id, $data);
-
-        return app('json')->success('修改成功');
+        return app('json')->success($this->services->getInfo((int)$id));
     }
 
     /**

+ 6 - 11
crmeb/app/adminapi/route/system.php

@@ -113,18 +113,13 @@ Route::group('system', function () {
     //同步路由接口
     Route::get('route/sync_route/[:appName]', 'v1.system.SystemRoute/syncRoute')->option(['real_name' => '同步路由']);
     //获取路由tree行数据
-    Route::get('route/tree', 'v1.system.SystemRoute/tree')->option(['real_name' => '获取路由tree']);
+    Route::get('route/tree', 'v1.setting.SystemRoute/tree')->option(['real_name' => '获取路由tree']);
     //权限路由
-    Route::resource('route', 'v1.setting.SystemRoute')->option([
-        'real_name' => [
-            'index' => '获取路由列表',
-            'create' => '获取创建路由表单',
-            'save' => '保存路由',
-            'edit' => '获取修改路由表单',
-            'update' => '修改路由',
-            'delete' => '删除路由'
-        ],
-    ]);
+    Route::delete('route/:id', 'v1.setting.SystemRoute/delete')->option(['real_name' => '删除路由权限']);
+    //查看路由权限
+    Route::get('route/:id', 'v1.setting.SystemRoute/read')->option(['real_name' => '查看路由权限']);
+    //保存路由权限
+    Route::post('route/:id', 'v1.setting.SystemRoute/save')->option(['real_name' => '保存路由权限']);
     //路由分类
     Route::resource('route_cate', 'v1.setting.SystemRouteCate')->option([
         'real_name' => [

+ 41 - 0
crmeb/app/model/system/SystemRoute.php

@@ -45,4 +45,45 @@ class SystemRoute extends BaseModel
             $query->where('name|path', 'LIKE', '%' . $value . '%');
         }
     }
+
+    public function setRequestAttr($value)
+    {
+        return json_encode($value);
+    }
+
+    public function getRequestAttr($value)
+    {
+        return json_decode($value, true);
+    }
+
+    public function setResponseAttr($value)
+    {
+        return json_encode($value);
+    }
+
+    public function getResponseAttr($value)
+    {
+        return json_decode($value, true);
+    }
+
+    public function setRequestExampleAttr($value)
+    {
+        return json_encode($value);
+    }
+
+    public function getRequestExampleAttr($value)
+    {
+        return json_decode($value, true);
+    }
+
+
+    public function setResponseExampleAttr($value)
+    {
+        return json_encode($value);
+    }
+
+    public function getResponseExampleAttr($value)
+    {
+        return json_decode($value, true);
+    }
 }

+ 30 - 1
crmeb/app/services/system/SystemRouteServices.php

@@ -17,6 +17,7 @@ namespace app\services\system;
 use app\dao\system\SystemRouteDao;
 use app\services\BaseServices;
 use crmeb\services\FormBuilder;
+use think\exception\ValidateException;
 use think\helper\Str;
 
 /**
@@ -53,6 +54,23 @@ class SystemRouteServices extends BaseServices
         return compact('list', 'count');
     }
 
+    /**
+     * @param int $id
+     * @return array
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/4/10
+     */
+    public function getInfo(int $id)
+    {
+        $routeInfo = $this->dao->get($id);
+        if (!$routeInfo) {
+            throw new ValidateException('修改的路由不存在');
+        }
+
+        return $routeInfo->toArray();
+    }
+
     /**
      * 获取tree数据
      * @param string $appName
@@ -100,7 +118,7 @@ class SystemRouteServices extends BaseServices
 
         $route = $this->app->route->getRuleList();
         $action_arr = ['index', 'read', 'create', 'save', 'edit', 'update', 'delete'];
-        
+
         foreach ($route as &$item) {
             $real_name = $item['option']['real_name'] ?? '';
             if (is_array($real_name)) {
@@ -124,6 +142,16 @@ class SystemRouteServices extends BaseServices
      */
     public function syncRoute(string $app = 'adminapi')
     {
+        $id = app()->make(SystemRouteCateServices::class)->value(['app_name' => $app, 'name' => '全部权限', 'pid' => 0], 'id');
+        if (!$id) {
+            $res = app()->make(SystemRouteCateServices::class)->save([
+                'app_name' => $app,
+                'name' => '全部权限',
+                'pid' => 0,
+                'add_time' => time(),
+            ]);
+            $id = $res->id;
+        }
         $listAll = $this->getRouteListAll($app);
         //保持新增的权限路由
         $data = $this->dao->selectList(['app_name' => $app], 'path,method')->toArray();
@@ -133,6 +161,7 @@ class SystemRouteServices extends BaseServices
                 $save[] = [
                     'name' => $item['option']['real_name'] ?? $item['name'],
                     'path' => $item['rule'],
+                    'cate_id' => $id,
                     'app_name' => $app,
                     'type' => isset($item['option']['is_common']) && $item['option']['is_common'] ? 1 : 0,
                     'method' => $item['method'],