diff --git a/app/common/logic/PermLogic.php b/app/common/logic/PermLogic.php index 275912b..b1ea2f3 100644 --- a/app/common/logic/PermLogic.php +++ b/app/common/logic/PermLogic.php @@ -52,7 +52,6 @@ class PermLogic return $all->unique('id')->values()->sortBy('sort'); } - /** * 构建目录/菜单树,节点包含权限与打开方式,拼接完整路径,并对子级菜单 component 处理 * @@ -66,13 +65,13 @@ class PermLogic $tree = []; foreach ($resources as $node) { - if ($node->parent_id !== $parentId) { + // 只处理目录和菜单,不把 permission 当作菜单节点 + if ($node->parent_id !== $parentId || $node->type === 'permission') { continue; } // —— 拼接当前节点的完整路径 —— $currentPath = rtrim($parentPath, '/'); - if (!empty($node->url)) { $urlSegment = ltrim($node->url, '/'); $currentPath = $currentPath === '' @@ -81,10 +80,8 @@ class PermLogic } // —— 递归构建子节点 —— - $children = []; - if (in_array($node->type, ['directory', 'menu'])) { - $children = $this->buildTree($resources, $node->id, $currentPath); - } + // 这里只会继续收目录和菜单,permission 永远不会进入此方法 + $children = $this->buildTree($resources, $node->id, $currentPath); // —— 本级权限列表 —— $authList = $resources @@ -98,10 +95,7 @@ class PermLogic ->all(); // —— 判断是否有子目录或子菜单 —— - $hasChildrenMenu = $resources - ->where('parent_id', $node->id) - ->whereIn('type', ['directory', 'menu']) - ->isNotEmpty(); + $hasChildrenMenu = ! empty($children); // —— 计算 component 字段 —— if ($hasChildrenMenu) {