index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <Header :class="getHeaderClass">
  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 :class="`${prefixCls}-menu`" v-if="getShowTopMenu && !getIsMobile">
  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. <div v-if="expire">
  35. <Tag color="pink">已过期</Tag>
  36. </div>
  37. <!-- <AppSearch :class="`${prefixCls}-action__item `" v-if="getShowSearch" /> -->
  38. <!-- <ErrorAction v-if="getUseErrorHandle" :class="`${prefixCls}-action__item error-action`" /> -->
  39. <Notify v-if="getShowNotice" :class="`${prefixCls}-action__item notify-item`" />
  40. <FullScreen v-if="getShowFullScreen" :class="`${prefixCls}-action__item fullscreen-item`" />
  41. <AppLocalePicker
  42. v-if="getShowLocalePicker"
  43. :reload="true"
  44. :showText="false"
  45. :class="`${prefixCls}-action__item`"
  46. />
  47. <UserDropDown :theme="getHeaderTheme" />
  48. <SettingDrawer v-if="true" :class="`${prefixCls}-action__item`" />
  49. </div>
  50. </Header>
  51. </template>
  52. <script lang="ts">
  53. import { defineComponent, unref, computed } from 'vue';
  54. import { propTypes } from '/@/utils/propTypes';
  55. import { Layout } from 'ant-design-vue';
  56. import { AppLogo } from '/@/components/Application';
  57. import LayoutMenu from '../menu/index.vue';
  58. import LayoutTrigger from '../trigger/index.vue';
  59. import dayjs from 'dayjs';
  60. // import { AppSearch } from '/@/components/Application';
  61. import { Tag } from 'ant-design-vue';
  62. import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting';
  63. import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
  64. import { useRootSetting } from '/@/hooks/setting/useRootSetting';
  65. import { MenuModeEnum, MenuSplitTyeEnum } from '/@/enums/menuEnum';
  66. import { SettingButtonPositionEnum } from '/@/enums/appEnum';
  67. import { AppLocalePicker } from '/@/components/Application';
  68. // Notify ErrorAction
  69. import { UserDropDown, LayoutBreadcrumb, FullScreen, Notify } from './components';
  70. import { useAppInject } from '/@/hooks/web/useAppInject';
  71. import { useDesign } from '/@/hooks/web/useDesign';
  72. import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
  73. import { useLocale } from '/@/locales/useLocale';
  74. import { useUserStore } from '/@/store/modules/user';
  75. export default defineComponent({
  76. name: 'LayoutHeader',
  77. components: {
  78. Header: Layout.Header,
  79. AppLogo,
  80. LayoutTrigger,
  81. LayoutBreadcrumb,
  82. LayoutMenu,
  83. UserDropDown,
  84. AppLocalePicker,
  85. FullScreen,
  86. Tag,
  87. Notify,
  88. // AppSearch,
  89. // ErrorAction,
  90. SettingDrawer: createAsyncComponent(() => import('/@/layouts/default/setting/index.vue'), {
  91. loading: true,
  92. }),
  93. },
  94. props: {
  95. fixed: propTypes.bool,
  96. },
  97. setup(props) {
  98. const { prefixCls } = useDesign('layout-header');
  99. const userStore = useUserStore();
  100. const {
  101. getShowTopMenu,
  102. getShowHeaderTrigger,
  103. getSplit,
  104. getIsMixMode,
  105. getMenuWidth,
  106. getIsMixSidebar,
  107. } = useMenuSetting();
  108. const { getUseErrorHandle, getShowSettingButton, getSettingButtonPosition } =
  109. useRootSetting();
  110. const {
  111. getHeaderTheme,
  112. getShowFullScreen,
  113. getShowNotice,
  114. getShowContent,
  115. getShowBread,
  116. getShowHeaderLogo,
  117. getShowHeader,
  118. getShowSearch,
  119. } = useHeaderSetting();
  120. const { getShowLocalePicker } = useLocale();
  121. const { getIsMobile } = useAppInject();
  122. const userinfo = computed(() => userStore.getUserInfo);
  123. const expire = computed(() => {
  124. let expireTime = userinfo.value?.companyExpirationTime;
  125. if (expireTime && dayjs(expireTime) < dayjs()) {
  126. return true;
  127. } else {
  128. return false;
  129. }
  130. });
  131. console.log('userinfo', userinfo.value);
  132. const getHeaderClass = computed(() => {
  133. const theme = unref(getHeaderTheme);
  134. return [
  135. prefixCls,
  136. {
  137. [`${prefixCls}--fixed`]: props.fixed,
  138. [`${prefixCls}--mobile`]: unref(getIsMobile),
  139. [`${prefixCls}--${theme}`]: theme,
  140. },
  141. ];
  142. });
  143. const getShowSetting = computed(() => {
  144. if (!unref(getShowSettingButton)) {
  145. return false;
  146. }
  147. const settingButtonPosition = unref(getSettingButtonPosition);
  148. if (settingButtonPosition === SettingButtonPositionEnum.AUTO) {
  149. return unref(getShowHeader);
  150. }
  151. return settingButtonPosition === SettingButtonPositionEnum.HEADER;
  152. });
  153. const getLogoWidth = computed(() => {
  154. if (!unref(getIsMixMode) || unref(getIsMobile)) {
  155. return {};
  156. }
  157. const width = unref(getMenuWidth) < 180 ? 180 : unref(getMenuWidth);
  158. return { width: `${width}px` };
  159. });
  160. const getSplitType = computed(() => {
  161. return unref(getSplit) ? MenuSplitTyeEnum.TOP : MenuSplitTyeEnum.NONE;
  162. });
  163. const getMenuMode = computed(() => {
  164. return unref(getSplit) ? MenuModeEnum.HORIZONTAL : null;
  165. });
  166. return {
  167. prefixCls,
  168. getHeaderClass,
  169. getShowHeaderLogo,
  170. getHeaderTheme,
  171. getShowHeaderTrigger,
  172. getIsMobile,
  173. getShowBread,
  174. getShowContent,
  175. getSplitType,
  176. getSplit,
  177. getMenuMode,
  178. getShowTopMenu,
  179. getShowLocalePicker,
  180. getShowFullScreen,
  181. getShowNotice,
  182. getUseErrorHandle,
  183. getLogoWidth,
  184. getIsMixSidebar,
  185. getShowSettingButton,
  186. getShowSetting,
  187. getShowSearch,
  188. userinfo,
  189. expire,
  190. };
  191. },
  192. });
  193. </script>
  194. <style lang="less">
  195. @import './index.less';
  196. </style>