LayoutHeader.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import { defineComponent, unref, computed } from 'vue';
  2. import { Layout, Tooltip, Badge } from 'ant-design-vue';
  3. import Logo from '/@/layouts/Logo.vue';
  4. import UserDropdown from './UserDropdown';
  5. import LayoutMenu from './LayoutMenu';
  6. import { appStore } from '/@/store/modules/app';
  7. import { MenuModeEnum, MenuSplitTyeEnum, MenuTypeEnum } from '/@/enums/menuEnum';
  8. import LayoutBreadcrumb from './LayoutBreadcrumb';
  9. import {
  10. RedoOutlined,
  11. FullscreenExitOutlined,
  12. FullscreenOutlined,
  13. GithubFilled,
  14. LockOutlined,
  15. BugOutlined,
  16. } from '@ant-design/icons-vue';
  17. import { useFullscreen } from '/@/hooks/web/useFullScreen';
  18. import { useTabs } from '/@/hooks/web/useTabs';
  19. import { GITHUB_URL } from '/@/settings/siteSetting';
  20. import LockAction from './actions/LockActionItem';
  21. import { useModal } from '/@/components/Modal/index';
  22. import { errorStore } from '/@/store/modules/error';
  23. import { useGo } from '/@/hooks/web/usePage';
  24. export default defineComponent({
  25. name: 'DefaultLayoutHeader',
  26. setup() {
  27. const { refreshPage } = useTabs();
  28. const [register, { openModal }] = useModal();
  29. const { toggleFullscreen, isFullscreenRef } = useFullscreen();
  30. const go = useGo();
  31. const getProjectConfigRef = computed(() => {
  32. return appStore.getProjectConfig;
  33. });
  34. function goToGithub() {
  35. window.open(GITHUB_URL, '__blank');
  36. }
  37. const headerClass = computed(() => {
  38. const theme = unref(getProjectConfigRef).headerSetting.theme;
  39. return theme ? `layout-header__header--${theme}` : '';
  40. });
  41. function handleToErrorList() {
  42. errorStore.commitErrorListCountState(0);
  43. go('/exception/error-log');
  44. }
  45. /**
  46. * @description: 锁定屏幕
  47. */
  48. function handleLockPage() {
  49. openModal(true);
  50. }
  51. return () => {
  52. const getProjectConfig = unref(getProjectConfigRef);
  53. const {
  54. useErrorHandle,
  55. showLogo,
  56. headerSetting: { theme: headerTheme, useLockPage, showRedo, showGithub, showFullScreen },
  57. menuSetting: { mode, type: menuType, split: splitMenu, topMenuAlign },
  58. showBreadCrumb,
  59. } = getProjectConfig;
  60. const isSidebarType = menuType === MenuTypeEnum.SIDEBAR;
  61. return (
  62. <Layout.Header class={['layout-header', 'flex p-0 px-4 ', unref(headerClass)]}>
  63. {() => (
  64. <>
  65. <div class="layout-header__content ">
  66. {showLogo && !isSidebarType && <Logo class={`layout-header__logo`} />}
  67. {mode !== MenuModeEnum.HORIZONTAL && showBreadCrumb && !splitMenu && (
  68. <LayoutBreadcrumb />
  69. )}
  70. {(mode === MenuModeEnum.HORIZONTAL || splitMenu) && (
  71. <div class={[`layout-header__menu `, `justify-${topMenuAlign}`]}>
  72. <LayoutMenu
  73. theme={headerTheme}
  74. splitType={splitMenu ? MenuSplitTyeEnum.TOP : MenuSplitTyeEnum.NONE}
  75. menuMode={splitMenu ? MenuModeEnum.HORIZONTAL : null}
  76. showSearch={false}
  77. />
  78. </div>
  79. )}
  80. </div>
  81. <div class={`layout-header__action`}>
  82. {useErrorHandle && (
  83. <Tooltip>
  84. {{
  85. title: () => '错误日志',
  86. default: () => (
  87. <Badge
  88. count={errorStore.getErrorListCountState}
  89. offset={[0, 10]}
  90. overflowCount={99}
  91. >
  92. {() => (
  93. <div class={`layout-header__action-item`} onClick={handleToErrorList}>
  94. <BugOutlined class={`layout-header__action-icon`} />
  95. </div>
  96. )}
  97. </Badge>
  98. ),
  99. }}
  100. </Tooltip>
  101. )}
  102. {showGithub && (
  103. <Tooltip>
  104. {{
  105. title: () => 'github',
  106. default: () => (
  107. <div class={`layout-header__action-item`} onClick={goToGithub}>
  108. <GithubFilled class={`layout-header__action-icon`} />
  109. </div>
  110. ),
  111. }}
  112. </Tooltip>
  113. )}
  114. {useLockPage && (
  115. <Tooltip>
  116. {{
  117. title: () => '锁定屏幕',
  118. default: () => (
  119. <div class={`layout-header__action-item`} onClick={handleLockPage}>
  120. <LockOutlined class={`layout-header__action-icon`} />
  121. </div>
  122. ),
  123. }}
  124. </Tooltip>
  125. )}
  126. {showRedo && (
  127. <Tooltip>
  128. {{
  129. title: () => '刷新',
  130. default: () => (
  131. <div class={`layout-header__action-item`} onClick={refreshPage}>
  132. <RedoOutlined class={`layout-header__action-icon`} />
  133. </div>
  134. ),
  135. }}
  136. </Tooltip>
  137. )}
  138. {showFullScreen && (
  139. <Tooltip>
  140. {{
  141. title: () => (unref(isFullscreenRef) ? '退出全屏' : '全屏'),
  142. default: () => {
  143. const Icon: any = !unref(isFullscreenRef) ? (
  144. <FullscreenOutlined />
  145. ) : (
  146. <FullscreenExitOutlined />
  147. );
  148. return (
  149. <div class={`layout-header__action-item`} onClick={toggleFullscreen}>
  150. <Icon class={`layout-header__action-icon`} />
  151. </div>
  152. );
  153. },
  154. }}
  155. </Tooltip>
  156. )}
  157. <UserDropdown class={`layout-header__user-dropdown`} />
  158. </div>
  159. <LockAction onRegister={register} />
  160. </>
  161. )}
  162. </Layout.Header>
  163. );
  164. };
  165. },
  166. });