Skip to content

Commit

Permalink
fix(useViewHeight): Fix the problem that useContentViewHeight does no…
Browse files Browse the repository at this point in the history
…t calculate the footer (#747)

Co-authored-by: NorthLan <lan6995@gmail.com>
  • Loading branch information
noahlann and NorthLan authored Jun 11, 2021
1 parent c6b766d commit 33cd8fe
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/components/Page/src/PageWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 [
Expand Down Expand Up @@ -109,7 +112,7 @@
});
watch(
() => [contentHeight?.value, getShowFooter.value],
() => [contentHeight?.value, getShowFooter.value, footerHeightRef.value],
() => {
calcContentHeight();
},
Expand Down
14 changes: 13 additions & 1 deletion src/layouts/default/content/useContentViewHeight.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
24 changes: 22 additions & 2 deletions src/layouts/default/footer/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</template>

<script lang="ts">
import { computed, defineComponent, unref } from 'vue';
import { computed, defineComponent, unref, ref } from 'vue';
import { Layout } from 'ant-design-vue';
import { GithubFilled } from '@ant-design/icons-vue';
Expand All @@ -24,6 +24,7 @@
import { useRootSetting } from '/@/hooks/setting/useRootSetting';
import { useRouter } from 'vue-router';
import { useDesign } from '/@/hooks/web/useDesign';
import { useLayoutHeight } from '../content/useContentViewHeight';
export default defineComponent({
name: 'LayoutFooter',
Expand All @@ -34,10 +35,29 @@
const { currentRoute } = useRouter();
const { prefixCls } = useDesign('layout-footer');
const footerRef = ref<ComponentRef>(null);
const { setFooterHeight } = useLayoutHeight();
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 { getShowLayoutFooter, prefixCls, t, DOC_URL, GITHUB_URL, SITE_URL, openWindow };
return {
getShowLayoutFooter,
prefixCls,
t,
DOC_URL,
GITHUB_URL,
SITE_URL,
openWindow,
footerRef,
};
},
});
</script>
Expand Down
5 changes: 3 additions & 2 deletions src/layouts/default/header/MultipleHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +26,7 @@
name: 'LayoutMultipleHeader',
components: { LayoutHeader, MultipleTabs },
setup() {
const { setHeaderHeight } = useLayoutHeight();
const { prefixCls } = useDesign('layout-multiple-header');
const { getCalcContentWidth, getSplit } = useMenuSetting();
Expand Down Expand Up @@ -77,7 +78,7 @@
if (unref(getShowMultipleTab) && !unref(getFullContent)) {
height += TABS_HEIGHT;
}
headerHeightRef.value = height;
setHeaderHeight(height);
return {
height: `${height}px`,
};
Expand Down

0 comments on commit 33cd8fe

Please sign in to comment.