navbar.vue 5.9 KB

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