MultipleHeader.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 { useLayoutHeight } 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 { setHeaderHeight } = useLayoutHeight();
  26. const { prefixCls } = useDesign('layout-multiple-header');
  27. const { getCalcContentWidth, getSplit } = useMenuSetting();
  28. const { getIsMobile } = useAppInject();
  29. const {
  30. getFixed,
  31. getShowInsetHeaderRef,
  32. getShowFullHeaderRef,
  33. getHeaderTheme,
  34. getShowHeader,
  35. } = useHeaderSetting();
  36. const { getFullContent } = useFullContent();
  37. const { getShowMultipleTab } = useMultipleTabSetting();
  38. const getShowTabs = computed(() => {
  39. return unref(getShowMultipleTab) && !unref(getFullContent);
  40. });
  41. const getIsShowPlaceholderDom = computed(() => {
  42. return unref(getFixed) || unref(getShowFullHeaderRef);
  43. });
  44. const getWrapStyle = computed((): 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. const getIsFixed = computed(() => {
  55. return unref(getFixed) || unref(getShowFullHeaderRef);
  56. });
  57. const getPlaceholderDomStyle = computed((): CSSProperties => {
  58. let height = 0;
  59. if (
  60. (unref(getShowFullHeaderRef) || !unref(getSplit)) &&
  61. unref(getShowHeader) &&
  62. !unref(getFullContent)
  63. ) {
  64. height += HEADER_HEIGHT;
  65. }
  66. if (unref(getShowMultipleTab) && !unref(getFullContent)) {
  67. height += TABS_HEIGHT;
  68. }
  69. setHeaderHeight(height);
  70. return {
  71. height: `${height}px`,
  72. };
  73. });
  74. const getClass = computed(() => {
  75. return [
  76. prefixCls,
  77. `${prefixCls}--${unref(getHeaderTheme)}`,
  78. { [`${prefixCls}--fixed`]: unref(getIsFixed) },
  79. ];
  80. });
  81. return {
  82. getClass,
  83. prefixCls,
  84. getPlaceholderDomStyle,
  85. getIsFixed,
  86. getWrapStyle,
  87. getIsShowPlaceholderDom,
  88. getShowTabs,
  89. getShowInsetHeaderRef,
  90. };
  91. },
  92. });
  93. </script>
  94. <style lang="less" scoped>
  95. @prefix-cls: ~'@{namespace}-layout-multiple-header';
  96. .@{prefix-cls} {
  97. flex: 0 0 auto;
  98. transition: width 0.2s;
  99. &--dark {
  100. margin-left: -1px;
  101. }
  102. &--fixed {
  103. position: fixed;
  104. z-index: @multiple-tab-fixed-z-index;
  105. top: 0;
  106. width: 100%;
  107. }
  108. }
  109. </style>