fix(useViewHeight): Fix the problem that useContentViewHeight does not calculate the footer (#747)

Co-authored-by: NorthLan <lan6995@gmail.com>
This commit is contained in:
Lan 2021-06-11 09:37:17 +08:00 committed by GitHub
parent c6b766d8ea
commit 33cd8fe653
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 6 deletions

View File

@ -44,6 +44,8 @@
import { omit } from 'lodash-es'; import { omit } from 'lodash-es';
import { PageHeader } from 'ant-design-vue'; import { PageHeader } from 'ant-design-vue';
import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated'; import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated';
import { useLayoutHeight } from '/@/layouts/default/content/useContentViewHeight';
export default defineComponent({ export default defineComponent({
name: 'PageWrapper', name: 'PageWrapper',
components: { PageFooter, PageHeader }, components: { PageFooter, PageHeader },
@ -67,6 +69,7 @@
const footerHeight = ref(0); const footerHeight = ref(0);
const { prefixCls, prefixVar } = useDesign('page-wrapper'); const { prefixCls, prefixVar } = useDesign('page-wrapper');
const { contentHeight, setPageHeight, pageHeight } = usePageContext(); const { contentHeight, setPageHeight, pageHeight } = usePageContext();
const { footerHeightRef } = useLayoutHeight();
const getClass = computed(() => { const getClass = computed(() => {
return [ return [
@ -109,7 +112,7 @@
}); });
watch( watch(
() => [contentHeight?.value, getShowFooter.value], () => [contentHeight?.value, getShowFooter.value, footerHeightRef.value],
() => { () => {
calcContentHeight(); calcContentHeight();
}, },

View File

@ -1,7 +1,19 @@
import { ref, computed, unref } from 'vue'; import { ref, computed, unref } from 'vue';
import { createPageContext } from '/@/hooks/component/usePageContext'; import { createPageContext } from '/@/hooks/component/usePageContext';
import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn'; 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() { export function useContentViewHeight() {
const contentHeight = ref(window.innerHeight); const contentHeight = ref(window.innerHeight);

View File

@ -12,7 +12,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, defineComponent, unref } from 'vue'; import { computed, defineComponent, unref, ref } from 'vue';
import { Layout } from 'ant-design-vue'; import { Layout } from 'ant-design-vue';
import { GithubFilled } from '@ant-design/icons-vue'; import { GithubFilled } from '@ant-design/icons-vue';
@ -24,6 +24,7 @@
import { useRootSetting } from '/@/hooks/setting/useRootSetting'; import { useRootSetting } from '/@/hooks/setting/useRootSetting';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { useDesign } from '/@/hooks/web/useDesign'; import { useDesign } from '/@/hooks/web/useDesign';
import { useLayoutHeight } from '../content/useContentViewHeight';
export default defineComponent({ export default defineComponent({
name: 'LayoutFooter', name: 'LayoutFooter',
@ -34,10 +35,29 @@
const { currentRoute } = useRouter(); const { currentRoute } = useRouter();
const { prefixCls } = useDesign('layout-footer'); const { prefixCls } = useDesign('layout-footer');
const footerRef = ref<ComponentRef>(null);
const { setFooterHeight } = useLayoutHeight();
const getShowLayoutFooter = computed(() => { const getShowLayoutFooter = computed(() => {
if (unref(getShowFooter)) {
const footerEl = unref(footerRef)?.$el;
setFooterHeight(footerEl?.offsetHeight || 0);
} else {
setFooterHeight(0);
}
return unref(getShowFooter) && !unref(currentRoute).meta?.hiddenFooter; return unref(getShowFooter) && !unref(currentRoute).meta?.hiddenFooter;
}); });
return { getShowLayoutFooter, prefixCls, t, DOC_URL, GITHUB_URL, SITE_URL, openWindow };
return {
getShowLayoutFooter,
prefixCls,
t,
DOC_URL,
GITHUB_URL,
SITE_URL,
openWindow,
footerRef,
};
}, },
}); });
</script> </script>

View File

@ -17,7 +17,7 @@
import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
import { useAppInject } from '/@/hooks/web/useAppInject'; import { useAppInject } from '/@/hooks/web/useAppInject';
import { useDesign } from '/@/hooks/web/useDesign'; import { useDesign } from '/@/hooks/web/useDesign';
import { headerHeightRef } from '../content/useContentViewHeight'; import { useLayoutHeight } from '../content/useContentViewHeight';
const HEADER_HEIGHT = 48; const HEADER_HEIGHT = 48;
@ -26,6 +26,7 @@
name: 'LayoutMultipleHeader', name: 'LayoutMultipleHeader',
components: { LayoutHeader, MultipleTabs }, components: { LayoutHeader, MultipleTabs },
setup() { setup() {
const { setHeaderHeight } = useLayoutHeight();
const { prefixCls } = useDesign('layout-multiple-header'); const { prefixCls } = useDesign('layout-multiple-header');
const { getCalcContentWidth, getSplit } = useMenuSetting(); const { getCalcContentWidth, getSplit } = useMenuSetting();
@ -77,7 +78,7 @@
if (unref(getShowMultipleTab) && !unref(getFullContent)) { if (unref(getShowMultipleTab) && !unref(getFullContent)) {
height += TABS_HEIGHT; height += TABS_HEIGHT;
} }
headerHeightRef.value = height; setHeaderHeight(height);
return { return {
height: `${height}px`, height: `${height}px`,
}; };