From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/layout/components/Menu/src/helper.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/src/layout/components/Menu/src/helper.ts b/src/layout/components/Menu/src/helper.ts
new file mode 100644
index 0000000..c26f5f4
--- /dev/null
+++ b/src/layout/components/Menu/src/helper.ts
@@ -0,0 +1,54 @@
+import type { RouteMeta } from 'vue-router'
+import { findPath } from '@/utils/tree'
+
+type OnlyOneChildType = AppRouteRecordRaw & { noShowingChildren?: boolean }
+
+interface HasOneShowingChild {
+ oneShowingChild?: boolean
+ onlyOneChild?: OnlyOneChildType
+}
+
+export const getAllParentPath = <T = Recordable>(treeData: T[], path: string) => {
+ const menuList = findPath(treeData, (n) => n.path === path) as AppRouteRecordRaw[]
+ return (menuList || []).map((item) => item.path)
+}
+
+export const hasOneShowingChild = (
+ children: AppRouteRecordRaw[] = [],
+ parent: AppRouteRecordRaw
+): HasOneShowingChild => {
+ const onlyOneChild = ref<OnlyOneChildType>()
+
+ const showingChildren = children.filter((v) => {
+ const meta = (v.meta ?? {}) as RouteMeta
+ if (meta.hidden) {
+ return false
+ } else {
+ // Temp set(will be used if only has one showing child)
+ onlyOneChild.value = v
+ return true
+ }
+ })
+
+ // When there is only one child router, the child router is displayed by default
+ if (showingChildren.length === 1) {
+ return {
+ oneShowingChild: true,
+ onlyOneChild: unref(onlyOneChild)
+ }
+ }
+
+ // Show parent if there are no child router to display
+ if (!showingChildren.length) {
+ onlyOneChild.value = { ...parent, path: '', noShowingChildren: true }
+ return {
+ oneShowingChild: true,
+ onlyOneChild: unref(onlyOneChild)
+ }
+ }
+
+ return {
+ oneShowingChild: false,
+ onlyOneChild: unref(onlyOneChild)
+ }
+}
--
Gitblit v1.8.0