From 58aadbc1f5f7d369ccbd16b6b934e113391c0c16 Mon Sep 17 00:00:00 2001 From: mzl Date: Tue, 22 Jul 2025 10:41:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=8F=9C=E5=8D=95=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/PermLogic.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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) {