From 881c737839456f2cd814eb2d0dc85ffa9691ceda Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Mon, 27 Feb 2023 22:19:38 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E5=AE=8C=E5=96=84=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E8=BD=AC=E6=8D=A2=E8=8F=9C=E5=8D=95=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: e8e8b67b6c88a1a030fa7d100c0d0fc79e31afbd --- src/layout/components/Sidebar/SidebarItem.vue | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/layout/components/Sidebar/SidebarItem.vue b/src/layout/components/Sidebar/SidebarItem.vue index 98665a22..7f5abc1a 100644 --- a/src/layout/components/Sidebar/SidebarItem.vue +++ b/src/layout/components/Sidebar/SidebarItem.vue @@ -24,36 +24,34 @@ const props = defineProps({ } }); -const onlyOneChild = ref(); // 临时变量,记录仅显示的一个子路由的信息 +const onlyOneChild = ref(); // 临时变量,唯一子路由 /** - * 判断当前路由是否只有一个子路由需要显示 + * 判断当前路由是否只有一个子路由 * - * 1:如果只有一个子路由,当前路由直接显示子路由 - * 2:如果无子路由,显示当前路由 + * 1:如果只有一个子路由: 返回 true + * 2:如果无子路由 :返回 true * - * @param children 子路由数组 + * @param children 子路由数组 * @param parent 当前路由 */ function hasOneShowingChild(children = [], parent: any) { // 需要显示的子路由数组 const showingChildren = children.filter((item: any) => { if (item.meta?.hidden) { - // 过滤不显示的子路由 - return false; + return false; // 过滤不显示的子路由 } else { - // 仅有一个子路由生效,其他情况设置无效 - onlyOneChild.value = item; + onlyOneChild.value = item; // 唯一子路由赋值(多个子路由情况 onlyOneChild 变量是用不上的) return true; } }); - // 1:如果只有一个子路由,当前路由直接显示子路由 + // 1:如果只有一个子路由, 返回 true if (showingChildren.length === 1) { return true; } - // 2:如果无子路由,显示当前路由 + // 2:如果无子路由, 复制当前路由信息作为其子路由,满足只拥有一个子路由的条件,所以返回 true if (showingChildren.length === 0) { onlyOneChild.value = { ...parent, path: '', noShowingChildren: true }; return true; @@ -74,13 +72,13 @@ function resolvePath(routePath: string) { return props.basePath; } // 完整路径 = 父级路径(/level/level_3) + 路由路径 - const fullPath = path.resolve(props.basePath, routePath); + const fullPath = path.resolve(props.basePath, routePath); // 相对路径 → 绝对路径 return fullPath; }