|
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; |
|
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; |
|
4
|
|
4
|
|
|
5
|
|
5
|
|
|
6
|
use App\Enums\Common\Code;
|
6
|
use App\Enums\Common\Code;
|
|
|
|
7
|
+use App\Http\Logic\Bside\Nav\NavLogic;
|
|
7
|
use App\Http\Requests\Bside\Nav\NavRequest;
|
8
|
use App\Http\Requests\Bside\Nav\NavRequest;
|
|
8
|
use App\Models\BNav;
|
9
|
use App\Models\BNav;
|
|
9
|
|
10
|
|
|
@@ -27,17 +28,8 @@ class NavController extends BaseController |
|
@@ -27,17 +28,8 @@ class NavController extends BaseController |
|
27
|
*/
|
28
|
*/
|
|
28
|
public function index(){
|
29
|
public function index(){
|
|
29
|
|
30
|
|
|
30
|
- $isTree = $this->param['tree']??false;
|
|
|
|
31
|
- // 显示位置
|
|
|
|
32
|
- $location = $this->param['location']??'';
|
|
|
|
33
|
|
31
|
|
|
34
|
- $lists = BNav::_all($this->user['project_id'],$location)->toArray();
|
|
|
|
35
|
-
|
|
|
|
36
|
- if($isTree){
|
|
|
|
37
|
- $lists = list_to_tree($lists);
|
|
|
|
38
|
- }
|
|
|
|
39
|
-
|
|
|
|
40
|
- return $this->success($lists);
|
32
|
+ return $this->success(NavLogic::instance()->list());
|
|
41
|
|
33
|
|
|
42
|
}
|
34
|
}
|
|
43
|
|
35
|
|
|
@@ -53,33 +45,11 @@ class NavController extends BaseController |
|
@@ -53,33 +45,11 @@ class NavController extends BaseController |
|
53
|
* @author:dc
|
45
|
* @author:dc
|
|
54
|
* @time 2023/5/8 17:06
|
46
|
* @time 2023/5/8 17:06
|
|
55
|
*/
|
47
|
*/
|
|
56
|
- private function save(NavRequest $request){
|
48
|
+ public function save(NavRequest $request){
|
|
57
|
$data = $request->validated();
|
49
|
$data = $request->validated();
|
|
58
|
|
50
|
|
|
59
|
- if($data['pid']){
|
|
|
|
60
|
- // 验证是否存在上级
|
|
|
|
61
|
- $all = BNav::_all($this->user['project_id'],$data['location']);
|
|
|
|
62
|
- if(!$all->where('id',$data['pid'])->count()){
|
|
|
|
63
|
- return $this->response('上级栏目不存在',Code::SYSTEM_ERROR);
|
|
|
|
64
|
- }
|
|
|
|
65
|
- // 上级不允许是自己的下级
|
|
|
|
66
|
- if(!empty($data['id'])){
|
|
|
|
67
|
- $all = list_to_tree($all->toArray(),$data['id']);
|
|
|
|
68
|
- $all = tree_to_list($all);
|
|
|
|
69
|
- if(in_array($data['pid'],array_column($all,'id'))){
|
|
|
|
70
|
- return $this->response('上级栏目不允许为本身的下级',Code::SYSTEM_ERROR);
|
|
|
|
71
|
- }
|
|
|
|
72
|
- }
|
|
|
|
73
|
- }
|
|
|
|
74
|
-
|
|
|
|
75
|
- // 保存
|
|
|
|
76
|
- $id = BNav::_save($this->user['project_id'],$data,$data['id']??0);
|
|
|
|
77
|
-
|
|
|
|
78
|
- if($id===-1){
|
|
|
|
79
|
- return $this->response('导航菜单不存在',Code::SYSTEM_ERROR);
|
|
|
|
80
|
- }
|
|
|
|
81
|
-
|
|
|
|
82
|
- return $this->success(BNav::_find($this->user['project_id'],$id,true));
|
51
|
+ return $this->success(NavLogic::instance()->save($data));
|
|
|
|
52
|
+
|
|
83
|
}
|
53
|
}
|
|
84
|
|
54
|
|
|
85
|
|
55
|
|
|
@@ -94,21 +64,9 @@ class NavController extends BaseController |
|
@@ -94,21 +64,9 @@ class NavController extends BaseController |
|
94
|
|
64
|
|
|
95
|
$id = $request->validated()['id'];
|
65
|
$id = $request->validated()['id'];
|
|
96
|
|
66
|
|
|
97
|
- $data = BNav::_find($this->user['project_id'],$id);
|
|
|
|
98
|
-
|
|
|
|
99
|
- if(empty($data)){
|
|
|
|
100
|
- return $this->response('导航菜单不存在',Code::SYSTEM_ERROR);
|
|
|
|
101
|
- }
|
|
|
|
102
|
-
|
|
|
|
103
|
-
|
|
|
|
104
|
- if(BNav::isChild($data['id'],$this->user['project_id'])){
|
|
|
|
105
|
- return $this->response('存在下级无法删除',Code::SYSTEM_ERROR);
|
|
|
|
106
|
- }
|
|
|
|
107
|
-
|
67
|
+ NavLogic::instance()->delete($id);
|
|
108
|
|
68
|
|
|
109
|
- if($data->delete()){
|
|
|
|
110
|
- return $this->response('删除成功',Code::SUCCESS);
|
|
|
|
111
|
- }
|
69
|
+ return $this->response('删除成功');
|
|
112
|
|
70
|
|
|
113
|
}
|
71
|
}
|
|
114
|
|
72
|
|