Commit 25d43a5f7c9182f2ca620f1daf0d5f47d2e4fb2d
1 parent
36734100
fix: fix topMenu align not work
Showing
3 changed files
with
20 additions
and
18 deletions
src/design/global.less
src/layouts/default/header/LayoutHeader.tsx
1 | 1 | import './index.less'; |
2 | 2 | |
3 | -import { defineComponent, unref, computed, ref } from 'vue'; | |
3 | +import { defineComponent, unref, computed, ref, nextTick } from 'vue'; | |
4 | 4 | |
5 | 5 | import { Layout, Tooltip, Badge } from 'ant-design-vue'; |
6 | 6 | import { AppLogo } from '/@/components/Application'; |
... | ... | @@ -39,8 +39,8 @@ export default defineComponent({ |
39 | 39 | setup() { |
40 | 40 | let logoEl: Element | null; |
41 | 41 | |
42 | - const widthRef = ref(200); | |
43 | - | |
42 | + const logoWidthRef = ref(200); | |
43 | + const logoRef = ref<any>(null); | |
44 | 44 | const { refreshPage } = useTabs(); |
45 | 45 | |
46 | 46 | const { getShowTopMenu, getShowHeaderTrigger, getSplit, getTopMenuAlign } = useMenuSetting(); |
... | ... | @@ -64,15 +64,17 @@ export default defineComponent({ |
64 | 64 | |
65 | 65 | useWindowSizeFn( |
66 | 66 | () => { |
67 | - if (!unref(getShowTopMenu)) return; | |
68 | - let width = 0; | |
69 | - if (!logoEl) { | |
70 | - logoEl = document.querySelector('.layout-header__logo'); | |
71 | - } | |
72 | - if (logoEl) { | |
73 | - width += logoEl.clientWidth; | |
74 | - } | |
75 | - widthRef.value = width + 60; | |
67 | + nextTick(() => { | |
68 | + if (!unref(getShowTopMenu)) return; | |
69 | + let width = 0; | |
70 | + if (!logoEl) { | |
71 | + logoEl = logoRef.value.$el; | |
72 | + } | |
73 | + if (logoEl) { | |
74 | + width += logoEl.clientWidth; | |
75 | + } | |
76 | + logoWidthRef.value = width + 80; | |
77 | + }); | |
76 | 78 | }, |
77 | 79 | 200, |
78 | 80 | { immediate: true } |
... | ... | @@ -105,11 +107,11 @@ export default defineComponent({ |
105 | 107 | } |
106 | 108 | |
107 | 109 | function renderHeaderContent() { |
108 | - const width = unref(widthRef); | |
110 | + const width = unref(logoWidthRef); | |
109 | 111 | return ( |
110 | 112 | <div class="layout-header__content "> |
111 | 113 | {unref(getShowHeaderLogo) && ( |
112 | - <AppLogo class={`layout-header__logo`} theme={unref(getTheme)} /> | |
114 | + <AppLogo class={`layout-header__logo`} ref={logoRef} theme={unref(getTheme)} /> | |
113 | 115 | )} |
114 | 116 | |
115 | 117 | {unref(getShowContent) && ( | ... | ... |
src/layouts/default/header/index.less
... | ... | @@ -12,7 +12,7 @@ |
12 | 12 | |
13 | 13 | &__left { |
14 | 14 | display: flex; |
15 | - flex-grow: 1; | |
15 | + // flex-grow: 1; | |
16 | 16 | align-items: center; |
17 | 17 | |
18 | 18 | .layout-trigger { |
... | ... | @@ -184,7 +184,7 @@ |
184 | 184 | } |
185 | 185 | |
186 | 186 | &__menu { |
187 | - margin-left: 20px; | |
187 | + margin-left: 4px; | |
188 | 188 | overflow: hidden; |
189 | 189 | align-items: center; |
190 | 190 | } | ... | ... |