MultipleHeader.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div :style="getPlaceholderDomStyle" v-if="getIsShowPlaceholderDom"></div>
  3. <div :style="getWrapStyle" :class="getClass">
  4. <LayoutHeader v-if="getShowInsetHeaderRef" />
  5. <MultipleTabs v-if="getShowTabs" />
  6. </div>
  7. </template>
  8. <script lang="ts">
  9. import { defineComponent, unref, computed, CSSProperties } from 'vue';
  10. import LayoutHeader from './index.vue';
  11. import MultipleTabs from '../tabs/index.vue';
  12. import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting';
  13. import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
  14. import { useFullContent } from '/@/hooks/web/useFullContent';
  15. import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
  16. import { useAppInject } from '/@/hooks/web/useAppInject';
  17. import { useDesign } from '/@/hooks/web/useDesign';
  18. import { headerHeightRef } from '../content/useContentViewHeight';
  19. const HEADER_HEIGHT = 48;
  20. const TABS_HEIGHT = 32;
  21. export default defineComponent({
  22. name: 'LayoutMultipleHeader',
  23. components: { LayoutHeader, MultipleTabs },
  24. setup() {
  25. const { prefixCls } = useDesign('layout-multiple-header');
  26. const { getCalcContentWidth, getSplit } = useMenuSetting();
  27. const { getIsMobile } = useAppInject();
  28. const {
  29. getFixed,
  30. getShowInsetHeaderRef,
  31. getShowFullHeaderRef,
  32. getHeaderTheme,
  33. getShowHeader,
  34. } = useHeaderSetting();
  35. const { getFullContent } = useFullContent();
  36. const { getShowMultipleTab } = useMultipleTabSetting();
  37. const getShowTabs = computed(() => {
  38. return unref(getShowMultipleTab) && !unref(getFullContent);
  39. });
  40. const getIsShowPlaceholderDom = computed(() => {
  41. return unref(getFixed) || unref(getShowFullHeaderRef);
  42. });
  43. const getWrapStyle = computed(
  44. (): CSSProperties => {
  45. const style: CSSProperties = {};
  46. if (unref(getFixed)) {
  47. style.width = unref(getIsMobile) ? '100%' : unref(getCalcContentWidth);
  48. }
  49. if (unref(getShowFullHeaderRef)) {
  50. style.top = `${HEADER_HEIGHT}px`;
  51. }
  52. return style;
  53. }
  54. );
  55. const getIsFixed = computed(() => {
  56. return unref(getFixed) || unref(getShowFullHeaderRef);
  57. });
  58. const getPlaceholderDomStyle = computed(
  59. (): CSSProperties => {
  60. let height = 0;
  61. if (
  62. (unref(getShowFullHeaderRef) || !unref(getSplit)) &&
  63. unref(getShowHeader) &&
  64. !unref(getFullContent)
  65. ) {
  66. height += HEADER_HEIGHT;
  67. }
  68. if (unref(getShowMultipleTab) && !unref(getFullContent)) {
  69. height += TABS_HEIGHT;
  70. }
  71. headerHeightRef.value = height;
  72. return {
  73. height: `${height}px`,
  74. };
  75. }
  76. );
  77. const getClass = computed(() => {
  78. return [
  79. prefixCls,
  80. `${prefixCls}--${unref(getHeaderTheme)}`,
  81. { [`${prefixCls}--fixed`]: unref(getIsFixed) },
  82. ];
  83. });
  84. return {
  85. getClass,
  86. prefixCls,
  87. getPlaceholderDomStyle,
  88. getIsFixed,
  89. getWrapStyle,
  90. getIsShowPlaceholderDom,
  91. getShowTabs,
  92. getShowInsetHeaderRef,
  93. };
  94. },
  95. });
  96. </script>
  97. <style lang="less" scoped>
  98. @prefix-cls: ~'@{namespace}-layout-multiple-header';
  99. .@{prefix-cls} {
  100. // margin-left: 1px;
  101. transition: width 0.2s;
  102. flex: 0 0 auto;
  103. &--dark {
  104. margin-left: 0;
  105. }
  106. &--fixed {
  107. position: fixed;
  108. top: 0;
  109. z-index: @multiple-tab-fixed-z-index;
  110. width: 100%;
  111. }
  112. }
  113. </style>