Navbar.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div class="navbar">
  3. <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
  4. <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
  5. <div class="right-menu">
  6. <template v-if="device!=='mobile'">
  7. <!-- <search id="header-search" class="right-menu-item" />-->
  8. <div class="right-menu-item" style="color: #409EFF">{{ partInfo.full_name }} {{ partInfo.part_name }}</div>
  9. <div class="right-menu-item" style="color: #ff4949;font-size: 14px">{{ licence }}</div>
  10. <error-log class="errLog-container right-menu-item hover-effect" />
  11. <screenfull id="screenfull" class="right-menu-item hover-effect" />
  12. <el-tooltip content="字体大小" effect="dark" placement="bottom">
  13. <size-select id="size-select" class="right-menu-item hover-effect" />
  14. </el-tooltip>
  15. </template>
  16. <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
  17. <div class="avatar-wrapper">
  18. <img :src="avator" class="user-avatar">
  19. <i class="el-icon-caret-bottom" />
  20. </div>
  21. <el-dropdown-menu slot="dropdown">
  22. <!-- <router-link to="/profile/index">-->
  23. <!-- <el-dropdown-item>Profile</el-dropdown-item>-->
  24. <!-- </router-link>-->
  25. <router-link to="/">
  26. <el-dropdown-item>{{ this.$t("action.home") }}</el-dropdown-item>
  27. </router-link>
  28. <!-- <a target="_blank" href="https://github.com/PanJiaChen/vue-element-admin/">-->
  29. <!-- <el-dropdown-item>Github</el-dropdown-item>-->
  30. <!-- </a>-->
  31. <!-- <a target="_blank" href="https://panjiachen.github.io/vue-element-admin-site/#/">-->
  32. <!-- <el-dropdown-item>Docs</el-dropdown-item>-->
  33. <!-- </a>-->
  34. <el-dropdown-item divided>
  35. <el-dropdown placement="right-start" @command="switchLanguage">
  36. <span class="el-dropdown-link">
  37. {{ this.$t("action.chooseLang") }}<i class="el-icon-arrow-right el-icon--right" />
  38. </span>
  39. <el-dropdown-menu slot="dropdown">
  40. <el-dropdown-item v-for="(value,index) in language" :key="index" :command="value.value">
  41. {{value.label}}
  42. </el-dropdown-item>
  43. </el-dropdown-menu>
  44. </el-dropdown>
  45. </el-dropdown-item>
  46. <el-dropdown-item divided @click.native="logout">
  47. <span style="display:block;">{{ this.$t("action.logout") }}</span>
  48. </el-dropdown-item>
  49. </el-dropdown-menu>
  50. </el-dropdown>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import { mapGetters } from 'vuex'
  56. import Breadcrumb from '@/components/Breadcrumb'
  57. import Hamburger from '@/components/Hamburger'
  58. import ErrorLog from '@/components/ErrorLog'
  59. import Screenfull from '@/components/Screenfull'
  60. import SizeSelect from '@/components/SizeSelect'
  61. import Search from '@/components/HeaderSearch'
  62. import avator from '@/assets/avatar.jpeg'
  63. import * as API_Part from '@/api/calling-part'
  64. import Storage from '@/utils/storage'
  65. export default {
  66. components: {
  67. Breadcrumb,
  68. Hamburger,
  69. ErrorLog,
  70. Screenfull,
  71. SizeSelect,
  72. Search
  73. },
  74. data() {
  75. return {
  76. avator: avator,
  77. licence: '',
  78. value: this.$i18n.locale,
  79. language: [
  80. {
  81. value: 'en',
  82. label: 'English'
  83. },
  84. {
  85. value: 'zh',
  86. label: '中文简体'
  87. }
  88. ]
  89. }
  90. },
  91. computed: {
  92. ...mapGetters([
  93. 'sidebar',
  94. // 'avatar',
  95. 'device'
  96. ]),
  97. partInfo() {
  98. return this.$store.getters.organization
  99. }
  100. },
  101. mounted() {
  102. if (Number(this.$store.getters.partId) > 0) {
  103. API_Part.getExpire().then(res => {
  104. if (res.timeout === 'nolimit') {
  105. this.licence = this.$t('action.perpetualLicence')
  106. } else {
  107. const days = Math.floor(((Number(res.timeout) * 1000) - new Date()) / (1000 * 60 * 60 * 24))
  108. if (days > 30) {
  109. this.licence = this.$t('action.licenseValidity') + new Date((Number(res.timeout) * 1000)).toLocaleString()
  110. } else {
  111. this.licence = this.$t('action.licenseRemainsValid') + days + this.$t('action.getLicense')
  112. }
  113. }
  114. }).catch(err => {
  115. this.$message.error(err)
  116. })
  117. }
  118. },
  119. methods: {
  120. toggleSideBar() {
  121. this.$store.dispatch('app/toggleSideBar')
  122. },
  123. async logout() {
  124. await this.$store.dispatch('user/logout')
  125. this.$store.dispatch('permission/removeRoutes')
  126. console.log('hello')
  127. this.$router.push(`/login?redirect=${this.$route.fullPath}`)
  128. },
  129. switchLanguage(value) {
  130. if (value === 'zh') {
  131. this.$i18n.locale = 'zh'
  132. } else if (value === 'en') {
  133. this.$i18n.locale = 'en'
  134. }
  135. // 在选择了显示的语言后,将配置保存到缓存里
  136. Storage.setItem('DefaultLanguage', value)
  137. // location.reload()
  138. this.$router.go(0)
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. .navbar {
  145. height: 50px;
  146. overflow: hidden;
  147. position: relative;
  148. background: #fff;
  149. box-shadow: 0 1px 4px rgba(0,21,41,.08);
  150. .hamburger-container {
  151. line-height: 46px;
  152. height: 100%;
  153. float: left;
  154. cursor: pointer;
  155. transition: background .3s;
  156. -webkit-tap-highlight-color:transparent;
  157. &:hover {
  158. background: rgba(0, 0, 0, .025)
  159. }
  160. }
  161. .breadcrumb-container {
  162. float: left;
  163. }
  164. .errLog-container {
  165. display: inline-block;
  166. vertical-align: top;
  167. }
  168. .right-menu {
  169. float: right;
  170. height: 100%;
  171. line-height: 50px;
  172. &:focus {
  173. outline: none;
  174. }
  175. .right-menu-item {
  176. display: inline-block;
  177. padding: 0 8px;
  178. height: 100%;
  179. font-size: 18px;
  180. color: #5a5e66;
  181. vertical-align: text-bottom;
  182. &.hover-effect {
  183. cursor: pointer;
  184. transition: background .3s;
  185. &:hover {
  186. background: rgba(0, 0, 0, .025)
  187. }
  188. }
  189. }
  190. .avatar-container {
  191. margin-right: 30px;
  192. .avatar-wrapper {
  193. margin-top: 5px;
  194. position: relative;
  195. .user-avatar {
  196. cursor: pointer;
  197. width: 40px;
  198. height: 40px;
  199. border-radius: 10px;
  200. }
  201. .el-icon-caret-bottom {
  202. cursor: pointer;
  203. position: absolute;
  204. right: -20px;
  205. top: 25px;
  206. font-size: 12px;
  207. }
  208. }
  209. }
  210. }
  211. }
  212. </style>