mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 优化细节
This commit is contained in:
parent
15bc6119f6
commit
6368462a18
@ -241,9 +241,9 @@ class Auth extends Base {
|
||||
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;
|
||||
|
@ -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
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ class Tools {
|
||||
* @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();
|
||||
@ -153,11 +153,11 @@ class Tools {
|
||||
$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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user