From 7256ad4ee3c51c9e78e5efea1645e3ecf4964890 Mon Sep 17 00:00:00 2001 From: Soybean Date: Fri, 23 Feb 2024 21:51:20 +0800 Subject: [PATCH] feat(projects): support directory menu hide all child menus. fixed #325 --- src/locales/langs/en-us.ts | 4 ++ src/locales/langs/zh-cn.ts | 4 ++ src/router/elegant/imports.ts | 3 ++ src/router/elegant/routes.ts | 44 +++++++++++++++++++ src/router/elegant/transform.ts | 4 ++ src/store/modules/route/shared.ts | 2 +- src/typings/elegant-router.d.ts | 7 +++ src/typings/router.d.ts | 2 +- src/views/function/hide-child/one/index.vue | 7 +++ src/views/function/hide-child/three/index.vue | 7 +++ src/views/function/hide-child/two/index.vue | 7 +++ 11 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/views/function/hide-child/one/index.vue create mode 100644 src/views/function/hide-child/three/index.vue create mode 100644 src/views/function/hide-child/two/index.vue diff --git a/src/locales/langs/en-us.ts b/src/locales/langs/en-us.ts index 866bd1d6..7f6afc3c 100644 --- a/src/locales/langs/en-us.ts +++ b/src/locales/langs/en-us.ts @@ -129,6 +129,10 @@ const local: App.I18n.Schema = { function: 'System Function', function_tab: 'Tab', 'function_multi-tab': 'Multi Tab', + 'function_hide-child': 'Hide Child', + 'function_hide-child_one': 'Hide Child', + 'function_hide-child_two': 'Two', + 'function_hide-child_three': 'Three', manage: 'System Manage', manage_user: 'User Manage', 'manage_user-detail': 'User Detail', diff --git a/src/locales/langs/zh-cn.ts b/src/locales/langs/zh-cn.ts index 36ebb58a..9b670d04 100644 --- a/src/locales/langs/zh-cn.ts +++ b/src/locales/langs/zh-cn.ts @@ -129,6 +129,10 @@ const local: App.I18n.Schema = { function: '系统功能', function_tab: '标签页', 'function_multi-tab': '多标签页', + 'function_hide-child': '隐藏子菜单', + 'function_hide-child_one': '隐藏子菜单', + 'function_hide-child_two': '菜单二', + 'function_hide-child_three': '菜单三', manage: '系统管理', manage_user: '用户管理', 'manage_user-detail': '用户详情', diff --git a/src/router/elegant/imports.ts b/src/router/elegant/imports.ts index eee3a7ab..3ae5976b 100644 --- a/src/router/elegant/imports.ts +++ b/src/router/elegant/imports.ts @@ -20,6 +20,9 @@ export const views: Record Promise import("@/views/_builtin/500/index.vue"), login: () => import("@/views/_builtin/login/index.vue"), about: () => import("@/views/about/index.vue"), + "function_hide-child_one": () => import("@/views/function/hide-child/one/index.vue"), + "function_hide-child_three": () => import("@/views/function/hide-child/three/index.vue"), + "function_hide-child_two": () => import("@/views/function/hide-child/two/index.vue"), "function_multi-tab": () => import("@/views/function/multi-tab/index.vue"), function_tab: () => import("@/views/function/tab/index.vue"), home: () => import("@/views/home/index.vue"), diff --git a/src/router/elegant/routes.ts b/src/router/elegant/routes.ts index 8c6e5067..5e6d8f24 100644 --- a/src/router/elegant/routes.ts +++ b/src/router/elegant/routes.ts @@ -58,6 +58,50 @@ export const generatedRoutes: GeneratedRoute[] = [ order: 6 }, children: [ + { + name: 'function_hide-child', + path: '/function/hide-child', + meta: { + title: 'function_hide-child', + i18nKey: 'route.function_hide-child' + }, + redirect: '/function/hide-child/one', + children: [ + { + name: 'function_hide-child_one', + path: '/function/hide-child/one', + component: 'view.function_hide-child_one', + meta: { + title: 'function_hide-child_one', + i18nKey: 'route.function_hide-child_one', + hideInMenu: true, + activeMenu: 'function_hide-child' + } + }, + { + name: 'function_hide-child_three', + path: '/function/hide-child/three', + component: 'view.function_hide-child_three', + meta: { + title: 'function_hide-child_three', + i18nKey: 'route.function_hide-child_three', + hideInMenu: true, + activeMenu: 'function_hide-child' + } + }, + { + name: 'function_hide-child_two', + path: '/function/hide-child/two', + component: 'view.function_hide-child_two', + meta: { + title: 'function_hide-child_two', + i18nKey: 'route.function_hide-child_two', + hideInMenu: true, + activeMenu: 'function_hide-child' + } + } + ] + }, { name: 'function_multi-tab', path: '/function/multi-tab', diff --git a/src/router/elegant/transform.ts b/src/router/elegant/transform.ts index 56189ef8..40c1f2ae 100644 --- a/src/router/elegant/transform.ts +++ b/src/router/elegant/transform.ts @@ -152,6 +152,10 @@ const routeMap: RouteMap = { "500": "/500", "about": "/about", "function": "/function", + "function_hide-child": "/function/hide-child", + "function_hide-child_one": "/function/hide-child/one", + "function_hide-child_three": "/function/hide-child/three", + "function_hide-child_two": "/function/hide-child/two", "function_multi-tab": "/function/multi-tab", "function_tab": "/function/tab", "home": "/home", diff --git a/src/store/modules/route/shared.ts b/src/store/modules/route/shared.ts index 22b4945e..c7cfb821 100644 --- a/src/store/modules/route/shared.ts +++ b/src/store/modules/route/shared.ts @@ -85,7 +85,7 @@ export function getGlobalMenusByAuthRoutes(routes: ElegantConstRoute[]) { if (!route.meta?.hideInMenu) { const menu = getGlobalMenuByBaseRoute(route); - if (route.children?.length) { + if (route.children?.some(child => !child.meta?.hideInMenu)) { menu.children = getGlobalMenusByAuthRoutes(route.children); } diff --git a/src/typings/elegant-router.d.ts b/src/typings/elegant-router.d.ts index 7e4a1598..b6f5ab67 100644 --- a/src/typings/elegant-router.d.ts +++ b/src/typings/elegant-router.d.ts @@ -26,6 +26,10 @@ declare module "@elegant-router/types" { "500": "/500"; "about": "/about"; "function": "/function"; + "function_hide-child": "/function/hide-child"; + "function_hide-child_one": "/function/hide-child/one"; + "function_hide-child_three": "/function/hide-child/three"; + "function_hide-child_two": "/function/hide-child/two"; "function_multi-tab": "/function/multi-tab"; "function_tab": "/function/tab"; "home": "/home"; @@ -109,6 +113,9 @@ declare module "@elegant-router/types" { | "500" | "login" | "about" + | "function_hide-child_one" + | "function_hide-child_three" + | "function_hide-child_two" | "function_multi-tab" | "function_tab" | "home" diff --git a/src/typings/router.d.ts b/src/typings/router.d.ts index 67e45e5e..adcb5400 100644 --- a/src/typings/router.d.ts +++ b/src/typings/router.d.ts @@ -54,7 +54,7 @@ declare module 'vue-router' { * @example * the route is "user_detail", if it is set to "user_list", the menu "user_list" will be activated */ - activeMenu?: import('@elegant-router/types').LastLevelRouteKey; + activeMenu?: import('@elegant-router/types').RouteKey; /** By default, the same route path will use one tab, if set to true, it will use multiple tabs */ multiTab?: boolean; /** If set, the route will be fixed in tabs, and the value is the order of fixed tabs */ diff --git a/src/views/function/hide-child/one/index.vue b/src/views/function/hide-child/one/index.vue new file mode 100644 index 00000000..c832430d --- /dev/null +++ b/src/views/function/hide-child/one/index.vue @@ -0,0 +1,7 @@ + + + + + diff --git a/src/views/function/hide-child/three/index.vue b/src/views/function/hide-child/three/index.vue new file mode 100644 index 00000000..f9b42b4e --- /dev/null +++ b/src/views/function/hide-child/three/index.vue @@ -0,0 +1,7 @@ + + + + + diff --git a/src/views/function/hide-child/two/index.vue b/src/views/function/hide-child/two/index.vue new file mode 100644 index 00000000..2fa26a86 --- /dev/null +++ b/src/views/function/hide-child/two/index.vue @@ -0,0 +1,7 @@ + + + + +