refactor: 修改用户菜单权限输出结构
This commit is contained in:
@@ -10,13 +10,16 @@ if (!function_exists('array_to_tree')) {
|
|||||||
* @param int $level 层级
|
* @param int $level 层级
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function array_to_tree(array $data, int $pid, string $with = 'pid', int $level = 1)
|
function array_to_tree(array $data, int $pid, string $with = 'pid', int|false $level = 1)
|
||||||
{
|
{
|
||||||
$ret = [];
|
$ret = [];
|
||||||
foreach ($data as $item) {
|
foreach ($data as $item) {
|
||||||
if ($item[$with] == $pid) {
|
if ($item[$with] == $pid) {
|
||||||
$item['level'] = $level;
|
if ($level !== false) {
|
||||||
$children = array_to_tree($data, $item['id'], $with, $level + 1);
|
$item['level'] = $level;
|
||||||
|
$level = $level + 1;
|
||||||
|
}
|
||||||
|
$children = array_to_tree($data, $item['id'], $with, $level);
|
||||||
if ($children) {
|
if ($children) {
|
||||||
$item['children'] = $children;
|
$item['children'] = $children;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,19 +58,25 @@ class User
|
|||||||
}
|
}
|
||||||
if (!empty($authoritys_map)) {
|
if (!empty($authoritys_map)) {
|
||||||
$menus->each(function($item) use($authoritys_map) {
|
$menus->each(function($item) use($authoritys_map) {
|
||||||
$item['hidden'] = !!$item['hidden'];
|
$meta = [
|
||||||
$item['actived'] = !!$item['actived'];
|
'title' => $item['title'],
|
||||||
$item['keep_alive'] = !!$item['keep_alive'];
|
'icon' => $item['icon'],
|
||||||
$item['permissions'] = [];
|
'isKeepAlive' => !!$item['keep_alive'],
|
||||||
|
'actived' => !!$item['actived'],
|
||||||
|
'permissions' => []
|
||||||
|
];
|
||||||
|
unset($item['title'], $item['icon'], $item['keep_alive'], $item['actived']);
|
||||||
if (isset($authoritys_map[$item['id']])) {
|
if (isset($authoritys_map[$item['id']])) {
|
||||||
$item['permissions'] = $authoritys_map[$item['id']];
|
$meta['permissions'] = $authoritys_map[$item['id']];
|
||||||
}
|
}
|
||||||
|
$item['hidden'] = !!$item['hidden'];
|
||||||
|
$item['meta'] = $meta;
|
||||||
return $item;
|
return $item;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return success('获取成功', array_to_tree($menus->toArray(), 0));
|
return success('获取成功', array_to_tree($menus->toArray(), 0, 'pid', false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户分页数据
|
// 用户分页数据
|
||||||
|
|||||||
Reference in New Issue
Block a user