navbar.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <script setup lang="ts">
  2. import { computed } from "vue";
  3. import { useI18n } from "vue-i18n";
  4. import { emitter } from "/@/utils/mitt";
  5. import Notice from "./notice/index.vue";
  6. import avatars from "/@/assets/avatars.jpg";
  7. import { transformI18n } from "/@/plugins/i18n";
  8. import Hamburger from "./sidebar/hamBurger.vue";
  9. import { useRouter, useRoute } from "vue-router";
  10. import { storageSession } from "/@/utils/storage";
  11. import Breadcrumb from "./sidebar/breadCrumb.vue";
  12. import { useAppStoreHook } from "/@/store/modules/app";
  13. import { unref, watch, getCurrentInstance } from "vue";
  14. import { deviceDetection } from "/@/utils/deviceDetection";
  15. import screenfull from "../components/screenfull/index.vue";
  16. import globalization from "/@/assets/svg/globalization.svg";
  17. const instance =
  18. getCurrentInstance().appContext.config.globalProperties.$storage;
  19. const pureApp = useAppStoreHook();
  20. const router = useRouter();
  21. const route = useRoute();
  22. let usename = storageSession.getItem("info")?.username;
  23. const { locale } = useI18n();
  24. const getDropdownItemStyle = computed(() => {
  25. return t => {
  26. return {
  27. background: locale.value === t ? "#1b2a47" : "",
  28. color: locale.value === t ? "#f4f4f5" : "#000"
  29. };
  30. };
  31. });
  32. watch(
  33. () => locale.value,
  34. () => {
  35. //@ts-ignore
  36. document.title = transformI18n(
  37. //@ts-ignore
  38. unref(route.meta.title),
  39. unref(route.meta.i18n)
  40. ); // 动态title
  41. }
  42. );
  43. // 退出登录
  44. const logout = (): void => {
  45. storageSession.removeItem("info");
  46. router.push("/login");
  47. };
  48. function onPanel() {
  49. emitter.emit("openPanel");
  50. }
  51. function toggleSideBar() {
  52. pureApp.toggleSideBar();
  53. }
  54. // 简体中文
  55. function translationCh() {
  56. instance.locale = { locale: "zh" };
  57. locale.value = "zh";
  58. }
  59. // English
  60. function translationEn() {
  61. instance.locale = { locale: "en" };
  62. locale.value = "en";
  63. }
  64. </script>
  65. <template>
  66. <div class="navbar">
  67. <Hamburger
  68. :is-active="pureApp.sidebar.opened"
  69. class="hamburger-container"
  70. @toggleClick="toggleSideBar"
  71. />
  72. <Breadcrumb class="breadcrumb-container" />
  73. <div class="vertical-header-right">
  74. <!-- 通知 -->
  75. <Notice id="header-notice" />
  76. <!-- 全屏 -->
  77. <screenfull id="header-screenfull" v-show="!deviceDetection()" />
  78. <!-- 国际化 -->
  79. <el-dropdown id="header-translation" trigger="click">
  80. <globalization />
  81. <template #dropdown>
  82. <el-dropdown-menu class="translation">
  83. <el-dropdown-item
  84. :style="getDropdownItemStyle('zh')"
  85. @click="translationCh"
  86. ><el-icon class="check-zh" v-show="locale === 'zh'"
  87. ><check /></el-icon
  88. >简体中文</el-dropdown-item
  89. >
  90. <el-dropdown-item
  91. :style="getDropdownItemStyle('en')"
  92. @click="translationEn"
  93. ><el-icon class="check-en" v-show="locale === 'en'"
  94. ><check /></el-icon
  95. >English</el-dropdown-item
  96. >
  97. </el-dropdown-menu>
  98. </template>
  99. </el-dropdown>
  100. <!-- 退出登陆 -->
  101. <el-dropdown trigger="click">
  102. <span class="el-dropdown-link">
  103. <img :src="avatars" />
  104. <p>{{ usename }}</p>
  105. </span>
  106. <template #dropdown>
  107. <el-dropdown-menu class="logout">
  108. <el-dropdown-item @click="logout">
  109. <i class="ri-logout-circle-r-line"></i
  110. >{{ $t("buttons.hsLoginOut") }}</el-dropdown-item
  111. >
  112. </el-dropdown-menu>
  113. </template>
  114. </el-dropdown>
  115. <el-icon
  116. class="el-icon-setting"
  117. :title="$t('buttons.hssystemSet')"
  118. @click="onPanel"
  119. >
  120. <Setting />
  121. </el-icon>
  122. </div>
  123. </div>
  124. </template>
  125. <style lang="scss" scoped>
  126. .navbar {
  127. width: 100%;
  128. height: 48px;
  129. overflow: hidden;
  130. background: #fff;
  131. box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  132. .hamburger-container {
  133. line-height: 48px;
  134. height: 100%;
  135. float: left;
  136. cursor: pointer;
  137. transition: background 0.3s;
  138. -webkit-tap-highlight-color: transparent;
  139. &:hover {
  140. background: rgba(0, 0, 0, 0.025);
  141. }
  142. }
  143. .vertical-header-right {
  144. display: flex;
  145. min-width: 280px;
  146. height: 48px;
  147. align-items: center;
  148. color: #000000d9;
  149. justify-content: flex-end;
  150. :deep(.dropdown-badge) {
  151. &:hover {
  152. background: #f6f6f6;
  153. }
  154. }
  155. .screen-full {
  156. cursor: pointer;
  157. &:hover {
  158. background: #f6f6f6;
  159. }
  160. }
  161. .globalization {
  162. height: 48px;
  163. width: 40px;
  164. padding: 11px;
  165. cursor: pointer;
  166. &:hover {
  167. background: #f6f6f6;
  168. }
  169. }
  170. .el-dropdown-link {
  171. width: 100px;
  172. height: 48px;
  173. padding: 10px;
  174. display: flex;
  175. align-items: center;
  176. justify-content: space-around;
  177. cursor: pointer;
  178. color: #000000d9;
  179. &:hover {
  180. background: #f6f6f6;
  181. }
  182. p {
  183. font-size: 14px;
  184. }
  185. img {
  186. width: 22px;
  187. height: 22px;
  188. border-radius: 50%;
  189. }
  190. }
  191. .el-icon-setting {
  192. height: 48px;
  193. width: 38px;
  194. padding: 12px;
  195. display: flex;
  196. cursor: pointer;
  197. align-items: center;
  198. &:hover {
  199. background: #f6f6f6;
  200. }
  201. }
  202. }
  203. .breadcrumb-container {
  204. float: left;
  205. }
  206. }
  207. .translation {
  208. .el-dropdown-menu__item {
  209. padding: 0 40px !important;
  210. }
  211. .el-dropdown-menu__item:focus,
  212. .el-dropdown-menu__item:not(.is-disabled):hover {
  213. color: #606266;
  214. background: #f0f0f0;
  215. }
  216. .check-zh {
  217. position: absolute;
  218. left: 20px;
  219. top: 13px;
  220. }
  221. .check-en {
  222. position: absolute;
  223. bottom: 13px;
  224. left: 20px;
  225. }
  226. }
  227. .logout {
  228. max-width: 120px;
  229. .el-dropdown-menu__item {
  230. min-width: 100%;
  231. display: inline-flex;
  232. flex-wrap: wrap;
  233. padding: 0 18px !important;
  234. }
  235. .el-dropdown-menu__item:focus,
  236. .el-dropdown-menu__item:not(.is-disabled):hover {
  237. color: #606266;
  238. background: #f0f0f0;
  239. }
  240. }
  241. </style>