Skip to content

Commit

Permalink
modified 优化细节
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoxiang committed Feb 24, 2020
1 parent 15bc611 commit 6368462
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions application/admin/controller/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ private function buildList($list, $rules) {
foreach ($list as $key => $value) {
$newList[$key]['title'] = $value['name'];
$newList[$key]['key'] = $value['url'];
if (isset($value['_child'])) {
if (isset($value['children'])) {
$newList[$key]['expand'] = true;
$newList[$key]['children'] = $this->buildList($value['_child'], $rules);
$newList[$key]['children'] = $this->buildList($value['children'], $rules);
} else {
if (in_array($value['url'], $rules)) {
$newList[$key]['checked'] = true;
Expand Down
11 changes: 6 additions & 5 deletions application/admin/controller/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ class Menu extends Base {
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public function index() {
$list = (new AdminMenu)->order('sort', 'ASC')->select();
$list = Tools::buildArrFromObj($list);
$list = Tools::formatTree(Tools::listToTree($list));

$origin = (new AdminMenu)->order('sort', 'ASC')->select();
$origin = Tools::buildArrFromObj($origin);
$list = Tools::listToTree($origin);
$choose = Tools::formatTree($list);
return $this->buildSuccess([
'list' => $list
'list' => $list,
'choose' => $choose
]);
}

Expand Down
8 changes: 4 additions & 4 deletions application/util/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static function buildArrByNewKey($array, $keyName = 'id') {
* @param string $root
* @return array
*/
public static function listToTree($list, $pk='id', $pid = 'fid', $child = '_child', $root = '0') {
public static function listToTree($list, $pk='id', $pid = 'fid', $child = 'children', $root = '0') {
$tree = array();
if(is_array($list)) {
$refer = array();
Expand Down Expand Up @@ -153,11 +153,11 @@ public static function formatTree($list, $lv = 0, $title = 'name'){
$val['lv'] = $lv;
$val['namePrefix'] = $lv == 0 ? '' : $title_prefix;
$val['showName'] = $lv == 0 ? $val[$title] : $title_prefix.$val[$title];
if(!array_key_exists('_child', $val)){
if(!array_key_exists('children', $val)){
array_push($formatTree, $val);
}else{
$child = $val['_child'];
unset($val['_child']);
$child = $val['children'];
unset($val['children']);
array_push($formatTree, $val);
$middle = self::formatTree($child, $lv+1, $title); //进行下一层递归
$formatTree = array_merge($formatTree, $middle);
Expand Down

0 comments on commit 6368462

Please sign in to comment.