You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.2 KiB

3 years ago
3 years ago
3 years ago
  1. <script setup lang="ts">
  2. import Search from "../search/index.vue";
  3. import Notice from "../notice/index.vue";
  4. import { ref, watch, nextTick } from "vue";
  5. import SidebarItem from "./sidebarItem.vue";
  6. import { useNav } from "@/layout/hooks/useNav";
  7. import { useTranslationLang } from "../../hooks/useTranslationLang";
  8. import { usePermissionStoreHook } from "@/store/modules/permission";
  9. import globalization from "@/assets/svg/globalization.svg?component";
  10. import LogoutCircleRLine from "@iconify-icons/ri/logout-circle-r-line";
  11. import Setting from "@iconify-icons/ri/settings-3-line";
  12. import Check from "@iconify-icons/ep/check";
  13. const menuRef = ref();
  14. const { t, route, locale, translationCh, translationEn } =
  15. useTranslationLang(menuRef);
  16. const {
  17. title,
  18. routers,
  19. logout,
  20. backHome,
  21. onPanel,
  22. menuSelect,
  23. username,
  24. avatarsStyle,
  25. getDropdownItemStyle,
  26. getDropdownItemClass
  27. } = useNav();
  28. nextTick(() => {
  29. menuRef.value?.handleResize();
  30. });
  31. watch(
  32. () => route.path,
  33. () => {
  34. menuSelect(route.path, routers);
  35. }
  36. );
  37. </script>
  38. <template>
  39. <div class="horizontal-header">
  40. <div class="horizontal-header-left" @click="backHome">
  41. <FontIcon icon="team-iconlogo" svg style="width: 35px; height: 35px" />
  42. <h4>{{ title }}</h4>
  43. </div>
  44. <el-menu
  45. router
  46. ref="menuRef"
  47. mode="horizontal"
  48. class="horizontal-header-menu"
  49. :default-active="route.path"
  50. @select="indexPath => menuSelect(indexPath, routers)"
  51. >
  52. <sidebar-item
  53. v-for="route in usePermissionStoreHook().wholeMenus"
  54. :key="route.path"
  55. :item="route"
  56. :base-path="route.path"
  57. />
  58. </el-menu>
  59. <div class="horizontal-header-right">
  60. <!-- 菜单搜索 -->
  61. <Search />
  62. <!-- 通知 -->
  63. <Notice id="header-notice" />
  64. <!-- 国际化 -->
  65. <el-dropdown id="header-translation" trigger="click">
  66. <globalization
  67. class="navbar-bg-hover w-[40px] h-[48px] p-[11px] cursor-pointer outline-none"
  68. />
  69. <template #dropdown>
  70. <el-dropdown-menu class="translation">
  71. <el-dropdown-item
  72. :style="getDropdownItemStyle(locale, 'zh')"
  73. :class="['dark:!text-white', getDropdownItemClass(locale, 'zh')]"
  74. @click="translationCh"
  75. >
  76. <span class="check-zh" v-show="locale === 'zh'">
  77. <IconifyIconOffline :icon="Check" />
  78. </span>
  79. 简体中文
  80. </el-dropdown-item>
  81. <el-dropdown-item
  82. :style="getDropdownItemStyle(locale, 'en')"
  83. :class="['dark:!text-white', getDropdownItemClass(locale, 'en')]"
  84. @click="translationEn"
  85. >
  86. <span class="check-en" v-show="locale === 'en'">
  87. <IconifyIconOffline :icon="Check" />
  88. </span>
  89. English
  90. </el-dropdown-item>
  91. </el-dropdown-menu>
  92. </template>
  93. </el-dropdown>
  94. <!-- 退出登录 -->
  95. <el-dropdown trigger="click">
  96. <span class="el-dropdown-link navbar-bg-hover">
  97. <img
  98. src="https://avatars.githubusercontent.com/u/44761321?v=4"
  99. :style="avatarsStyle"
  100. />
  101. <p v-if="username" class="dark:text-white">{{ username }}</p>
  102. </span>
  103. <template #dropdown>
  104. <el-dropdown-menu class="logout">
  105. <el-dropdown-item @click="logout">
  106. <IconifyIconOffline
  107. :icon="LogoutCircleRLine"
  108. style="margin: 5px"
  109. />
  110. {{ t("buttons.hsLoginOut") }}
  111. </el-dropdown-item>
  112. </el-dropdown-menu>
  113. </template>
  114. </el-dropdown>
  115. <span
  116. class="set-icon navbar-bg-hover"
  117. :title="t('buttons.hssystemSet')"
  118. @click="onPanel"
  119. >
  120. <IconifyIconOffline :icon="Setting" />
  121. </span>
  122. </div>
  123. </div>
  124. </template>
  125. <style lang="scss" scoped>
  126. .translation {
  127. ::v-deep(.el-dropdown-menu__item) {
  128. padding: 5px 40px;
  129. }
  130. .check-zh {
  131. position: absolute;
  132. left: 20px;
  133. }
  134. .check-en {
  135. position: absolute;
  136. left: 20px;
  137. }
  138. }
  139. .logout {
  140. max-width: 120px;
  141. ::v-deep(.el-dropdown-menu__item) {
  142. min-width: 100%;
  143. display: inline-flex;
  144. flex-wrap: wrap;
  145. }
  146. }
  147. </style>