useContentViewHeight.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { ref, computed, unref } from 'vue';
  2. import { createPageContext } from '/@/hooks/component/usePageContext';
  3. import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn';
  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. 100,
  26. { immediate: true },
  27. );
  28. async function setPageHeight(height: number) {
  29. pageHeight.value = height;
  30. }
  31. createPageContext({
  32. contentHeight: getViewHeight,
  33. setPageHeight,
  34. pageHeight,
  35. });
  36. }