From c7b880280bde2f93fdd2788e4ee395bb298704cf Mon Sep 17 00:00:00 2001 From: wang <1509326266@qq.com> Date: Sun, 8 Sep 2024 14:20:58 +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 | 73 +++++---- src/layouts/context/index.ts | 60 +++++-- 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.vue | 35 ++++ .../global-menu/modules/horizontal-menu.vue | 39 +++++ .../modules/horizontal-mix-menu.vue | 64 ++++++++ .../modules/reversed-horizontal-mix-menu.vue | 67 ++++++++ .../global-menu/modules/vertical-menu.vue | 47 ++++++ .../global-menu/modules/vertical-mix-menu.vue | 115 ++++++++++++++ .../modules/global-menu/vertical-mix-menu.vue | 72 --------- src/layouts/modules/global-sider/index.vue | 13 +- .../theme-drawer/modules/layout-mode.vue | 8 + src/locales/langs/en-us.ts | 3 +- src/locales/langs/zh-cn.ts | 3 +- src/theme/settings.ts | 3 +- src/typings/app.d.ts | 8 +- 21 files changed, 530 insertions(+), 339 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.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 645b0a5..4a43342 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'); } @@ -99,6 +112,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..7debe5d 100644 --- a/src/layouts/base-layout/index.vue +++ b/src/layouts/base-layout/index.vue @@ -1,5 +1,5 @@ + + +