From 33cd8fe6533830176ab63ddfc4d74f75a384366c Mon Sep 17 00:00:00 2001 From: Lan <6995syu@163.com> Date: Fri, 11 Jun 2021 09:37:17 +0800 Subject: [PATCH] fix(useViewHeight): Fix the problem that useContentViewHeight does not calculate the footer (#747) Co-authored-by: NorthLan --- src/components/Page/src/PageWrapper.vue | 5 +++- .../default/content/useContentViewHeight.ts | 14 ++++++++++- src/layouts/default/footer/index.vue | 24 +++++++++++++++++-- src/layouts/default/header/MultipleHeader.vue | 5 ++-- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/components/Page/src/PageWrapper.vue b/src/components/Page/src/PageWrapper.vue index 19d3a4f4..583e1369 100644 --- a/src/components/Page/src/PageWrapper.vue +++ b/src/components/Page/src/PageWrapper.vue @@ -44,6 +44,8 @@ import { omit } from 'lodash-es'; import { PageHeader } from 'ant-design-vue'; import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated'; + import { useLayoutHeight } from '/@/layouts/default/content/useContentViewHeight'; + export default defineComponent({ name: 'PageWrapper', components: { PageFooter, PageHeader }, @@ -67,6 +69,7 @@ const footerHeight = ref(0); const { prefixCls, prefixVar } = useDesign('page-wrapper'); const { contentHeight, setPageHeight, pageHeight } = usePageContext(); + const { footerHeightRef } = useLayoutHeight(); const getClass = computed(() => { return [ @@ -109,7 +112,7 @@ }); watch( - () => [contentHeight?.value, getShowFooter.value], + () => [contentHeight?.value, getShowFooter.value, footerHeightRef.value], () => { calcContentHeight(); }, diff --git a/src/layouts/default/content/useContentViewHeight.ts b/src/layouts/default/content/useContentViewHeight.ts index d37792a6..42d3b365 100644 --- a/src/layouts/default/content/useContentViewHeight.ts +++ b/src/layouts/default/content/useContentViewHeight.ts @@ -1,7 +1,19 @@ import { ref, computed, unref } from 'vue'; import { createPageContext } from '/@/hooks/component/usePageContext'; import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn'; -export const headerHeightRef = ref(0); + +const headerHeightRef = ref(0); +const footerHeightRef = ref(0); + +export function useLayoutHeight() { + function setHeaderHeight(val) { + headerHeightRef.value = val; + } + function setFooterHeight(val) { + footerHeightRef.value = val; + } + return { headerHeightRef, footerHeightRef, setHeaderHeight, setFooterHeight }; +} export function useContentViewHeight() { const contentHeight = ref(window.innerHeight); diff --git a/src/layouts/default/footer/index.vue b/src/layouts/default/footer/index.vue index ed02448a..7cd2b24d 100644 --- a/src/layouts/default/footer/index.vue +++ b/src/layouts/default/footer/index.vue @@ -12,7 +12,7 @@ diff --git a/src/layouts/default/header/MultipleHeader.vue b/src/layouts/default/header/MultipleHeader.vue index a71c442d..c852b7ee 100644 --- a/src/layouts/default/header/MultipleHeader.vue +++ b/src/layouts/default/header/MultipleHeader.vue @@ -17,7 +17,7 @@ import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; import { useAppInject } from '/@/hooks/web/useAppInject'; import { useDesign } from '/@/hooks/web/useDesign'; - import { headerHeightRef } from '../content/useContentViewHeight'; + import { useLayoutHeight } from '../content/useContentViewHeight'; const HEADER_HEIGHT = 48; @@ -26,6 +26,7 @@ name: 'LayoutMultipleHeader', components: { LayoutHeader, MultipleTabs }, setup() { + const { setHeaderHeight } = useLayoutHeight(); const { prefixCls } = useDesign('layout-multiple-header'); const { getCalcContentWidth, getSplit } = useMenuSetting(); @@ -77,7 +78,7 @@ if (unref(getShowMultipleTab) && !unref(getFullContent)) { height += TABS_HEIGHT; } - headerHeightRef.value = height; + setHeaderHeight(height); return { height: `${height}px`, };