MultipleHeader.vue 4.4 KB

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