NavController.php
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
namespace App\Http\Controllers\Bside\Nav;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Nav\NavLogic;
use App\Http\Requests\Bside\Nav\NavRequest;
use App\Models\Nav\BNav;
use App\Models\Nav\BNavGroup;
/**
* 导航栏目 b端编辑 c端显示
* @author:dc
* @time 2023/5/8 16:31
* Class NavController
* @package App\Http\Controllers\Bside
*/
class NavController extends BaseController
{
/**
* @remark :获取列表数据
* @name :index
* @author :lyh
* @method :post
* @time :2023/12/4 15:00
*/
public function index(BNav $nav,BNavGroup $navGroup){
$this->map['project_id'] = $this->user['project_id'];
$lists = $nav->list($this->map,$this->order = ['sort','id']);
//获取菜单组排序字段
$groupInfo = $navGroup->read(['id'=>$this->param['group_id']]);
if(!empty($groupInfo['sort_list'])){
$sort_list = json_decode($groupInfo['sort_list']);
$data = $this->findDetailsList($sort_list,$lists);
}else{
$data = array();
foreach ($lists as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $lists);
$data[] = $v;
}
}
}
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :根据固定的数组排序
* @name :findDetailsInList
* @author :lyh
* @method :post
* @time :2023/12/18 14:54
*/
public function findDetailsList($data, $detailsList) {
$result = [];
foreach ($data as $item) {
$items = $item = (array)$item;
$id = $item['id'];
// 在给定的详情列表中查找匹配的id
$matchingDetail = array_filter($detailsList, function ($detail) use ($id) {
return $detail['id'] == $id;
});
if (!empty($matchingDetail)) {
$items = reset($matchingDetail);
}
if (!empty($item['sub'])) {
$items['sub'] = $this->findDetailsList((array)$item['sub'], $detailsList);
}
$result[] = $items;
}
return $result;
}
/**
* @remark :获取当前id下的所有子集
* @name :getSubList
* @author :lyh
* @method :post
* @time :2023/12/4 15:04
*/
public function getSubList(NavLogic $logic){
$data = $logic->getSubList();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :保存数据
* @name :save
* @author :lyh
* @method :post
* @time :2023/8/21 11:32
*/
public function save(NavRequest $request,NavLogic $logic){
$request->validated();
$logic->navSave();
$this->response('success');
}
/**
* @remark :删除菜单
* @name :delete
* @author :lyh
* @method :post
* @time :2023/8/23 11:09
*/
public function delete(NavLogic $logic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => '产品ID不能为空',
]);
$logic->navDelete();
$this->response('success');
}
/**
* @author:dc
* @time 2023/5/9 16:14
*/
public function urls(){
// todo::需要配合 c端来
$data = [
['url'=>'index', 'name'=>'首页'],
['url'=>'news', 'name'=>'新闻'],
['url'=>'products', 'name'=>'产品'],
['url'=>'search', 'name'=>'搜索页'],
['url'=>'blog', 'name'=>'博客']
];
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :排序
* @name :sort
* @author :lyh
* @method :post
* @time :2023/8/22 9:49
*/
public function sort(NavLogic $navLogic){
$this->request->validate([
'id'=>'required',
'sort'=>'required'
],[
'id.required' => '产品ID不能为空',
'sort.required'=>'排序字段不能为空'
]);
$navLogic->navSort();
$this->response('success');
}
/**
* 一键导入子菜单
* @author zbj
* @date 2023/11/21
*/
public function import(NavLogic $navLogic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'ID不能为空',
]);
$navLogic->importNav();
$this->response('success');
}
/**
* @remark :菜单列表排序
* @name :setSortList
* @author :lyh
* @method :post
* @time :2023/12/18 13:44
*/
public function setSortList(NavLogic $navLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空',
]);
$navLogic->setSortList();
$this->response('success');
}
}