Navbar.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <div class="navbar">
  3. <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
  4. <breadcrumb class="breadcrumb-container" v-if="showBreadcrumb" />
  5. <!-- <NavMenu class="navmenu" /> -->
  6. <div class="right-menu">
  7. <div class="right-menu-item hover-effect">
  8. <el-tooltip effect="dark" content="工程机登录" placement="bottom">
  9. <a class="el-icon-s-platform" style="font-size: 24px; line-height: 50px;" href="https://mpkf.weixin.qq.com/" target="_blank"></a>
  10. </el-tooltip>
  11. </div>
  12. <el-badge :value="noticeCount" :max="10" :hidden="!noticeVisible" class="right-menu-item hover-effect">
  13. <el-tooltip effect="dark" content="系统消息" placement="bottom">
  14. <i class="el-icon-message-solid" @click="goNotice" style="font-size: 24px; line-height: 50px;"></i>
  15. </el-tooltip>
  16. <!-- <el-button icon="el-icon-message-solid" type="text" class="notice-icon" @click="goNotice"></el-button> -->
  17. </el-badge>
  18. <template v-if="device!=='mobile'">
  19. <screenfull id="screenfull" class="right-menu-item hover-effect" />
  20. </template>
  21. <el-dropdown class="user-container" trigger="click">
  22. <div class="user right-menu-item hover-effect">
  23. <i class="el-icon-user-solid"></i>
  24. <span>{{name}}</span>
  25. </div>
  26. <el-dropdown-menu slot="dropdown" class="user-dropdown">
  27. <router-link to="/setting/personal">
  28. <el-dropdown-item>个人信息</el-dropdown-item>
  29. </router-link>
  30. <el-dropdown-item divided @click.native="logout">
  31. <span style="display:block;">退出登录</span>
  32. </el-dropdown-item>
  33. </el-dropdown-menu>
  34. </el-dropdown>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. import { mapGetters } from 'vuex'
  40. import Breadcrumb from '@/components/Breadcrumb'
  41. import Hamburger from '@/components/Hamburger'
  42. import Screenfull from '@/components/Screenfull'
  43. import NavMenu from '@/components/NavMenu'
  44. import {getNoticeListCount} from "@/api/notice";
  45. export default {
  46. data() {
  47. return {
  48. timer: '',
  49. noticeCount: 0
  50. }
  51. },
  52. mounted() {
  53. const that = this
  54. // 开定时器轮询未读消息接口(写在全局vuex里比较好)
  55. that.initNotice()
  56. this.timer = setInterval(function () {
  57. that.initNotice()
  58. }, 3000)
  59. },
  60. beforeDestroy() {
  61. window.clearInterval(this.timer)
  62. console.log('退出清理定时器' + this.timer)
  63. },
  64. components: {
  65. Breadcrumb,
  66. Hamburger,
  67. Screenfull,
  68. NavMenu
  69. },
  70. computed: {
  71. showBreadcrumb() {
  72. return this.$store.state.settings.breadcrumb
  73. },
  74. noticeVisible() {
  75. return this.noticeCount > 0
  76. },
  77. ...mapGetters([
  78. 'sidebar',
  79. 'avatar',
  80. 'device',
  81. 'name'
  82. ])
  83. },
  84. methods: {
  85. toggleSideBar() {
  86. this.$store.dispatch('app/toggleSideBar')
  87. },
  88. async logout() {
  89. await this.$store.dispatch('user/logout')
  90. // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
  91. this.$router.push(`/login`)
  92. },
  93. initNotice() {
  94. getNoticeListCount().then(res => {
  95. if (res.data > 0 && this.noticeCount !== res.data) {
  96. this.noticeCount = res.data
  97. } else if (res.data === 0 && this.noticeCount !== res.data) {
  98. this.noticeCount = 0
  99. }
  100. })
  101. },
  102. goNotice() {
  103. this.$router.push('/notice/index')
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. @import "~@/styles/variables.scss";
  110. .navbar {
  111. width: 100%;
  112. height: 50px;
  113. overflow: hidden;
  114. background: #{$navbarBg};
  115. box-shadow: 0 1px 4px rgba(0,21,41,.08);
  116. .hamburger-container {
  117. line-height: 46px;
  118. height: 100%;
  119. color: #{$navbarText};
  120. float: left;
  121. cursor: pointer;
  122. transition: background .3s;
  123. -webkit-tap-highlight-color:transparent;
  124. border-right: 1px solid #eaeaea;
  125. &:hover {
  126. background: rgba(0, 0, 0, .025)
  127. }
  128. }
  129. .navmenu {
  130. float: left;
  131. }
  132. .breadcrumb-container {
  133. float: left;
  134. }
  135. .right-menu {
  136. float: right;
  137. height: 100%;
  138. line-height: 50px;
  139. &>div {
  140. float: left;
  141. }
  142. &:focus {
  143. outline: none;
  144. }
  145. .user-container {
  146. height: 50px;
  147. .user {
  148. i {
  149. font-size: 18px;
  150. margin-right: 5px;
  151. }
  152. span {
  153. font-size: 16px;
  154. }
  155. }
  156. }
  157. .right-menu-item {
  158. display: inline-block;
  159. padding: 0 15px;
  160. height: 100%;
  161. font-size: 18px;
  162. color: #{$navbarText};
  163. vertical-align: text-bottom;
  164. border-left: 1px solid #eaeaea;
  165. &.hover-effect {
  166. cursor: pointer;
  167. transition: background .3s;
  168. &:hover {
  169. background: rgba(0, 0, 0, .025)
  170. }
  171. }
  172. .notice-icon {
  173. padding-top: 0;
  174. padding-bottom: 0;
  175. }
  176. }
  177. }
  178. }
  179. </style>
  180. <style lang="scss">
  181. .navbar {
  182. .right-menu {
  183. .right-menu-item {
  184. .notice-icon>i {
  185. font-size: 18px;
  186. }
  187. sup {
  188. top: 12px;
  189. right: 25px;
  190. }
  191. }
  192. }
  193. }
  194. </style>