From ec2c6eff6f19c49722897330e5268fa9ed679031 Mon Sep 17 00:00:00 2001 From: Netfan Date: Sat, 28 Dec 2024 16:16:48 +0800 Subject: [PATCH] feat: header menu align support (#5256) * feat: header menu align support * fix: typo --- packages/@core/base/typings/src/app.d.ts | 2 ++ .../__snapshots__/config.test.ts.snap | 1 + packages/@core/preferences/src/config.ts | 1 + packages/@core/preferences/src/types.ts | 3 ++ .../ui-kit/menu-ui/src/components/menu.vue | 5 +++ .../layouts/src/basic/header/header.vue | 18 ++++++++++- .../preferences/blocks/layout/header.vue | 31 ++++++++++++++++++- .../preferences/preferences-drawer.vue | 4 +++ .../locales/src/langs/en-US/preferences.json | 6 +++- .../locales/src/langs/zh-CN/preferences.json | 6 +++- 10 files changed, 73 insertions(+), 4 deletions(-) diff --git a/packages/@core/base/typings/src/app.d.ts b/packages/@core/base/typings/src/app.d.ts index e49a8657d93..f783c8b5690 100644 --- a/packages/@core/base/typings/src/app.d.ts +++ b/packages/@core/base/typings/src/app.d.ts @@ -38,6 +38,7 @@ type BuiltinThemeType = type ContentCompactType = 'compact' | 'wide'; type LayoutHeaderModeType = 'auto' | 'auto-scroll' | 'fixed' | 'static'; +type LayoutHeaderMenuAlignType = 'center' | 'end' | 'start'; /** * 登录过期模式 @@ -95,6 +96,7 @@ export type { BreadcrumbStyleType, BuiltinThemeType, ContentCompactType, + LayoutHeaderMenuAlignType, LayoutHeaderModeType, LayoutType, LoginExpiredModeType, diff --git a/packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap b/packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap index f05a96dc3c9..87f03de69bb 100644 --- a/packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap +++ b/packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap @@ -46,6 +46,7 @@ exports[`defaultPreferences immutability test > should not modify the config obj "header": { "enable": true, "hidden": false, + "menuAlign": "start", "mode": "fixed", }, "logo": { diff --git a/packages/@core/preferences/src/config.ts b/packages/@core/preferences/src/config.ts index c4dce039f54..a5912a06722 100644 --- a/packages/@core/preferences/src/config.ts +++ b/packages/@core/preferences/src/config.ts @@ -46,6 +46,7 @@ const defaultPreferences: Preferences = { header: { enable: true, hidden: false, + menuAlign: 'start', mode: 'fixed', }, logo: { diff --git a/packages/@core/preferences/src/types.ts b/packages/@core/preferences/src/types.ts index 59dce2e2164..f8b35242c6a 100644 --- a/packages/@core/preferences/src/types.ts +++ b/packages/@core/preferences/src/types.ts @@ -5,6 +5,7 @@ import type { BuiltinThemeType, ContentCompactType, DeepPartial, + LayoutHeaderMenuAlignType, LayoutHeaderModeType, LayoutType, LoginExpiredModeType, @@ -104,6 +105,8 @@ interface HeaderPreferences { enable: boolean; /** 顶栏是否隐藏,css-隐藏 */ hidden: boolean; + /** 顶栏菜单位置 */ + menuAlign: LayoutHeaderMenuAlignType; /** header显示模式 */ mode: LayoutHeaderModeType; } diff --git a/packages/@core/ui-kit/menu-ui/src/components/menu.vue b/packages/@core/ui-kit/menu-ui/src/components/menu.vue index ea7a14c05ee..9433d54836d 100644 --- a/packages/@core/ui-kit/menu-ui/src/components/menu.vue +++ b/packages/@core/ui-kit/menu-ui/src/components/menu.vue @@ -332,6 +332,7 @@ function removeMenuItem(item: MenuItemRegistered) { is(theme, true), is('rounded', rounded), is('collapse', collapse), + is('menu-align', mode === 'horizontal'), ]" :style="menuStyle" role="menu" @@ -423,6 +424,10 @@ $namespace: vben; opacity: 1; } +.is-menu-align { + justify-content: var(--menu-align, start); +} + .#{$namespace}-menu__popup-container, .#{$namespace}-menu { --menu-title-width: 140px; diff --git a/packages/effects/layouts/src/basic/header/header.vue b/packages/effects/layouts/src/basic/header/header.vue index 546342bf9b6..c271f834ab9 100644 --- a/packages/effects/layouts/src/basic/header/header.vue +++ b/packages/effects/layouts/src/basic/header/header.vue @@ -133,7 +133,10 @@ function clearPreferencesAndLogout() { > -
+
@@ -166,3 +169,16 @@ function clearPreferencesAndLogout() {
+ diff --git a/packages/effects/layouts/src/widgets/preferences/blocks/layout/header.vue b/packages/effects/layouts/src/widgets/preferences/blocks/layout/header.vue index cdb236cf3d5..ee04ee28d73 100644 --- a/packages/effects/layouts/src/widgets/preferences/blocks/layout/header.vue +++ b/packages/effects/layouts/src/widgets/preferences/blocks/layout/header.vue @@ -1,15 +1,22 @@ diff --git a/packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue b/packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue index 4ae09130b70..67729fd3602 100644 --- a/packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue +++ b/packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue @@ -4,6 +4,7 @@ import type { BreadcrumbStyleType, BuiltinThemeType, ContentCompactType, + LayoutHeaderMenuAlignType, LayoutHeaderModeType, LayoutType, NavigationStyleType, @@ -94,6 +95,8 @@ const SidebarExpandOnHover = defineModel('sidebarExpandOnHover'); const headerEnable = defineModel('headerEnable'); const headerMode = defineModel('headerMode'); +const headerMenuAlign = + defineModel('headerMenuAlign'); const breadcrumbEnable = defineModel('breadcrumbEnable'); const breadcrumbShowIcon = defineModel('breadcrumbShowIcon'); @@ -317,6 +320,7 @@ async function handleReset() {
diff --git a/packages/locales/src/langs/en-US/preferences.json b/packages/locales/src/langs/en-US/preferences.json index 5bb58176973..57b535c4946 100644 --- a/packages/locales/src/langs/en-US/preferences.json +++ b/packages/locales/src/langs/en-US/preferences.json @@ -138,7 +138,11 @@ "modeStatic": "Static", "modeFixed": "Fixed", "modeAuto": "Auto hide & Show", - "modeAutoScroll": "Scroll to Hide & Show" + "modeAutoScroll": "Scroll to Hide & Show", + "menuAlign": "Menu Align", + "menuAlignStart": "Start", + "menuAlignEnd": "End", + "menuAlignCenter": "Center" }, "footer": { "title": "Footer", diff --git a/packages/locales/src/langs/zh-CN/preferences.json b/packages/locales/src/langs/zh-CN/preferences.json index 5c3c2283fa3..4963b6c7200 100644 --- a/packages/locales/src/langs/zh-CN/preferences.json +++ b/packages/locales/src/langs/zh-CN/preferences.json @@ -138,7 +138,11 @@ "modeFixed": "固定", "modeAuto": "自动隐藏和显示", "modeAutoScroll": "滚动隐藏和显示", - "visible": "显示顶栏" + "visible": "显示顶栏", + "menuAlign": "菜单位置", + "menuAlignStart": "左侧", + "menuAlignEnd": "右侧", + "menuAlignCenter": "居中" }, "footer": { "title": "底栏",