LayoutMultipleHeader.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import './LayoutMultipleHeader.less';
  2. import { defineComponent, unref, computed, ref, watch, nextTick, CSSProperties } from 'vue';
  3. import LayoutHeader from './LayoutHeader';
  4. import MultipleTabs from '../multitabs/index';
  5. import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting';
  6. import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
  7. import { useFullContent } from '/@/hooks/web/useFullContent';
  8. import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
  9. import { useLayoutContext } from '../useLayoutContext';
  10. export default defineComponent({
  11. name: 'LayoutMultipleHeader',
  12. setup() {
  13. const placeholderHeightRef = ref(0);
  14. const fullHeaderHeightRef = ref(0);
  15. const headerElRef = ref<ComponentRef>(null);
  16. const tabElRef = ref<ComponentRef>(null);
  17. const injectValue = useLayoutContext();
  18. const { getCalcContentWidth } = useMenuSetting();
  19. const {
  20. getFixed,
  21. getShowInsetHeaderRef,
  22. getShowFullHeaderRef,
  23. getShowHeader,
  24. getUnFixedAndFull,
  25. getHeaderTheme,
  26. } = useHeaderSetting();
  27. const { getFullContent } = useFullContent();
  28. const { getShowMultipleTab } = useMultipleTabSetting();
  29. const showTabsRef = computed(() => {
  30. return unref(getShowMultipleTab) && !unref(getFullContent);
  31. });
  32. const getPlaceholderDomStyle = computed(
  33. (): CSSProperties => {
  34. return {
  35. height: `${unref(placeholderHeightRef)}px`,
  36. };
  37. }
  38. );
  39. const getIsShowPlaceholderDom = computed(() => {
  40. return unref(getFixed) || unref(getShowFullHeaderRef);
  41. });
  42. const getWrapStyle = computed(
  43. (): CSSProperties => {
  44. const style: CSSProperties = {};
  45. if (unref(getFixed)) {
  46. style.width = unref(getCalcContentWidth);
  47. }
  48. if (unref(getShowFullHeaderRef)) {
  49. style.top = `${unref(fullHeaderHeightRef)}px`;
  50. }
  51. return style;
  52. }
  53. );
  54. const getIsFixed = computed(() => {
  55. return unref(getFixed) || unref(getShowFullHeaderRef);
  56. });
  57. watch(
  58. () => [
  59. unref(getFixed),
  60. unref(getShowFullHeaderRef),
  61. unref(getShowHeader),
  62. unref(getShowMultipleTab),
  63. ],
  64. () => {
  65. if (unref(getUnFixedAndFull)) return;
  66. nextTick(() => {
  67. const headerEl = unref(headerElRef)?.$el;
  68. const tabEl = unref(tabElRef)?.$el;
  69. const fullHeaderEl = unref(injectValue.fullHeaderRef)?.$el;
  70. let height = 0;
  71. if (headerEl && !unref(getShowFullHeaderRef)) {
  72. height += headerEl.offsetHeight;
  73. }
  74. if (tabEl) {
  75. height += tabEl.offsetHeight;
  76. }
  77. if (fullHeaderEl && unref(getShowFullHeaderRef)) {
  78. const fullHeaderHeight = fullHeaderEl.offsetHeight;
  79. height += fullHeaderHeight;
  80. fullHeaderHeightRef.value = fullHeaderHeight;
  81. }
  82. placeholderHeightRef.value = height;
  83. });
  84. },
  85. {
  86. immediate: true,
  87. }
  88. );
  89. return () => {
  90. return (
  91. <>
  92. {unref(getIsShowPlaceholderDom) && <div style={unref(getPlaceholderDomStyle)} />}
  93. <div
  94. style={unref(getWrapStyle)}
  95. class={['multiple-tab-header', unref(getHeaderTheme), { fixed: unref(getIsFixed) }]}
  96. >
  97. {unref(getShowInsetHeaderRef) && <LayoutHeader ref={headerElRef} />}
  98. {unref(showTabsRef) && <MultipleTabs ref={tabElRef} />}
  99. </div>
  100. </>
  101. );
  102. };
  103. },
  104. });