Navbar.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div class="navbar">
  3. <Hamburger
  4. :is-active="pureApp.sidebar.opened"
  5. class="hamburger-container"
  6. @toggleClick="toggleSideBar"
  7. />
  8. <Breadcrumb class="breadcrumb-container" />
  9. <div class="right-menu">
  10. <!-- 全屏 -->
  11. <screenfull v-show="!deviceDetection()" />
  12. <!-- 国际化 -->
  13. <div
  14. v-show="!deviceDetection()"
  15. class="inter"
  16. :title="langs ? '中文' : 'English'"
  17. @click="toggleLang"
  18. >
  19. <img :src="langs ? ch : en" />
  20. </div>
  21. <i
  22. class="el-icon-setting hsset"
  23. :title="$t('message.hssystemSet')"
  24. @click="onPanel"
  25. ></i>
  26. <!-- 退出登陆 -->
  27. <el-dropdown trigger="click">
  28. <span class="el-dropdown-link">
  29. <img :src="favicon" />
  30. <p>{{ usename }}</p>
  31. </span>
  32. <template #dropdown>
  33. <el-dropdown-menu>
  34. <el-dropdown-item icon="el-icon-switch-button" @click="logout">{{
  35. $t("message.hsLoginOut")
  36. }}</el-dropdown-item>
  37. </el-dropdown-menu>
  38. </template>
  39. </el-dropdown>
  40. </div>
  41. </div>
  42. </template>
  43. <script lang="ts">
  44. import { ref, defineComponent, onMounted, unref, watch } from "vue";
  45. import Breadcrumb from "/@/components/ReBreadCrumb";
  46. import Hamburger from "/@/components/ReHamBurger";
  47. import screenfull from "../components/screenfull/index.vue";
  48. import { useRouter, useRoute } from "vue-router";
  49. import { useAppStoreHook } from "/@/store/modules/app";
  50. import { storageSession } from "/@/utils/storage";
  51. import ch from "/@/assets/ch.png";
  52. import en from "/@/assets/en.png";
  53. import favicon from "/favicon.ico";
  54. import { emitter } from "/@/utils/mitt";
  55. import { deviceDetection } from "/@/utils/deviceDetection";
  56. import { useI18n } from "vue-i18n";
  57. import ElementLocale from "element-plus/lib/locale";
  58. import enLocale from "element-plus/lib/locale/lang/en";
  59. import zhLocale from "element-plus/lib/locale/lang/zh-cn";
  60. export default defineComponent({
  61. name: "Navbar",
  62. components: {
  63. Breadcrumb,
  64. Hamburger,
  65. screenfull
  66. },
  67. setup() {
  68. let langs = ref(true);
  69. const pureApp = useAppStoreHook();
  70. const router = useRouter();
  71. const route = useRoute();
  72. let usename = storageSession.getItem("info")?.username;
  73. const { locale, t } = useI18n();
  74. // 国际化语言切换
  75. const toggleLang = (): void => {
  76. langs.value = !langs.value;
  77. if (langs.value) {
  78. locale.value = "zh";
  79. ElementLocale.use(zhLocale);
  80. } else {
  81. locale.value = "en";
  82. ElementLocale.use(enLocale);
  83. }
  84. };
  85. watch(
  86. () => langs.value,
  87. () => {
  88. //@ts-ignore
  89. document.title = t(unref(route.meta.title)); // 动态title
  90. }
  91. );
  92. // 退出登录
  93. const logout = (): void => {
  94. storageSession.removeItem("info");
  95. router.push("/login");
  96. };
  97. function onPanel() {
  98. emitter.emit("openPanel");
  99. }
  100. function toggleSideBar() {
  101. pureApp.toggleSideBar();
  102. }
  103. onMounted(() => {
  104. document
  105. .querySelector(".el-dropdown__popper")
  106. ?.setAttribute("class", "resetTop");
  107. document
  108. .querySelector(".el-popper__arrow")
  109. ?.setAttribute("class", "hidden");
  110. });
  111. return {
  112. pureApp,
  113. toggleSideBar,
  114. langs,
  115. usename,
  116. toggleLang,
  117. logout,
  118. ch,
  119. en,
  120. favicon,
  121. onPanel,
  122. deviceDetection,
  123. locale,
  124. t
  125. };
  126. }
  127. });
  128. </script>
  129. <style lang="scss" scoped>
  130. .navbar {
  131. width: 100%;
  132. height: 50px;
  133. overflow: hidden;
  134. background: #fff;
  135. box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  136. .hamburger-container {
  137. line-height: 46px;
  138. height: 100%;
  139. float: left;
  140. cursor: pointer;
  141. transition: background 0.3s;
  142. -webkit-tap-highlight-color: transparent;
  143. &:hover {
  144. background: rgba(0, 0, 0, 0.025);
  145. }
  146. }
  147. .breadcrumb-container {
  148. float: left;
  149. }
  150. .right-menu {
  151. position: absolute;
  152. right: 0;
  153. display: flex;
  154. align-items: center;
  155. height: 48px;
  156. line-height: 48px;
  157. .inter {
  158. width: 40px;
  159. height: 48px;
  160. display: flex;
  161. align-items: center;
  162. justify-content: space-around;
  163. &:hover {
  164. cursor: pointer;
  165. background: #f0f0f0;
  166. }
  167. img {
  168. width: 25px;
  169. }
  170. }
  171. .hsset {
  172. width: 40px;
  173. height: 48px;
  174. display: flex;
  175. align-items: center;
  176. justify-content: space-around;
  177. margin-right: 5px;
  178. &:hover {
  179. cursor: pointer;
  180. background: #f0f0f0;
  181. }
  182. }
  183. .el-dropdown-link {
  184. width: 70px;
  185. display: flex;
  186. align-items: center;
  187. justify-content: space-around;
  188. margin-right: 10px;
  189. cursor: pointer;
  190. p {
  191. font-size: 14px;
  192. }
  193. img {
  194. width: 22px;
  195. height: 22px;
  196. }
  197. }
  198. }
  199. }
  200. // single element-plus reset
  201. .el-dropdown-menu__item {
  202. padding: 0 10px;
  203. }
  204. .el-dropdown-menu {
  205. padding: 6px 0;
  206. }
  207. .el-dropdown-menu__item:focus,
  208. .el-dropdown-menu__item:not(.is-disabled):hover {
  209. color: #606266;
  210. background: #f0f0f0;
  211. }
  212. </style>