|
...
|
...
|
@@ -31,19 +31,8 @@ class NavController extends BaseController |
|
|
|
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']);
|
|
|
|
$result = $this->findDetailsList($sort_list,$lists);
|
|
|
|
$detailsList = $result['detailsList'];
|
|
|
|
if(!empty($detailsList)){
|
|
|
|
//写入
|
|
|
|
|
|
|
|
}
|
|
|
|
$data = $result['result'];
|
|
|
|
}else{
|
|
|
|
$data = array();
|
|
|
|
$data = array();
|
|
|
|
if(!empty($lists)){
|
|
|
|
foreach ($lists as $v){
|
|
|
|
$v = (array)$v;
|
|
|
|
if ($v['pid'] == 0) {
|
|
...
|
...
|
@@ -51,6 +40,13 @@ class NavController extends BaseController |
|
|
|
$data[] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//获取菜单组排序字段
|
|
|
|
$groupInfo = $navGroup->read(['id'=>$this->param['group_id']]);
|
|
|
|
if(!empty($groupInfo['sort_list'])){
|
|
|
|
$sort_list = json_decode($groupInfo['sort_list']);
|
|
|
|
$detailsList = $this->getIdDetailsList($data);
|
|
|
|
$data = $this->findDetailsLists($sort_list,$detailsList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->response('success',Code::SUCCESS,$data);
|
|
|
|
}
|
|
...
|
...
|
@@ -62,72 +58,43 @@ class NavController extends BaseController |
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/18 14:54
|
|
|
|
*/
|
|
|
|
public function findDetailsList($data, &$detailsList) {
|
|
|
|
public function findDetailsLists($sort_list, $detailsList)
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
foreach ($data as $item) {
|
|
|
|
$item = (array)$item;
|
|
|
|
$items = $item;
|
|
|
|
$id = $items['id'];
|
|
|
|
$matchingDetail = null;
|
|
|
|
foreach ($detailsList as $k => $v) {
|
|
|
|
if ($id == $v['id']) {
|
|
|
|
$matchingDetail = $v;
|
|
|
|
unset($detailsList[$k]);
|
|
|
|
break; // Break once a match is found
|
|
|
|
}
|
|
|
|
foreach ($sort_list as $val) {
|
|
|
|
$val = (array)$val;
|
|
|
|
if (!empty($val['sub'])){
|
|
|
|
$detailsList[$val['id']]['sub'] = $this->findDetailsLists($val['sub'], $detailsList[$val['id']]['sub']);
|
|
|
|
}
|
|
|
|
if (!empty($matchingDetail)) {
|
|
|
|
$items = $matchingDetail;
|
|
|
|
if (empty($detailsList[$val['id']])){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!empty($item['sub']) && is_array($item['sub'])) {
|
|
|
|
$items['sub'] = $this->findDetailsList($item['sub'], $detailsList)['result'];
|
|
|
|
}
|
|
|
|
$result[] = $items;
|
|
|
|
$result[] = $detailsList[$val['id']];
|
|
|
|
unset($detailsList[$val['id']]);
|
|
|
|
}
|
|
|
|
return ['result'=>$result,'detailsList'=>$detailsList];
|
|
|
|
$result = array_merge($result, $detailsList);
|
|
|
|
return $this->success($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :
|
|
|
|
* @name : setDetails
|
|
|
|
* @author : lyh
|
|
|
|
* @method : post
|
|
|
|
* @time : 2023/12/21 9:09
|
|
|
|
*/
|
|
|
|
public function setDetails($details, &$result)
|
|
|
|
{
|
|
|
|
foreach ($details as $k => $v) {
|
|
|
|
if ($v['pid'] == 0) {// 一级菜单
|
|
|
|
$result[] = $v;
|
|
|
|
} else {
|
|
|
|
$parentIndex = $this->findParentIndex($result, $v['pid']);
|
|
|
|
if ($parentIndex !== null) {
|
|
|
|
// Add the current element under its parent
|
|
|
|
$result[$parentIndex]['sub'][] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the index of the parent element in $result based on 'id'.
|
|
|
|
*
|
|
|
|
* @param array $result
|
|
|
|
* @param int $parentId
|
|
|
|
* @return int|null
|
|
|
|
* @remark :根据id组装数据
|
|
|
|
* @name :getDetailsList
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/20 18:52
|
|
|
|
*/
|
|
|
|
private function findParentIndex($result, $parentId)
|
|
|
|
{
|
|
|
|
foreach ($result as $index => $item) {
|
|
|
|
if ($item['id'] == $parentId) {
|
|
|
|
return $index;
|
|
|
|
public function getIdDetailsList($data){
|
|
|
|
$detailsList = [];
|
|
|
|
foreach ($data as $v) {
|
|
|
|
if (!empty($v['sub'])){
|
|
|
|
$v['sub'] = $this->getIdDetailsList($v['sub']);
|
|
|
|
}
|
|
|
|
$detailsList[$v['id']] = $v;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return $this->success($detailsList);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取当前id下的所有子集
|
|
|
|
* @name :getSubList
|
...
|
...
|
|