Skip to content

Commit 6368462

Browse files
author
zhaoxiang
committed
modified 优化细节
1 parent 15bc611 commit 6368462

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

application/admin/controller/Auth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ private function buildList($list, $rules) {
241241
foreach ($list as $key => $value) {
242242
$newList[$key]['title'] = $value['name'];
243243
$newList[$key]['key'] = $value['url'];
244-
if (isset($value['_child'])) {
244+
if (isset($value['children'])) {
245245
$newList[$key]['expand'] = true;
246-
$newList[$key]['children'] = $this->buildList($value['_child'], $rules);
246+
$newList[$key]['children'] = $this->buildList($value['children'], $rules);
247247
} else {
248248
if (in_array($value['url'], $rules)) {
249249
$newList[$key]['checked'] = true;

application/admin/controller/Menu.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ class Menu extends Base {
2020
* @author zhaoxiang <zhaoxiang051405@gmail.com>
2121
*/
2222
public function index() {
23-
$list = (new AdminMenu)->order('sort', 'ASC')->select();
24-
$list = Tools::buildArrFromObj($list);
25-
$list = Tools::formatTree(Tools::listToTree($list));
26-
23+
$origin = (new AdminMenu)->order('sort', 'ASC')->select();
24+
$origin = Tools::buildArrFromObj($origin);
25+
$list = Tools::listToTree($origin);
26+
$choose = Tools::formatTree($list);
2727
return $this->buildSuccess([
28-
'list' => $list
28+
'list' => $list,
29+
'choose' => $choose
2930
]);
3031
}
3132

application/util/Tools.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static function buildArrByNewKey($array, $keyName = 'id') {
121121
* @param string $root
122122
* @return array
123123
*/
124-
public static function listToTree($list, $pk='id', $pid = 'fid', $child = '_child', $root = '0') {
124+
public static function listToTree($list, $pk='id', $pid = 'fid', $child = 'children', $root = '0') {
125125
$tree = array();
126126
if(is_array($list)) {
127127
$refer = array();
@@ -153,11 +153,11 @@ public static function formatTree($list, $lv = 0, $title = 'name'){
153153
$val['lv'] = $lv;
154154
$val['namePrefix'] = $lv == 0 ? '' : $title_prefix;
155155
$val['showName'] = $lv == 0 ? $val[$title] : $title_prefix.$val[$title];
156-
if(!array_key_exists('_child', $val)){
156+
if(!array_key_exists('children', $val)){
157157
array_push($formatTree, $val);
158158
}else{
159-
$child = $val['_child'];
160-
unset($val['_child']);
159+
$child = $val['children'];
160+
unset($val['children']);
161161
array_push($formatTree, $val);
162162
$middle = self::formatTree($child, $lv+1, $title); //进行下一层递归
163163
$formatTree = array_merge($formatTree, $middle);

0 commit comments

Comments
 (0)