useContentViewHeight.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { ref, computed, unref } from 'vue';
  2. import { createPageContext } from '/@/hooks/component/usePageContext';
  3. import { useWindowSizeFn } from '@vben/hooks';
  4. const headerHeightRef = ref(0);
  5. const footerHeightRef = ref(0);
  6. export function useLayoutHeight() {
  7. function setHeaderHeight(val) {
  8. headerHeightRef.value = val;
  9. }
  10. function setFooterHeight(val) {
  11. footerHeightRef.value = val;
  12. }
  13. return { headerHeightRef, footerHeightRef, setHeaderHeight, setFooterHeight };
  14. }
  15. export function useContentViewHeight() {
  16. const contentHeight = ref(window.innerHeight);
  17. const pageHeight = ref(window.innerHeight);
  18. const getViewHeight = computed(() => {
  19. return unref(contentHeight) - unref(headerHeightRef) - unref(footerHeightRef) || 0;
  20. });
  21. useWindowSizeFn(
  22. () => {
  23. contentHeight.value = window.innerHeight;
  24. },
  25. { wait: 100, immediate: true },
  26. );
  27. async function setPageHeight(height: number) {
  28. pageHeight.value = height;
  29. }
  30. createPageContext({
  31. contentHeight: getViewHeight,
  32. setPageHeight,
  33. pageHeight,
  34. });
  35. }