diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemRoute.php b/crmeb/app/adminapi/controller/v1/setting/SystemRoute.php index f2ecd08d2..21c477297 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemRoute.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemRoute.php @@ -87,17 +87,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 +94,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 +103,11 @@ class SystemRoute extends AuthController ['method', ''], ['type', 0], ['app_name', ''], + ['request', []], + ['response', []], + ['request_example', []], + ['response_example', []], + ['describe', ''], ]); if (!$data['name']) { @@ -128,10 +122,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('添加成功'); + return app('json')->success($id ? '修改成功' : '添加成功'); } /** @@ -141,45 +138,9 @@ class SystemRoute extends AuthController * @email 136327134@qq.com * @date 2023/4/7 */ - public function edit($id) + public function read($id) { - return app('json')->success($this->services->getFrom($id, $this->request->get('app_name', 'adminapi'))); - } - - /** - * @param $id - * @return \think\Response - * @author 等风来 - * @email 136327134@qq.com - * @date 2023/4/7 - */ - public function update($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)); } /** diff --git a/crmeb/app/adminapi/route/system.php b/crmeb/app/adminapi/route/system.php index 9886a78d2..b6a2cc838 100644 --- a/crmeb/app/adminapi/route/system.php +++ b/crmeb/app/adminapi/route/system.php @@ -115,16 +115,11 @@ Route::group('system', function () { //获取路由tree行数据 Route::get('route/tree', 'v1.system.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' => [ diff --git a/crmeb/app/model/system/SystemRoute.php b/crmeb/app/model/system/SystemRoute.php index 9465b46cc..e489750fd 100644 --- a/crmeb/app/model/system/SystemRoute.php +++ b/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); + } } diff --git a/crmeb/app/services/system/SystemRouteServices.php b/crmeb/app/services/system/SystemRouteServices.php index 2d0fb0339..bfa4f8ddb 100644 --- a/crmeb/app/services/system/SystemRouteServices.php +++ b/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