horizontal.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <script setup lang="ts">
  2. import { useI18n } from "vue-i18n";
  3. import { useNav } from "../../hooks/nav";
  4. import Search from "../search/index.vue";
  5. import Notice from "../notice/index.vue";
  6. import { templateRef } from "@vueuse/core";
  7. import SidebarItem from "./sidebarItem.vue";
  8. import avatars from "/@/assets/avatars.jpg";
  9. import screenfull from "../screenfull/index.vue";
  10. import { useRoute, useRouter } from "vue-router";
  11. import { deviceDetection } from "/@/utils/deviceDetection";
  12. import { watch, nextTick, onMounted, getCurrentInstance } from "vue";
  13. import { usePermissionStoreHook } from "/@/store/modules/permission";
  14. import globalization from "/@/assets/svg/globalization.svg?component";
  15. const route = useRoute();
  16. const { locale, t } = useI18n();
  17. const routers = useRouter().options.routes;
  18. const menuRef = templateRef<ElRef | null>("menu", null);
  19. const instance =
  20. getCurrentInstance().appContext.config.globalProperties.$storage;
  21. const title =
  22. getCurrentInstance().appContext.config.globalProperties.$config?.Title;
  23. const {
  24. logout,
  25. backHome,
  26. onPanel,
  27. changeTitle,
  28. handleResize,
  29. menuSelect,
  30. usename,
  31. getDropdownItemStyle
  32. } = useNav();
  33. onMounted(() => {
  34. nextTick(() => {
  35. handleResize(menuRef.value);
  36. });
  37. });
  38. watch(
  39. () => locale.value,
  40. () => {
  41. changeTitle(route.meta);
  42. }
  43. );
  44. watch(
  45. () => route.path,
  46. () => {
  47. menuSelect(route.path, routers);
  48. }
  49. );
  50. function translationCh() {
  51. instance.locale = { locale: "zh" };
  52. locale.value = "zh";
  53. handleResize(menuRef.value);
  54. }
  55. function translationEn() {
  56. instance.locale = { locale: "en" };
  57. locale.value = "en";
  58. handleResize(menuRef.value);
  59. }
  60. </script>
  61. <template>
  62. <div class="horizontal-header">
  63. <div class="horizontal-header-left" @click="backHome">
  64. <FontIcon icon="team-iconlogo" svg style="width: 35px; height: 35px" />
  65. <h4>{{ title }}</h4>
  66. </div>
  67. <el-menu
  68. ref="menu"
  69. class="horizontal-header-menu"
  70. mode="horizontal"
  71. :default-active="route.path"
  72. router
  73. @select="indexPath => menuSelect(indexPath, routers)"
  74. >
  75. <sidebar-item
  76. v-for="route in usePermissionStoreHook().wholeMenus"
  77. :key="route.path"
  78. :item="route"
  79. :base-path="route.path"
  80. />
  81. </el-menu>
  82. <div class="horizontal-header-right">
  83. <!-- 菜单搜索 -->
  84. <Search />
  85. <!-- 通知 -->
  86. <Notice id="header-notice" />
  87. <!-- 全屏 -->
  88. <screenfull id="header-screenfull" v-show="!deviceDetection()" />
  89. <!-- 国际化 -->
  90. <el-dropdown id="header-translation" trigger="click">
  91. <globalization />
  92. <template #dropdown>
  93. <el-dropdown-menu class="translation">
  94. <el-dropdown-item
  95. :style="getDropdownItemStyle(locale, 'zh')"
  96. @click="translationCh"
  97. ><el-icon class="check-zh" v-show="locale === 'zh'"
  98. ><IconifyIconOffline icon="check" /></el-icon
  99. >简体中文</el-dropdown-item
  100. >
  101. <el-dropdown-item
  102. :style="getDropdownItemStyle(locale, 'en')"
  103. @click="translationEn"
  104. ><el-icon class="check-en" v-show="locale === 'en'"
  105. ><IconifyIconOffline icon="check" /></el-icon
  106. >English</el-dropdown-item
  107. >
  108. </el-dropdown-menu>
  109. </template>
  110. </el-dropdown>
  111. <!-- 退出登陆 -->
  112. <el-dropdown trigger="click">
  113. <span class="el-dropdown-link">
  114. <img :src="avatars" />
  115. <p>{{ usename }}</p>
  116. </span>
  117. <template #dropdown>
  118. <el-dropdown-menu class="logout">
  119. <el-dropdown-item @click="logout">
  120. <IconifyIconOffline
  121. icon="logout-circle-r-line"
  122. style="margin: 5px"
  123. />
  124. {{ t("buttons.hsLoginOut") }}</el-dropdown-item
  125. >
  126. </el-dropdown-menu>
  127. </template>
  128. </el-dropdown>
  129. <el-icon
  130. class="el-icon-setting"
  131. :title="t('buttons.hssystemSet')"
  132. @click="onPanel"
  133. >
  134. <IconifyIconOffline icon="setting" />
  135. </el-icon>
  136. </div>
  137. </div>
  138. </template>
  139. <style lang="scss" scoped>
  140. .translation {
  141. ::v-deep(.el-dropdown-menu__item) {
  142. padding: 5px 40px;
  143. }
  144. .check-zh {
  145. position: absolute;
  146. left: 20px;
  147. }
  148. .check-en {
  149. position: absolute;
  150. left: 20px;
  151. }
  152. }
  153. .logout {
  154. max-width: 120px;
  155. ::v-deep(.el-dropdown-menu__item) {
  156. min-width: 100%;
  157. display: inline-flex;
  158. flex-wrap: wrap;
  159. }
  160. }
  161. </style>