Navbar.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div class="navbar">
  3. <div class="left-menu">
  4. <hamburger
  5. :is-active="sidebar.opened"
  6. class="hamburger-container"
  7. @toggleClick="toggleSideBar"
  8. />
  9. </div>
  10. <h3 class="tmrTitle">{{$t('navbar.title')}}</h3>
  11. <div class="right-menu">
  12. <!-- <search id="header-search" class="right-menu-item" />-->
  13. <!--<screenfull id="screenfull" class="right-menu-item hover-effect" /> -->
  14. <!-- <el-dropdown id="news" class="avatar-container" trigger="click">
  15. <span class="right-menu-news">
  16. <svg-icon class="right-menu-news-icon" :icon-class="'icon-news'" />
  17. <i class="right-menu-news-right">{{ sumAmount }}</i>
  18. </span>
  19. <el-dropdown-menu slot="dropdown" class="user-dropdown">
  20. <div class="newsTitle" style="padding-left: 10px">
  21. 消息通知
  22. </div>
  23. <el-dropdown-item v-for="(item,index) in meslist" :key="index" divided>
  24. <span style="display:block;" @click="clickList(item)"><span style="margin-right:30px;">{{ item.remark }}</span><span style="float:right;">{{ item.mesTime }}</span></span>
  25. </el-dropdown-item>
  26. <router-link to="/console/News">
  27. <el-dropdown-item style="text-align:center;margin-top:10px;">
  28. 查看全部
  29. </el-dropdown-item>
  30. </router-link>
  31. </el-dropdown-menu>
  32. </el-dropdown> -->
  33. <!-- 切换中英文 -->
  34. <!-- <el-switch
  35. class="swichs"
  36. v-model="langValue"
  37. :active-text="active_text"
  38. :inactive-text="inactive_text"
  39. active-color="#13ce66"
  40. inactive-color="#ff4949"
  41. @change="translate"
  42. ></el-switch> -->
  43. <el-dropdown class="avatar-container" trigger="click">
  44. <div class="avatar-wrapper">
  45. <!-- <img src="@/assets/cow.jpg" class="user-avatar"> -->
  46. <span style="font-size: 12px; color: #fff"
  47. >{{$t('navbar.Welcome')}} , {{ employename }}</span
  48. >
  49. <i class="el-icon-caret-bottom" style="color: #fff" />
  50. </div>
  51. <el-dropdown-menu slot="dropdown" class="user-dropdown">
  52. <router-link to="/">
  53. <el-dropdown-item> {{$t('navbar.homePage')}} </el-dropdown-item>
  54. </router-link>
  55. <el-dropdown-item divided>
  56. <span style="display: block" @click="logout">{{$t('navbar.singOUt')}}</span>
  57. </el-dropdown-item>
  58. <router-link to="/changpwd/Changpwd">
  59. <el-dropdown-item> {{$t('navbar.editPassword')}} </el-dropdown-item>
  60. </router-link>
  61. </el-dropdown-menu>
  62. </el-dropdown>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. // import { GetDataByName } from '@/api/common'
  68. import { mapGetters } from 'vuex'
  69. import Hamburger from '@/components/Hamburger'
  70. // import Screenfull from '@/components/Screenfull'
  71. // import Search from '@/components/HeaderSearch'
  72. // import path from 'path'
  73. // import Cookies from 'js-cookie'
  74. export default {
  75. components: {
  76. Hamburger
  77. // Screenfull,
  78. // Search
  79. },
  80. data() {
  81. return {
  82. sumAmount: '',
  83. meslist: '',
  84. langValue: false,
  85. lang: '',
  86. active_text: '',
  87. inactive_text: ''
  88. }
  89. },
  90. computed: {
  91. ...mapGetters([
  92. 'sidebar',
  93. 'avatar',
  94. 'employename',
  95. 'employeid',
  96. 'pastureid',
  97. 'departmentid',
  98. 'sumamount'
  99. ])
  100. },
  101. created() {
  102. this.setSwitch()
  103. // window.setInterval(() => {
  104. // setTimeout(() => {
  105. // this.sumAmount = JSON.parse(sessionStorage.sumamount)
  106. // this.meslist = JSON.parse(sessionStorage.meslist)
  107. // }, 0)
  108. // }, 100)
  109. },
  110. methods: {
  111. // 切换中英文
  112. setSwitch() {
  113. this.active_text = navigator.language === 'zh' ? '英文' : '中文'
  114. this.inactive_text = navigator.language === 'zh' ? '中文' : '英文'
  115. this.lang = navigator.language
  116. },
  117. // 切换调用
  118. translate() {
  119. this.lang = this.lang === 'zh' ? 'en' : 'zh'
  120. console.log(this.lang)
  121. this.$i18n.locale = this.lang
  122. },
  123. toggleSideBar() {
  124. this.$store.dispatch('app/toggleSideBar')
  125. },
  126. async logout() {
  127. await this.$store.dispatch('user/logout')
  128. this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => {
  129. this.$router.push(`/login}`) // 跳转到主页
  130. })
  131. // this.$router.push(`/login?redirect=${this.$route.fullPath}`) //跳转到登陆前页面
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .swichs {
  138. padding: 0 20px;
  139. color: #fff;
  140. }
  141. .navbar {
  142. height: 50px;
  143. overflow: hidden;
  144. position: relative;
  145. background: url(../../assets/images/index/topBg.png);
  146. box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  147. .tmrTitle {
  148. color: #fff;
  149. float: left;
  150. }
  151. .hamburger-container {
  152. line-height: 46px;
  153. height: 100%;
  154. float: left;
  155. cursor: pointer;
  156. color: #fff !important;
  157. transition: background 0.3s;
  158. -webkit-tap-highlight-color: transparent;
  159. &:hover {
  160. background: rgba(255, 255, 255, 0.025);
  161. }
  162. }
  163. h3 {
  164. margin-top: 11px;
  165. }
  166. .breadcrumb-container {
  167. float: left;
  168. }
  169. .right-menu {
  170. float: right;
  171. height: 100%;
  172. line-height: 50px;
  173. &:focus {
  174. outline: none;
  175. }
  176. .right-menu-item {
  177. display: inline-block;
  178. padding: 0 8px;
  179. height: 100%;
  180. font-size: 18px;
  181. color: #5a5e66;
  182. vertical-align: text-bottom;
  183. &.hover-effect {
  184. cursor: pointer;
  185. transition: background 0.3s;
  186. &:hover {
  187. background: rgba(0, 0, 0, 0.025);
  188. }
  189. }
  190. }
  191. .avatar-container {
  192. margin-right: 30px;
  193. .avatar-wrapper {
  194. margin-top: 5px;
  195. position: relative;
  196. .user-avatar {
  197. cursor: pointer;
  198. width: 40px;
  199. height: 40px;
  200. border-radius: 10px;
  201. }
  202. .el-icon-caret-bottom {
  203. cursor: pointer;
  204. position: absolute;
  205. right: -20px;
  206. top: 18px;
  207. font-size: 12px;
  208. }
  209. }
  210. }
  211. .right-menu-news {
  212. margin-right: 25px;
  213. position: relative;
  214. .right-menu-news-icon {
  215. display: block;
  216. float: left;
  217. width: 25px;
  218. height: 40px;
  219. }
  220. .right-menu-news-right {
  221. display: block;
  222. width: 20px;
  223. height: 20px;
  224. float: left;
  225. border-radius: 10px;
  226. background: red;
  227. font-style: normal;
  228. position: absolute;
  229. right: -12px;
  230. bottom: 25px;
  231. font-weight: 300;
  232. font-size: 12px;
  233. line-height: 20px;
  234. text-align: center;
  235. color: #fff;
  236. }
  237. }
  238. }
  239. }
  240. </style>
  241. <style lang="scss" >
  242. .user-dropdown {
  243. top: 40px !important;
  244. color: #fff !important;
  245. }
  246. </style>