NavHorizontal.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <script setup lang="ts">
  2. import { emitter } from "@/utils/mitt";
  3. import { useNav } from "@/layout/hooks/useNav";
  4. import LaySearch from "../lay-search/index.vue";
  5. import LayNotice from "../lay-notice/index.vue";
  6. import { responsiveStorageNameSpace } from "@/config";
  7. import { ref, nextTick, computed, onMounted } from "vue";
  8. import { storageLocal, isAllEmpty } from "@pureadmin/utils";
  9. import { useTranslationLang } from "../../hooks/useTranslationLang";
  10. import { usePermissionStoreHook } from "@/store/modules/permission";
  11. import LaySidebarItem from "../lay-sidebar/components/SidebarItem.vue";
  12. import LaySidebarFullScreen from "../lay-sidebar/components/SidebarFullScreen.vue";
  13. import GlobalizationIcon from "@/assets/svg/globalization.svg?component";
  14. import AccountSettingsIcon from "~icons/ri/user-settings-line";
  15. import LogoutCircleRLine from "~icons/ri/logout-circle-r-line";
  16. import Setting from "~icons/ri/settings-3-line";
  17. import Check from "~icons/ep/check";
  18. const swEnable = ref(false);
  19. const refreshKey = ref(0);
  20. const menuRef = ref();
  21. const showLogo = ref(
  22. storageLocal().getItem<StorageConfigs>(
  23. `${responsiveStorageNameSpace()}configure`
  24. )?.showLogo ?? true
  25. );
  26. const { t, route, locale, translationCh, translationEn } =
  27. useTranslationLang(menuRef);
  28. const {
  29. title,
  30. logout,
  31. onPanel,
  32. getTitle,
  33. getLogo,
  34. uid,
  35. userAvatar,
  36. backTopMenu,
  37. avatarsStyle,
  38. toAccountSettings,
  39. getDropdownItemStyle,
  40. getDropdownItemClass
  41. } = useNav();
  42. const defaultActive = computed(() =>
  43. !isAllEmpty(route.meta?.activePath) ? route.meta.activePath : route.path
  44. );
  45. nextTick(() => {
  46. menuRef.value?.handleResize();
  47. });
  48. onMounted(() => {
  49. emitter.on("logoChange", key => {
  50. showLogo.value = key;
  51. });
  52. const ci = setInterval(() => {
  53. if (window.vueGlobal.isInited()) {
  54. clearInterval(ci);
  55. refreshKey.value++;
  56. console.log('refreshKey', refreshKey.value);
  57. }
  58. }, 100);
  59. });
  60. </script>
  61. <template>
  62. <div
  63. v-loading="usePermissionStoreHook().wholeMenus.length === 0"
  64. class="horizontal-header"
  65. >
  66. <div :key="refreshKey" v-if="showLogo" class="horizontal-header-left" @click="backTopMenu">
  67. <img :src="getLogo()" alt="logo" />
  68. <span>{{ getTitle() }}</span>
  69. </div>
  70. <el-menu
  71. ref="menuRef"
  72. mode="horizontal"
  73. popper-class="pure-scrollbar"
  74. class="horizontal-header-menu"
  75. :default-active="defaultActive"
  76. >
  77. <LaySidebarItem
  78. v-for="route in usePermissionStoreHook().wholeMenus"
  79. :key="route.path"
  80. :item="route"
  81. :base-path="route.path"
  82. />
  83. </el-menu>
  84. <div class="horizontal-header-right">
  85. <!-- 菜单搜索 -->
  86. <LaySearch id="header-search" />
  87. <!-- 国际化 -->
  88. <el-dropdown v-if="swEnable" id="header-translation" trigger="click">
  89. <GlobalizationIcon
  90. class="navbar-bg-hover w-[40px] h-[48px] p-[11px] cursor-pointer outline-hidden"
  91. />
  92. <template #dropdown>
  93. <el-dropdown-menu class="translation">
  94. <el-dropdown-item
  95. :style="getDropdownItemStyle(locale, 'zh')"
  96. :class="['dark:text-white!', getDropdownItemClass(locale, 'zh')]"
  97. @click="translationCh"
  98. >
  99. <span v-show="locale === 'zh'" class="check-zh">
  100. <IconifyIconOffline :icon="Check" />
  101. </span>
  102. 简体中文
  103. </el-dropdown-item>
  104. <el-dropdown-item
  105. :style="getDropdownItemStyle(locale, 'en')"
  106. :class="['dark:text-white!', getDropdownItemClass(locale, 'en')]"
  107. @click="translationEn"
  108. >
  109. <span v-show="locale === 'en'" class="check-en">
  110. <IconifyIconOffline :icon="Check" />
  111. </span>
  112. English
  113. </el-dropdown-item>
  114. </el-dropdown-menu>
  115. </template>
  116. </el-dropdown>
  117. <!-- 全屏 -->
  118. <LaySidebarFullScreen id="full-screen" />
  119. <!-- 消息通知 -->
  120. <LayNotice v-if="swEnable" id="header-notice" />
  121. <!-- 退出登录 -->
  122. <el-dropdown trigger="click">
  123. <span class="el-dropdown-link navbar-bg-hover">
  124. <img :src="userAvatar" :style="avatarsStyle" />
  125. <p v-if="uid" class="dark:text-white">{{ uid }}</p>
  126. </span>
  127. <template #dropdown>
  128. <!-- <el-dropdown-item @click="toAccountSettings">
  129. <IconifyIconOffline
  130. :icon="AccountSettingsIcon"
  131. style="margin: 5px"
  132. />
  133. {{ t("buttons.pureAccountSettings") }}
  134. </el-dropdown-item> -->
  135. <el-dropdown-menu class="logout">
  136. <el-dropdown-item @click="logout">
  137. <IconifyIconOffline
  138. :icon="LogoutCircleRLine"
  139. style="margin: 5px"
  140. />
  141. {{ t("buttons.pureLoginOut") }}
  142. </el-dropdown-item>
  143. </el-dropdown-menu>
  144. </template>
  145. </el-dropdown>
  146. <span
  147. class="set-icon navbar-bg-hover"
  148. :title="t('buttons.pureOpenSystemSet')"
  149. @click="onPanel"
  150. >
  151. <IconifyIconOffline :icon="Setting" />
  152. </span>
  153. </div>
  154. </div>
  155. </template>
  156. <style lang="scss" scoped>
  157. :deep(.el-loading-mask) {
  158. opacity: 0.45;
  159. }
  160. .translation {
  161. ::v-deep(.el-dropdown-menu__item) {
  162. padding: 5px 40px;
  163. }
  164. .check-zh {
  165. position: absolute;
  166. left: 20px;
  167. }
  168. .check-en {
  169. position: absolute;
  170. left: 20px;
  171. }
  172. }
  173. .logout {
  174. width: 120px;
  175. ::v-deep(.el-dropdown-menu__item) {
  176. display: inline-flex;
  177. flex-wrap: wrap;
  178. min-width: 100%;
  179. }
  180. }
  181. </style>