修复若干bug

This commit is contained in:
2026-03-10 22:24:06 +08:00
parent 7cdb591f69
commit 98156991c1
16 changed files with 1021 additions and 892 deletions
+39 -1
View File
@@ -100,10 +100,13 @@ class MenuController extends BaseController
]);
}
// 获取有权限的菜单及其所有父级菜单
$allMenuIds = $this->getMenuIdsWithParents($menuIds);
// 获取有权限的菜单
$menus = SystemMenu::where('delete_time', null)
->where('status', 1)
->whereIn('id', $menuIds)
->whereIn('id', $allMenuIds)
->field('id,pid,title,path,component_path,icon,sort')
->order('sort', 'asc')
->select();
@@ -489,6 +492,41 @@ class MenuController extends BaseController
}
}
/**
* 获取菜单ID及其所有父级菜单ID
* @param array $menuIds 菜单ID数组
* @return array 包含所有父级菜单的ID数组
*/
private function getMenuIdsWithParents(array $menuIds): array
{
if (empty($menuIds)) {
return [];
}
$allIds = $menuIds;
$toCheck = $menuIds;
while (!empty($toCheck)) {
// 查询这些菜单的父级
$parents = SystemMenu::whereIn('id', $toCheck)
->where('delete_time', null)
->column('pid');
// 过滤掉已经存在的和为0的父ID
$newParents = [];
foreach ($parents as $pid) {
if ($pid > 0 && !in_array($pid, $allIds)) {
$newParents[] = $pid;
$allIds[] = $pid;
}
}
$toCheck = $newParents;
}
return $allIds;
}
/**
* 构建菜单树形结构
* @param array $menus 菜单列表