调整菜单结果展示

This commit is contained in:
mzl
2025-07-22 10:41:38 +08:00
parent 77a7337cf0
commit 58aadbc1f5
+5 -11
View File
@@ -52,7 +52,6 @@ class PermLogic
return $all->unique('id')->values()->sortBy('sort'); return $all->unique('id')->values()->sortBy('sort');
} }
/** /**
* 构建目录/菜单树,节点包含权限与打开方式,拼接完整路径,并对子级菜单 component 处理 * 构建目录/菜单树,节点包含权限与打开方式,拼接完整路径,并对子级菜单 component 处理
* *
@@ -66,13 +65,13 @@ class PermLogic
$tree = []; $tree = [];
foreach ($resources as $node) { foreach ($resources as $node) {
if ($node->parent_id !== $parentId) { // 只处理目录和菜单,不把 permission 当作菜单节点
if ($node->parent_id !== $parentId || $node->type === 'permission') {
continue; continue;
} }
// —— 拼接当前节点的完整路径 —— // —— 拼接当前节点的完整路径 ——
$currentPath = rtrim($parentPath, '/'); $currentPath = rtrim($parentPath, '/');
if (!empty($node->url)) { if (!empty($node->url)) {
$urlSegment = ltrim($node->url, '/'); $urlSegment = ltrim($node->url, '/');
$currentPath = $currentPath === '' $currentPath = $currentPath === ''
@@ -81,10 +80,8 @@ class PermLogic
} }
// —— 递归构建子节点 —— // —— 递归构建子节点 ——
$children = []; // 这里只会继续收目录和菜单,permission 永远不会进入此方法
if (in_array($node->type, ['directory', 'menu'])) { $children = $this->buildTree($resources, $node->id, $currentPath);
$children = $this->buildTree($resources, $node->id, $currentPath);
}
// —— 本级权限列表 —— // —— 本级权限列表 ——
$authList = $resources $authList = $resources
@@ -98,10 +95,7 @@ class PermLogic
->all(); ->all();
// —— 判断是否有子目录或子菜单 —— // —— 判断是否有子目录或子菜单 ——
$hasChildrenMenu = $resources $hasChildrenMenu = ! empty($children);
->where('parent_id', $node->id)
->whereIn('type', ['directory', 'menu'])
->isNotEmpty();
// —— 计算 component 字段 —— // —— 计算 component 字段 ——
if ($hasChildrenMenu) { if ($hasChildrenMenu) {