From 1140dfd27d2564f74f796c3ac08e3f54551cd159 Mon Sep 17 00:00:00 2001 From: liaofei <136327134@qq.com> Date: Mon, 10 Apr 2023 11:27:15 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/v1/setting/SystemRouteCate.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php b/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php index 86fb7020c..d277d7b99 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php @@ -73,7 +73,7 @@ class SystemRouteCate extends AuthController public function save(Request $request) { $data = $request->postMore([ - ['pid', 0], + ['pid', ''], ['name', ''], ['sort', 0], ['app_name', ''], @@ -84,10 +84,16 @@ class SystemRouteCate extends AuthController } $data['add_time'] = time(); + $pathAttr = explode('/', $data['pid']); + $pathData = []; + foreach ($pathAttr as $item) { + if (!$item) { + $pathData[] = $item; + } + } + $data['pid'] = $pathData[count($pathData) - 1] ?? 0; $res = $this->services->save($data); - - $path = $this->services->getPathValue($data['pid']); - $path = $this->services->setPathValue($path, $res->id); + $path = $this->services->setPathValue($data['pid'], $res->id); $res->path = $path; $res->save(); From 00af7e929fa600d67ffb7d49c151e9c2a9eb5683 Mon Sep 17 00:00:00 2001 From: liaofei <136327134@qq.com> Date: Mon, 10 Apr 2023 11:33:43 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/v1/setting/SystemRouteCate.php | 13 +++---------- .../app/services/system/SystemRouteCateServices.php | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php b/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php index d277d7b99..d5280b38d 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php @@ -73,7 +73,7 @@ class SystemRouteCate extends AuthController public function save(Request $request) { $data = $request->postMore([ - ['pid', ''], + ['pid', 0], ['name', ''], ['sort', 0], ['app_name', ''], @@ -84,16 +84,9 @@ class SystemRouteCate extends AuthController } $data['add_time'] = time(); - $pathAttr = explode('/', $data['pid']); - $pathData = []; - foreach ($pathAttr as $item) { - if (!$item) { - $pathData[] = $item; - } - } - $data['pid'] = $pathData[count($pathData) - 1] ?? 0; $res = $this->services->save($data); - $path = $this->services->setPathValue($data['pid'], $res->id); + $path = $this->services->getPathValue($data['pid']); + $path = $this->services->setPathValue($path, $res->id); $res->path = $path; $res->save(); diff --git a/crmeb/app/services/system/SystemRouteCateServices.php b/crmeb/app/services/system/SystemRouteCateServices.php index df80b661c..12f79166b 100644 --- a/crmeb/app/services/system/SystemRouteCateServices.php +++ b/crmeb/app/services/system/SystemRouteCateServices.php @@ -96,7 +96,7 @@ class SystemRouteCateServices extends BaseServices $cateInfo = $cateInfo ? $cateInfo->toArray() : []; $url .= '/' . $id; } - $options = $this->dao->selectList(['app_name' => $appName], 'name as label,path as value')->toArray(); + $options = $this->dao->selectList(['app_name' => $appName], 'name as label,id as value')->toArray(); $rule = [ FormBuilder::select('pid', '上级分类', (int)($cateInfo['pid'] ?? 0))->options($options), FormBuilder::input('name', '分类名称', $cateInfo['name'] ?? '')->required(), From 37ac5feb771639374ef9117aceef2c7e65e70b4d Mon Sep 17 00:00:00 2001 From: liaofei <136327134@qq.com> Date: Mon, 10 Apr 2023 11:35:07 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/app/services/system/SystemRouteServices.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crmeb/app/services/system/SystemRouteServices.php b/crmeb/app/services/system/SystemRouteServices.php index f11ea60d3..852427960 100644 --- a/crmeb/app/services/system/SystemRouteServices.php +++ b/crmeb/app/services/system/SystemRouteServices.php @@ -83,7 +83,7 @@ class SystemRouteServices extends BaseServices { $list = app()->make(SystemRouteCateServices::class) ->selectList(['app_name' => $appName], '*', 0, 0, 'id asc,sort desc', [ - 'children' => function ($query) use ($where) { + 'childrenList' => function ($query) use ($where) { $query->where('app_name', $where['app_name']) ->when('' !== $where['name_like'], function ($q) use ($where) { $q->where('name|path', 'LIKE', '%' . $where['name_like'] . '%'); From c133f4c898e9bf6ce29a8c02204c2d41124dbbe4 Mon Sep 17 00:00:00 2001 From: liaofei <136327134@qq.com> Date: Mon, 10 Apr 2023 11:36:15 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/app/model/system/SystemRouteCate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crmeb/app/model/system/SystemRouteCate.php b/crmeb/app/model/system/SystemRouteCate.php index 354960a74..c8137e906 100644 --- a/crmeb/app/model/system/SystemRouteCate.php +++ b/crmeb/app/model/system/SystemRouteCate.php @@ -37,7 +37,7 @@ class SystemRouteCate extends BaseModel * @email 136327134@qq.com * @date 2023/4/7 */ - public function children() + public function childrenList() { return $this->hasMany(SystemRoute::class, 'cate_id', 'id')->field(['id', 'cate_id', 'name', 'path', 'method'])->order('add_time desc'); } From f701fc87aceb2338be0c65eb4ee0d73a746eac46 Mon Sep 17 00:00:00 2001 From: liaofei <136327134@qq.com> Date: Mon, 10 Apr 2023 11:47:51 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E4=B8=BA=E5=A4=9A=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/v1/setting/SystemRouteCate.php | 19 ++++++------------- .../system/SystemRouteCateServices.php | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php b/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php index d5280b38d..985fe1d94 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemRouteCate.php @@ -73,7 +73,7 @@ class SystemRouteCate extends AuthController public function save(Request $request) { $data = $request->postMore([ - ['pid', 0], + ['path', []], ['name', ''], ['sort', 0], ['app_name', ''], @@ -84,11 +84,9 @@ class SystemRouteCate extends AuthController } $data['add_time'] = time(); - $res = $this->services->save($data); - $path = $this->services->getPathValue($data['pid']); - $path = $this->services->setPathValue($path, $res->id); - $res->path = $path; - $res->save(); + $data['pid'] = $data['path'][count($data['path']) - 1] ?? 0; + $this->services->save($data); + return app('json')->success('保存成功'); @@ -117,7 +115,7 @@ class SystemRouteCate extends AuthController public function update(Request $request, $id) { $data = $request->postMore([ - ['pid', 0], + ['path', []], ['name', ''], ['sort', 0], ['app_name', ''], @@ -127,12 +125,7 @@ class SystemRouteCate extends AuthController return app('json')->fail('缺少分类名称'); } - $pid = $this->services->value($id, 'pid'); - if ($data['pid'] != $pid) { - $path = $this->services->getPathValue($data['pid']); - $data['path'] = $this->services->setPathValue($path, $id); - } - + $data['pid'] = $data['path'][count($data['path']) - 1] ?? 0; $this->services->update($id, $data); return app('json')->success('修改成功'); diff --git a/crmeb/app/services/system/SystemRouteCateServices.php b/crmeb/app/services/system/SystemRouteCateServices.php index 12f79166b..b8f25d299 100644 --- a/crmeb/app/services/system/SystemRouteCateServices.php +++ b/crmeb/app/services/system/SystemRouteCateServices.php @@ -37,12 +37,8 @@ class SystemRouteCateServices extends BaseServices $this->dao = $dao; } - public function getPathValue(int $pid) + public function getPathValue(array $path) { - if (!$pid) { - return []; - } - $path = $this->dao->value($pid, 'path'); $pathAttr = explode('/', $path); $pathData = []; foreach ($pathAttr as $item) { @@ -91,14 +87,23 @@ class SystemRouteCateServices extends BaseServices { $url = '/system/route_cate'; $cateInfo = []; + $path = []; if ($id) { $cateInfo = $this->dao->get($id); $cateInfo = $cateInfo ? $cateInfo->toArray() : []; $url .= '/' . $id; + $path = explode('/', $cateInfo['path']); + $newPath = []; + foreach ($path as $item) { + if ($item) { + $newPath[] = $item; + } + } + $path = $newPath; } - $options = $this->dao->selectList(['app_name' => $appName], 'name as label,id as value')->toArray(); + $options = $this->dao->selectList(['app_name' => $appName], 'name as label,id as value,id,pid')->toArray(); $rule = [ - FormBuilder::select('pid', '上级分类', (int)($cateInfo['pid'] ?? 0))->options($options), + FormBuilder::cascader('path', '上级分类', $path)->data(get_tree_children($options)), FormBuilder::input('name', '分类名称', $cateInfo['name'] ?? '')->required(), FormBuilder::number('sort', '排序', (int)($cateInfo['sort'] ?? 0)), FormBuilder::hidden('app_name', $appName) From d928ca152376294d98475b3ba84db94144439dcc Mon Sep 17 00:00:00 2001 From: liaofei <136327134@qq.com> Date: Mon, 10 Apr 2023 11:59:41 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E4=B8=BA=E5=A4=9A=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/app/model/system/SystemRouteCate.php | 2 +- crmeb/app/services/system/SystemRouteServices.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crmeb/app/model/system/SystemRouteCate.php b/crmeb/app/model/system/SystemRouteCate.php index c8137e906..354960a74 100644 --- a/crmeb/app/model/system/SystemRouteCate.php +++ b/crmeb/app/model/system/SystemRouteCate.php @@ -37,7 +37,7 @@ class SystemRouteCate extends BaseModel * @email 136327134@qq.com * @date 2023/4/7 */ - public function childrenList() + public function children() { return $this->hasMany(SystemRoute::class, 'cate_id', 'id')->field(['id', 'cate_id', 'name', 'path', 'method'])->order('add_time desc'); } diff --git a/crmeb/app/services/system/SystemRouteServices.php b/crmeb/app/services/system/SystemRouteServices.php index 852427960..f11ea60d3 100644 --- a/crmeb/app/services/system/SystemRouteServices.php +++ b/crmeb/app/services/system/SystemRouteServices.php @@ -83,7 +83,7 @@ class SystemRouteServices extends BaseServices { $list = app()->make(SystemRouteCateServices::class) ->selectList(['app_name' => $appName], '*', 0, 0, 'id asc,sort desc', [ - 'childrenList' => function ($query) use ($where) { + 'children' => function ($query) use ($where) { $query->where('app_name', $where['app_name']) ->when('' !== $where['name_like'], function ($q) use ($where) { $q->where('name|path', 'LIKE', '%' . $where['name_like'] . '%');