MultipleHeader.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div :style="getPlaceholderDomStyle" v-if="getIsShowPlaceholderDom" />
  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. const HEADER_HEIGHT = 48;
  19. const TABS_HEIGHT = 32;
  20. export default defineComponent({
  21. name: 'LayoutMultipleHeader',
  22. components: { LayoutHeader, MultipleTabs },
  23. setup() {
  24. const { prefixCls } = useDesign('layout-multiple-header');
  25. const { getCalcContentWidth, getSplit } = useMenuSetting();
  26. const { getIsMobile } = useAppInject();
  27. const {
  28. getFixed,
  29. getShowInsetHeaderRef,
  30. getShowFullHeaderRef,
  31. getHeaderTheme,
  32. getShowHeader,
  33. } = useHeaderSetting();
  34. const { getFullContent } = useFullContent();
  35. const { getShowMultipleTab } = useMultipleTabSetting();
  36. const getShowTabs = computed(() => {
  37. return unref(getShowMultipleTab) && !unref(getFullContent);
  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(getIsMobile) ? '100%' : unref(getCalcContentWidth);
  47. }
  48. if (unref(getShowFullHeaderRef)) {
  49. style.top = `${HEADER_HEIGHT}px`;
  50. }
  51. return style;
  52. }
  53. );
  54. const getIsFixed = computed(() => {
  55. return unref(getFixed) || unref(getShowFullHeaderRef);
  56. });
  57. const getPlaceholderDomStyle = computed(
  58. (): CSSProperties => {
  59. let height = 0;
  60. if ((unref(getShowFullHeaderRef) || !unref(getSplit)) && unref(getShowHeader)) {
  61. height += HEADER_HEIGHT;
  62. }
  63. if (unref(getShowMultipleTab)) {
  64. height += TABS_HEIGHT;
  65. }
  66. return {
  67. height: `${height}px`,
  68. };
  69. }
  70. );
  71. const getClass = computed(() => {
  72. return [
  73. prefixCls,
  74. `${prefixCls}--${unref(getHeaderTheme)}`,
  75. { [`${prefixCls}--fixed`]: unref(getIsFixed) },
  76. ];
  77. });
  78. return {
  79. getClass,
  80. prefixCls,
  81. getPlaceholderDomStyle,
  82. getIsFixed,
  83. getWrapStyle,
  84. getIsShowPlaceholderDom,
  85. getShowTabs,
  86. getShowInsetHeaderRef,
  87. };
  88. },
  89. });
  90. </script>
  91. <style lang="less" scoped>
  92. @import (reference) '../../../design/index.less';
  93. @prefix-cls: ~'@{namespace}-layout-multiple-header';
  94. .@{prefix-cls} {
  95. margin-left: 1px;
  96. transition: width 0.2s;
  97. flex: 0 0 auto;
  98. &--dark {
  99. margin-left: 0;
  100. }
  101. &--fixed {
  102. position: fixed;
  103. top: 0;
  104. z-index: @multiple-tab-fixed-z-index;
  105. width: 100%;
  106. }
  107. }
  108. </style>