index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <Layout.Header :class="getHeaderClass" style="height: auto; padding-inline: 0">
  3. <!-- left start -->
  4. <div :class="`${prefixCls}-left`">
  5. <!-- logo -->
  6. <AppLogo
  7. v-if="getShowHeaderLogo || getIsMobile"
  8. :class="`${prefixCls}-logo`"
  9. :theme="getHeaderTheme"
  10. :style="getLogoWidth"
  11. />
  12. <LayoutTrigger
  13. v-if="
  14. (getShowContent && getShowHeaderTrigger && !getSplit && !getIsMixSidebar) || getIsMobile
  15. "
  16. :theme="getHeaderTheme"
  17. :sider="false"
  18. />
  19. <LayoutBreadcrumb v-if="getShowContent && getShowBread" :theme="getHeaderTheme" />
  20. </div>
  21. <!-- left end -->
  22. <!-- menu start -->
  23. <div v-if="getShowTopMenu && !getIsMobile" :class="`${prefixCls}-menu`">
  24. <LayoutMenu
  25. :isHorizontal="true"
  26. :theme="getHeaderTheme"
  27. :splitType="getSplitType"
  28. :menuMode="getMenuMode"
  29. />
  30. </div>
  31. <!-- menu-end -->
  32. <!-- action -->
  33. <div :class="`${prefixCls}-action`">
  34. <AppSearch v-if="getShowSearch" :class="`${prefixCls}-action__item `" />
  35. <ErrorAction v-if="getUseErrorHandle" :class="`${prefixCls}-action__item error-action`" />
  36. <Notify v-if="getShowNotice" :class="`${prefixCls}-action__item notify-item`" />
  37. <FullScreen v-if="getShowFullScreen" :class="`${prefixCls}-action__item fullscreen-item`" />
  38. <AppLocalePicker
  39. v-if="getShowLocalePicker"
  40. :reload="true"
  41. :showText="false"
  42. :class="`${prefixCls}-action__item`"
  43. />
  44. <UserDropDown :theme="getHeaderTheme" />
  45. <SettingDrawer v-if="getShowSetting" :class="`${prefixCls}-action__item`" />
  46. </div>
  47. </Layout.Header>
  48. </template>
  49. <script lang="ts" setup>
  50. import { Layout } from 'ant-design-vue';
  51. import { computed, unref } from 'vue';
  52. import { AppLocalePicker, AppLogo, AppSearch } from '@/components/Application';
  53. import { SettingButtonPositionEnum } from '@/enums/appEnum';
  54. import { MenuModeEnum, MenuSplitTyeEnum } from '@/enums/menuEnum';
  55. import { useHeaderSetting } from '@/hooks/setting/useHeaderSetting';
  56. import { useMenuSetting } from '@/hooks/setting/useMenuSetting';
  57. import { useRootSetting } from '@/hooks/setting/useRootSetting';
  58. import { useAppInject } from '@/hooks/web/useAppInject';
  59. import { useDesign } from '@/hooks/web/useDesign';
  60. import { useLocale } from '@/locales/useLocale';
  61. import { createAsyncComponent } from '@/utils/factory/createAsyncComponent';
  62. import { propTypes } from '@/utils/propTypes';
  63. import LayoutMenu from '../menu/index.vue';
  64. import LayoutTrigger from '../trigger/index.vue';
  65. import { ErrorAction, FullScreen, LayoutBreadcrumb, Notify, UserDropDown } from './components';
  66. const SettingDrawer = createAsyncComponent(() => import('@/layouts/default/setting/index.vue'), {
  67. loading: true,
  68. });
  69. defineOptions({ name: 'LayoutHeader' });
  70. const props = defineProps({
  71. fixed: propTypes.bool,
  72. });
  73. const { prefixCls } = useDesign('layout-header');
  74. const {
  75. getShowTopMenu,
  76. getShowHeaderTrigger,
  77. getSplit,
  78. getIsMixMode,
  79. getMenuWidth,
  80. getIsMixSidebar,
  81. } = useMenuSetting();
  82. const { getUseErrorHandle, getShowSettingButton, getSettingButtonPosition } = useRootSetting();
  83. const {
  84. getHeaderTheme,
  85. getShowFullScreen,
  86. getShowNotice,
  87. getShowContent,
  88. getShowBread,
  89. getShowHeaderLogo,
  90. getShowHeader,
  91. getShowSearch,
  92. } = useHeaderSetting();
  93. const { getShowLocalePicker } = useLocale();
  94. const { getIsMobile } = useAppInject();
  95. const getHeaderClass = computed(() => {
  96. const theme = unref(getHeaderTheme);
  97. return [
  98. prefixCls,
  99. {
  100. [`${prefixCls}--fixed`]: props.fixed,
  101. [`${prefixCls}--mobile`]: unref(getIsMobile),
  102. [`${prefixCls}--${theme}`]: theme,
  103. },
  104. ];
  105. });
  106. const getShowSetting = computed(() => {
  107. if (!unref(getShowSettingButton)) {
  108. return false;
  109. }
  110. const settingButtonPosition = unref(getSettingButtonPosition);
  111. if (settingButtonPosition === SettingButtonPositionEnum.AUTO) {
  112. return unref(getShowHeader);
  113. }
  114. return settingButtonPosition === SettingButtonPositionEnum.HEADER;
  115. });
  116. const getLogoWidth = computed(() => {
  117. if (!unref(getIsMixMode) || unref(getIsMobile)) {
  118. return {};
  119. }
  120. const width = unref(getMenuWidth) < 180 ? 180 : unref(getMenuWidth);
  121. return { width: `${width}px` };
  122. });
  123. const getSplitType = computed(() => {
  124. return unref(getSplit) ? MenuSplitTyeEnum.TOP : MenuSplitTyeEnum.NONE;
  125. });
  126. const getMenuMode = computed(() => {
  127. return unref(getSplit) ? MenuModeEnum.HORIZONTAL : null;
  128. });
  129. </script>
  130. <style lang="less">
  131. @import url('./index.less');
  132. </style>