From 2244f0c798444d5a83bfa2d82276799bb70339d9 Mon Sep 17 00:00:00 2001 From: Soybean Date: Sun, 8 Sep 2024 17:34:14 +0800 Subject: [PATCH] refactor(projects)!: refactor global menu & support reversed-horizontal-mix-menu --- src/constants/app.ts | 4 + src/hooks/common/router.ts | 18 ++- src/layouts/base-layout/index.vue | 68 ++++---- src/layouts/context/index.ts | 54 +++++-- src/layouts/modules/global-header/index.vue | 23 +-- src/layouts/modules/global-menu/base-menu.vue | 149 ------------------ .../{ => components}/first-level-menu.vue | 37 +++-- .../global-menu/horizontal-mix-menu.vue | 28 ---- src/layouts/modules/global-menu/index.scss | 49 ++++++ src/layouts/modules/global-menu/index.vue | 53 +++++++ .../global-menu/modules/horizontal-menu.vue | 40 +++++ .../modules/horizontal-mix-menu.vue | 67 ++++++++ .../modules/reversed-horizontal-mix-menu.vue | 84 ++++++++++ .../global-menu/modules/vertical-menu.vue | 61 +++++++ .../global-menu/modules/vertical-mix-menu.vue | 127 +++++++++++++++ .../modules/global-menu/vertical-mix-menu.vue | 72 --------- src/layouts/modules/global-sider/index.vue | 13 +- .../theme-drawer/modules/layout-mode.vue | 14 ++ src/locales/langs/en-us.ts | 3 +- src/locales/langs/zh-cn.ts | 3 +- src/router/elegant/transform.ts | 20 +-- src/store/modules/route/index.ts | 31 +--- src/store/modules/theme/index.ts | 12 +- src/theme/settings.ts | 3 +- src/typings/app.d.ts | 12 +- src/typings/elegant-router.d.ts | 4 +- src/typings/union-key.d.ts | 2 +- 27 files changed, 667 insertions(+), 384 deletions(-) delete mode 100644 src/layouts/modules/global-menu/base-menu.vue rename src/layouts/modules/global-menu/{ => components}/first-level-menu.vue (79%) delete mode 100644 src/layouts/modules/global-menu/horizontal-mix-menu.vue create mode 100644 src/layouts/modules/global-menu/index.scss create mode 100644 src/layouts/modules/global-menu/index.vue create mode 100644 src/layouts/modules/global-menu/modules/horizontal-menu.vue create mode 100644 src/layouts/modules/global-menu/modules/horizontal-mix-menu.vue create mode 100644 src/layouts/modules/global-menu/modules/reversed-horizontal-mix-menu.vue create mode 100644 src/layouts/modules/global-menu/modules/vertical-menu.vue create mode 100644 src/layouts/modules/global-menu/modules/vertical-mix-menu.vue delete mode 100644 src/layouts/modules/global-menu/vertical-mix-menu.vue diff --git a/src/constants/app.ts b/src/constants/app.ts index ca4f927..4948a15 100644 --- a/src/constants/app.ts +++ b/src/constants/app.ts @@ -1,5 +1,9 @@ import { transformRecordToOption } from '@/utils/common'; +export const GLOBAL_HEADER_MENU_ID = '__GLOBAL_HEADER_MENU__'; + +export const GLOBAL_SIDER_MENU_ID = '__GLOBAL_SIDER_MENU__'; + export const themeSchemaRecord: Record = { light: 'theme.themeSchema.light', dark: 'theme.themeSchema.dark', diff --git a/src/hooks/common/router.ts b/src/hooks/common/router.ts index 89374b7..f95a25a 100644 --- a/src/hooks/common/router.ts +++ b/src/hooks/common/router.ts @@ -30,17 +30,30 @@ export function useRouterPush(inSetup = true) { name: key }; - if (query) { + if (Object.keys(query || {}).length) { routeLocation.query = query; } - if (params) { + if (Object.keys(params || {}).length) { routeLocation.params = params; } return routerPush(routeLocation); } + function routerPushByKeyWithMetaQuery(key: RouteKey) { + const allRoutes = router.getRoutes(); + const meta = allRoutes.find(item => item.name === key)?.meta || null; + + const query: Record = {}; + + meta?.query?.forEach(item => { + query[item.key] = item.value; + }); + + return routerPushByKey(key, { query }); + } + async function toHome() { return routerPushByKey('root'); } @@ -95,6 +108,7 @@ export function useRouterPush(inSetup = true) { routerPush, routerBack, routerPushByKey, + routerPushByKeyWithMetaQuery, toLogin, toggleLoginModule, redirectFromLogin diff --git a/src/layouts/base-layout/index.vue b/src/layouts/base-layout/index.vue index 948638b..7d00da2 100644 --- a/src/layouts/base-layout/index.vue +++ b/src/layouts/base-layout/index.vue @@ -1,5 +1,5 @@