Navbar.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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="this.$t('action.FontSize')" 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="syncHis">
  47. <span style="display:block;">{{ this.$t("action.SynchronizeHISInformation") }}</span>
  48. </el-dropdown-item>
  49. <el-dropdown-item divided @click.native="logout">
  50. <span style="display:block;">{{ this.$t("action.logout") }}</span>
  51. </el-dropdown-item>
  52. </el-dropdown-menu>
  53. </el-dropdown>
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. import { mapGetters } from 'vuex'
  59. import Breadcrumb from '@/components/Breadcrumb'
  60. import Hamburger from '@/components/Hamburger'
  61. import ErrorLog from '@/components/ErrorLog'
  62. import Screenfull from '@/components/Screenfull'
  63. import SizeSelect from '@/components/SizeSelect'
  64. import Search from '@/components/HeaderSearch'
  65. import avator from '@/assets/avatar.jpeg'
  66. import * as API_Part from '@/api/calling-part'
  67. import Storage from '@/utils/storage'
  68. export default {
  69. components: {
  70. Breadcrumb,
  71. Hamburger,
  72. ErrorLog,
  73. Screenfull,
  74. SizeSelect,
  75. Search
  76. },
  77. data() {
  78. return {
  79. avator: avator,
  80. licence: '',
  81. value: this.$i18n.locale,
  82. language: [
  83. {
  84. value: 'en',
  85. label: 'English'
  86. },
  87. {
  88. value: 'zh',
  89. label: '中文简体'
  90. },{
  91. value: 'es',
  92. label: 'Español'
  93. }
  94. ]
  95. }
  96. },
  97. computed: {
  98. ...mapGetters([
  99. 'sidebar',
  100. // 'avatar',
  101. 'device'
  102. ]),
  103. partInfo() {
  104. return this.$store.getters.organization
  105. }
  106. },
  107. mounted() {
  108. if (Number(this.$store.getters.partId) > 0) {
  109. API_Part.getExpire().then(res => {
  110. if (res.timeout === 'nolimit') {
  111. this.licence = this.$t('action.perpetualLicence')
  112. } else {
  113. const days = Math.floor(((Number(res.timeout) * 1000) - new Date()) / (1000 * 60 * 60 * 24))
  114. if (days > 30) {
  115. this.licence = this.$t('action.licenseValidity') + new Date((Number(res.timeout) * 1000)).toLocaleString()
  116. } else {
  117. this.licence = this.$t('action.licenseRemainsValid') + days + this.$t('action.getLicense')
  118. }
  119. }
  120. }).catch(err => {
  121. this.$message.error(err)
  122. })
  123. }
  124. },
  125. methods: {
  126. toggleSideBar() {
  127. this.$store.dispatch('app/toggleSideBar')
  128. },
  129. syncHis() {
  130. API_Part.syncHis().then(res => {
  131. this.$message({
  132. type: 'success',
  133. message: this.$t("action.SynchronizeHISInformation")
  134. })
  135. })
  136. },
  137. async logout() {
  138. await this.$store.dispatch('user/logout')
  139. this.$store.dispatch('permission/removeRoutes')
  140. console.log('hello')
  141. this.$router.push(`/login?redirect=${this.$route.fullPath}`)
  142. },
  143. switchLanguage(value) {
  144. if (value === 'zh') {
  145. this.$i18n.locale = 'zh'
  146. } else if (value === 'en') {
  147. this.$i18n.locale = 'en'
  148. } else if (value === 'es') {
  149. this.$i18n.locale = 'es'
  150. }
  151. // 在选择了显示的语言后,将配置保存到缓存里
  152. Storage.setItem('DefaultLanguage', value)
  153. // location.reload()
  154. this.$router.go(0)
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. .navbar {
  161. height: 50px;
  162. overflow: hidden;
  163. position: relative;
  164. background: #fff;
  165. box-shadow: 0 1px 4px rgba(0,21,41,.08);
  166. .hamburger-container {
  167. line-height: 46px;
  168. height: 100%;
  169. float: left;
  170. cursor: pointer;
  171. transition: background .3s;
  172. -webkit-tap-highlight-color:transparent;
  173. &:hover {
  174. background: rgba(0, 0, 0, .025)
  175. }
  176. }
  177. .breadcrumb-container {
  178. float: left;
  179. }
  180. .errLog-container {
  181. display: inline-block;
  182. vertical-align: top;
  183. }
  184. .right-menu {
  185. float: right;
  186. height: 100%;
  187. line-height: 50px;
  188. &:focus {
  189. outline: none;
  190. }
  191. .right-menu-item {
  192. display: inline-block;
  193. padding: 0 8px;
  194. height: 100%;
  195. font-size: 18px;
  196. color: #5a5e66;
  197. vertical-align: text-bottom;
  198. &.hover-effect {
  199. cursor: pointer;
  200. transition: background .3s;
  201. &:hover {
  202. background: rgba(0, 0, 0, .025)
  203. }
  204. }
  205. }
  206. .avatar-container {
  207. margin-right: 30px;
  208. .avatar-wrapper {
  209. margin-top: 5px;
  210. position: relative;
  211. .user-avatar {
  212. cursor: pointer;
  213. width: 40px;
  214. height: 40px;
  215. border-radius: 10px;
  216. }
  217. .el-icon-caret-bottom {
  218. cursor: pointer;
  219. position: absolute;
  220. right: -20px;
  221. top: 25px;
  222. font-size: 12px;
  223. }
  224. }
  225. }
  226. }
  227. }
  228. </style>