From f66f80fc56de84bc846a068736d11849bd210163 Mon Sep 17 00:00:00 2001 From: oldR Date: Sun, 25 May 2025 10:42:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E6=90=9C=E7=B4=A2=E9=97=AE=E9=A2=98=20(#67)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/components/HeaderRightBar/Search.vue | 13 ++++++------- src/layout/components/Menu/MenuItem.vue | 14 +++++++------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/layout/components/HeaderRightBar/Search.vue b/src/layout/components/HeaderRightBar/Search.vue index 4a3f315..54ba428 100644 --- a/src/layout/components/HeaderRightBar/Search.vue +++ b/src/layout/components/HeaderRightBar/Search.vue @@ -107,15 +107,14 @@ const searchRoutes = (keyword: string) => { const result: SearchResult[] = [] const loop = (routes: RouteRecordRaw[]) => { routes.forEach((route) => { + if (route.meta?.title?.toLowerCase().includes(keyword.toLowerCase()) && !route.meta?.hidden) { + result.push({ + title: route.meta.title, + path: route.path, + }) + } if (route.children && route.children.length > 0) { loop(route.children) - } else { - if (route.meta?.title?.toLowerCase().includes(keyword.toLowerCase())) { - result.push({ - title: route.meta.title, - path: route.path, - }) - } } }) } diff --git a/src/layout/components/Menu/MenuItem.vue b/src/layout/components/Menu/MenuItem.vue index 918afee..2404830 100644 --- a/src/layout/components/Menu/MenuItem.vue +++ b/src/layout/components/Menu/MenuItem.vue @@ -41,26 +41,26 @@ interface Props { } // 如果hidden: false那么代表这个路由项显示在左侧菜单栏中 -// 如果props.item的子项chidren只有一个hidden: false的子元素, 那么onlyOneChild就表示这个子元素 +// 如果props.item的子项children只有一个hidden: false的子元素, 那么onlyOneChild就表示这个子元素 const onlyOneChild = ref(null) const isOneShowingChild = ref(false) const handleFunction = () => { - const chidrens = props.item?.children?.length ? props.item.children : [] + const children = props.item?.children?.length ? props.item.children : [] // 判断是否只有一个显示的子项 - const showingChildrens = chidrens.filter((i) => i.meta?.hidden === false) - if (showingChildrens.length) { + const showingChildren = children.filter((i) => i.meta?.hidden === false) + if (showingChildren.length) { // 保存子项最后一个hidden: false的元素 - onlyOneChild.value = showingChildrens[showingChildrens.length - 1] + onlyOneChild.value = showingChildren[showingChildren.length - 1] } // 当只有一个要显示子路由时, 默认显示该子路由器 - if (showingChildrens.length === 1) { + if (showingChildren.length === 1) { isOneShowingChild.value = true } // 如果没有要显示的子路由, 则显示父路由 - if (showingChildrens.length === 0) { + if (showingChildren.length === 0) { onlyOneChild.value = { ...props.item, meta: { ...props.item.meta, noShowingChildren: true } } as any isOneShowingChild.value = true }