正在显示
1 个修改的文件
包含
9 行增加
和
70 行删除
| @@ -31,8 +31,13 @@ class NavController extends BaseController | @@ -31,8 +31,13 @@ class NavController extends BaseController | ||
| 31 | public function index(BNav $nav,BNavGroup $navGroup){ | 31 | public function index(BNav $nav,BNavGroup $navGroup){ |
| 32 | $this->map['project_id'] = $this->user['project_id']; | 32 | $this->map['project_id'] = $this->user['project_id']; |
| 33 | $lists = $nav->list($this->map,$this->order = ['sort','id']); | 33 | $lists = $nav->list($this->map,$this->order = ['sort','id']); |
| 34 | + //获取菜单组排序字段 | ||
| 35 | + $groupInfo = $navGroup->read(['id'=>$this->param['group_id']]); | ||
| 36 | + if(!empty($groupInfo['sort_list'])){ | ||
| 37 | + $sort_list = json_decode($groupInfo['sort_list']); | ||
| 38 | + $data = $this->findDetailsList($sort_list,$lists); | ||
| 39 | + }else{ | ||
| 34 | $data = array(); | 40 | $data = array(); |
| 35 | - if(!empty($lists)){ | ||
| 36 | foreach ($lists as $v){ | 41 | foreach ($lists as $v){ |
| 37 | $v = (array)$v; | 42 | $v = (array)$v; |
| 38 | if ($v['pid'] == 0) { | 43 | if ($v['pid'] == 0) { |
| @@ -40,87 +45,21 @@ class NavController extends BaseController | @@ -40,87 +45,21 @@ class NavController extends BaseController | ||
| 40 | $data[] = $v; | 45 | $data[] = $v; |
| 41 | } | 46 | } |
| 42 | } | 47 | } |
| 43 | - //获取菜单组排序字段 | ||
| 44 | - $groupInfo = $navGroup->read(['id'=>$this->param['group_id']]); | ||
| 45 | - if(!empty($groupInfo['sort_list'])){ | ||
| 46 | - $sort_list = json_decode($groupInfo['sort_list']); | ||
| 47 | - $detailsList = $this->getIdDetailsList($data); | ||
| 48 | - $data = $this->findDetailsLists($sort_list,$detailsList); | ||
| 49 | - } | ||
| 50 | } | 48 | } |
| 51 | $this->response('success',Code::SUCCESS,$data); | 49 | $this->response('success',Code::SUCCESS,$data); |
| 52 | } | 50 | } |
| 53 | 51 | ||
| 54 | /** | 52 | /** |
| 55 | - * @remark :排序 | ||
| 56 | - * @name :findDetailsLists | ||
| 57 | - * @author :lyh | ||
| 58 | - * @method :post | ||
| 59 | - * @time :2023/12/20 20:29 | ||
| 60 | - */ | ||
| 61 | - public function findDetailsLists($sort_list, $detailsList) | ||
| 62 | - { | ||
| 63 | - $result = []; | ||
| 64 | - foreach ($sort_list as $val) { | ||
| 65 | - $val = (array)$val; | ||
| 66 | - if (!empty($val['sub'])){ | ||
| 67 | - $this->findDetailsLists($val['sub'], $detailsList[$val['id']]['sub']); | ||
| 68 | - } | ||
| 69 | - if (empty($detailsList[$val['id']])){ | ||
| 70 | - continue; | ||
| 71 | - } | ||
| 72 | - $result[] = $detailsList[$val['id']]; | ||
| 73 | - unset($detailsList[$val['id']]); | ||
| 74 | - } | ||
| 75 | - $result = array_merge($result, $detailsList); | ||
| 76 | - foreach ($result as $k => $v){ | ||
| 77 | - if(!empty($v['sub'])){ | ||
| 78 | - $result[$k] = $this->getSonList($v['sub']); | ||
| 79 | - } | ||
| 80 | - } | ||
| 81 | - return $this->success($result); | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - public function getSonList($result){ | ||
| 85 | - foreach ($result as $k => $v){ | ||
| 86 | - if(!empty($v['sub'])){ | ||
| 87 | - $this->getSonList($v['sub']); | ||
| 88 | - } | ||
| 89 | - $result[$k] = array_values($v['sub']); | ||
| 90 | - } | ||
| 91 | - return $result; | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - /** | ||
| 95 | - * @remark :根据id组装数据 | ||
| 96 | - * @name :getDetailsList | ||
| 97 | - * @author :lyh | ||
| 98 | - * @method :post | ||
| 99 | - * @time :2023/12/20 18:52 | ||
| 100 | - */ | ||
| 101 | - public function getIdDetailsList($data){ | ||
| 102 | - $detailsList = []; | ||
| 103 | - foreach ($data as $v) { | ||
| 104 | - if (!empty($v['sub'])){ | ||
| 105 | - $v['sub'] = $this->getIdDetailsList($v['sub']); | ||
| 106 | - } | ||
| 107 | - $detailsList[$v['id']] = $v; | ||
| 108 | - } | ||
| 109 | - return $this->success($detailsList); | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - | ||
| 113 | - /** | ||
| 114 | * @remark :根据固定的数组排序 | 53 | * @remark :根据固定的数组排序 |
| 115 | * @name :findDetailsInList | 54 | * @name :findDetailsInList |
| 116 | * @author :lyh | 55 | * @author :lyh |
| 117 | * @method :post | 56 | * @method :post |
| 118 | * @time :2023/12/18 14:54 | 57 | * @time :2023/12/18 14:54 |
| 119 | */ | 58 | */ |
| 120 | - public function findDetailsList($sort_list,$detailsList) { | 59 | + public function findDetailsList($data, $detailsList) { |
| 121 | $result = []; | 60 | $result = []; |
| 122 | - foreach ($sort_list as $item) { | ||
| 123 | - $items = $item = (array)$item; | 61 | + foreach ($data as $item) { |
| 62 | + $items = (array)$item; | ||
| 124 | $id = $item['id']; | 63 | $id = $item['id']; |
| 125 | // 在给定的详情列表中查找匹配的id | 64 | // 在给定的详情列表中查找匹配的id |
| 126 | $matchingDetail = array_filter($detailsList, function ($detail) use ($id) { | 65 | $matchingDetail = array_filter($detailsList, function ($detail) use ($id) { |
-
请 注册 或 登录 后发表评论