Commit 33cd8fe6533830176ab63ddfc4d74f75a384366c
Committed by
GitHub
1 parent
c6b766d8
fix(useViewHeight): Fix the problem that useContentViewHeight does not calculate the footer (#747)
Co-authored-by: NorthLan <lan6995@gmail.com>
Showing
4 changed files
with
42 additions
and
6 deletions
src/components/Page/src/PageWrapper.vue
@@ -44,6 +44,8 @@ | @@ -44,6 +44,8 @@ | ||
44 | import { omit } from 'lodash-es'; | 44 | import { omit } from 'lodash-es'; |
45 | import { PageHeader } from 'ant-design-vue'; | 45 | import { PageHeader } from 'ant-design-vue'; |
46 | import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated'; | 46 | import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated'; |
47 | + import { useLayoutHeight } from '/@/layouts/default/content/useContentViewHeight'; | ||
48 | + | ||
47 | export default defineComponent({ | 49 | export default defineComponent({ |
48 | name: 'PageWrapper', | 50 | name: 'PageWrapper', |
49 | components: { PageFooter, PageHeader }, | 51 | components: { PageFooter, PageHeader }, |
@@ -67,6 +69,7 @@ | @@ -67,6 +69,7 @@ | ||
67 | const footerHeight = ref(0); | 69 | const footerHeight = ref(0); |
68 | const { prefixCls, prefixVar } = useDesign('page-wrapper'); | 70 | const { prefixCls, prefixVar } = useDesign('page-wrapper'); |
69 | const { contentHeight, setPageHeight, pageHeight } = usePageContext(); | 71 | const { contentHeight, setPageHeight, pageHeight } = usePageContext(); |
72 | + const { footerHeightRef } = useLayoutHeight(); | ||
70 | 73 | ||
71 | const getClass = computed(() => { | 74 | const getClass = computed(() => { |
72 | return [ | 75 | return [ |
@@ -109,7 +112,7 @@ | @@ -109,7 +112,7 @@ | ||
109 | }); | 112 | }); |
110 | 113 | ||
111 | watch( | 114 | watch( |
112 | - () => [contentHeight?.value, getShowFooter.value], | 115 | + () => [contentHeight?.value, getShowFooter.value, footerHeightRef.value], |
113 | () => { | 116 | () => { |
114 | calcContentHeight(); | 117 | calcContentHeight(); |
115 | }, | 118 | }, |
src/layouts/default/content/useContentViewHeight.ts
1 | import { ref, computed, unref } from 'vue'; | 1 | import { ref, computed, unref } from 'vue'; |
2 | import { createPageContext } from '/@/hooks/component/usePageContext'; | 2 | import { createPageContext } from '/@/hooks/component/usePageContext'; |
3 | import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn'; | 3 | import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn'; |
4 | -export const headerHeightRef = ref(0); | 4 | + |
5 | +const headerHeightRef = ref(0); | ||
6 | +const footerHeightRef = ref(0); | ||
7 | + | ||
8 | +export function useLayoutHeight() { | ||
9 | + function setHeaderHeight(val) { | ||
10 | + headerHeightRef.value = val; | ||
11 | + } | ||
12 | + function setFooterHeight(val) { | ||
13 | + footerHeightRef.value = val; | ||
14 | + } | ||
15 | + return { headerHeightRef, footerHeightRef, setHeaderHeight, setFooterHeight }; | ||
16 | +} | ||
5 | 17 | ||
6 | export function useContentViewHeight() { | 18 | export function useContentViewHeight() { |
7 | const contentHeight = ref(window.innerHeight); | 19 | const contentHeight = ref(window.innerHeight); |
src/layouts/default/footer/index.vue
@@ -12,7 +12,7 @@ | @@ -12,7 +12,7 @@ | ||
12 | </template> | 12 | </template> |
13 | 13 | ||
14 | <script lang="ts"> | 14 | <script lang="ts"> |
15 | - import { computed, defineComponent, unref } from 'vue'; | 15 | + import { computed, defineComponent, unref, ref } from 'vue'; |
16 | import { Layout } from 'ant-design-vue'; | 16 | import { Layout } from 'ant-design-vue'; |
17 | 17 | ||
18 | import { GithubFilled } from '@ant-design/icons-vue'; | 18 | import { GithubFilled } from '@ant-design/icons-vue'; |
@@ -24,6 +24,7 @@ | @@ -24,6 +24,7 @@ | ||
24 | import { useRootSetting } from '/@/hooks/setting/useRootSetting'; | 24 | import { useRootSetting } from '/@/hooks/setting/useRootSetting'; |
25 | import { useRouter } from 'vue-router'; | 25 | import { useRouter } from 'vue-router'; |
26 | import { useDesign } from '/@/hooks/web/useDesign'; | 26 | import { useDesign } from '/@/hooks/web/useDesign'; |
27 | + import { useLayoutHeight } from '../content/useContentViewHeight'; | ||
27 | 28 | ||
28 | export default defineComponent({ | 29 | export default defineComponent({ |
29 | name: 'LayoutFooter', | 30 | name: 'LayoutFooter', |
@@ -34,10 +35,29 @@ | @@ -34,10 +35,29 @@ | ||
34 | const { currentRoute } = useRouter(); | 35 | const { currentRoute } = useRouter(); |
35 | const { prefixCls } = useDesign('layout-footer'); | 36 | const { prefixCls } = useDesign('layout-footer'); |
36 | 37 | ||
38 | + const footerRef = ref<ComponentRef>(null); | ||
39 | + const { setFooterHeight } = useLayoutHeight(); | ||
40 | + | ||
37 | const getShowLayoutFooter = computed(() => { | 41 | const getShowLayoutFooter = computed(() => { |
42 | + if (unref(getShowFooter)) { | ||
43 | + const footerEl = unref(footerRef)?.$el; | ||
44 | + setFooterHeight(footerEl?.offsetHeight || 0); | ||
45 | + } else { | ||
46 | + setFooterHeight(0); | ||
47 | + } | ||
38 | return unref(getShowFooter) && !unref(currentRoute).meta?.hiddenFooter; | 48 | return unref(getShowFooter) && !unref(currentRoute).meta?.hiddenFooter; |
39 | }); | 49 | }); |
40 | - return { getShowLayoutFooter, prefixCls, t, DOC_URL, GITHUB_URL, SITE_URL, openWindow }; | 50 | + |
51 | + return { | ||
52 | + getShowLayoutFooter, | ||
53 | + prefixCls, | ||
54 | + t, | ||
55 | + DOC_URL, | ||
56 | + GITHUB_URL, | ||
57 | + SITE_URL, | ||
58 | + openWindow, | ||
59 | + footerRef, | ||
60 | + }; | ||
41 | }, | 61 | }, |
42 | }); | 62 | }); |
43 | </script> | 63 | </script> |
src/layouts/default/header/MultipleHeader.vue
@@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
17 | import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; | 17 | import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; |
18 | import { useAppInject } from '/@/hooks/web/useAppInject'; | 18 | import { useAppInject } from '/@/hooks/web/useAppInject'; |
19 | import { useDesign } from '/@/hooks/web/useDesign'; | 19 | import { useDesign } from '/@/hooks/web/useDesign'; |
20 | - import { headerHeightRef } from '../content/useContentViewHeight'; | 20 | + import { useLayoutHeight } from '../content/useContentViewHeight'; |
21 | 21 | ||
22 | const HEADER_HEIGHT = 48; | 22 | const HEADER_HEIGHT = 48; |
23 | 23 | ||
@@ -26,6 +26,7 @@ | @@ -26,6 +26,7 @@ | ||
26 | name: 'LayoutMultipleHeader', | 26 | name: 'LayoutMultipleHeader', |
27 | components: { LayoutHeader, MultipleTabs }, | 27 | components: { LayoutHeader, MultipleTabs }, |
28 | setup() { | 28 | setup() { |
29 | + const { setHeaderHeight } = useLayoutHeight(); | ||
29 | const { prefixCls } = useDesign('layout-multiple-header'); | 30 | const { prefixCls } = useDesign('layout-multiple-header'); |
30 | 31 | ||
31 | const { getCalcContentWidth, getSplit } = useMenuSetting(); | 32 | const { getCalcContentWidth, getSplit } = useMenuSetting(); |
@@ -77,7 +78,7 @@ | @@ -77,7 +78,7 @@ | ||
77 | if (unref(getShowMultipleTab) && !unref(getFullContent)) { | 78 | if (unref(getShowMultipleTab) && !unref(getFullContent)) { |
78 | height += TABS_HEIGHT; | 79 | height += TABS_HEIGHT; |
79 | } | 80 | } |
80 | - headerHeightRef.value = height; | 81 | + setHeaderHeight(height); |
81 | return { | 82 | return { |
82 | height: `${height}px`, | 83 | height: `${height}px`, |
83 | }; | 84 | }; |