Navbar.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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" v-if="!topNav"/>
  5. <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav"/>
  6. <div class="right-menu">
  7. <template v-if="device!=='mobile'">
  8. <div class="right-menu-item hover-effect">
  9. <el-badge v-if="msgCount>0" :value="msgCount" :max="99" class="dot">
  10. </el-badge>
  11. <div class="msg" @click="openMsg()">
  12. <i class="el-icon-message-solid"></i>
  13. </div>
  14. </div>
  15. <search id="header-search" class="right-menu-item" />
  16. <screenfull id="screenfull" class="right-menu-item hover-effect" />
  17. <el-tooltip content="布局大小" effect="dark" placement="bottom">
  18. <size-select id="size-select" class="right-menu-item hover-effect" />
  19. </el-tooltip>
  20. </template>
  21. <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
  22. <div class="avatar-wrapper">
  23. <img :src="logImg" class="user-avatar">
  24. <i class="el-icon-caret-bottom" />
  25. </div>
  26. <el-dropdown-menu slot="dropdown">
  27. <router-link to="/user/profile">
  28. <el-dropdown-item>个人中心</el-dropdown-item>
  29. </router-link>
  30. <el-dropdown-item @click.native="setting = true">
  31. <span>布局设置</span>
  32. </el-dropdown-item>
  33. <el-dropdown-item divided @click.native="logout">
  34. <span>退出登录</span>
  35. </el-dropdown-item>
  36. </el-dropdown-menu>
  37. </el-dropdown>
  38. </div>
  39. <el-drawer
  40. :append-to-body="true"
  41. size="35%"
  42. :with-header="false"
  43. :visible.sync="msg.open"
  44. >
  45. <msg ref="msg" @update-count="getMsgCount" />
  46. </el-drawer>
  47. <integral-order-msg-dialog ref="integralOrderMsgDialog" @msg-read="getMsgCount" />
  48. <complaint-msg-dialog ref="complaintMsgDialog" @msg-read="getMsgCount" />
  49. </div>
  50. </template>
  51. <script>
  52. import { mapGetters } from 'vuex'
  53. import Breadcrumb from '@/components/Breadcrumb'
  54. import TopNav from '@/components/TopNav'
  55. import Hamburger from '@/components/Hamburger'
  56. import Screenfull from '@/components/Screenfull'
  57. import SizeSelect from '@/components/SizeSelect'
  58. import Search from '@/components/HeaderSearch'
  59. import msg from "@/views/crm/components/msg";
  60. import IntegralOrderMsgDialog from '@/components/IntegralOrderMsgDialog'
  61. import ComplaintMsgDialog from '@/components/ComplaintMsgDialog'
  62. import { getMsg, getMsgList, getMsgCount, setRead } from "@/api/crm/msg";
  63. export default {
  64. components: {
  65. Breadcrumb,
  66. TopNav,
  67. Hamburger,
  68. Screenfull,
  69. SizeSelect,
  70. Search,
  71. msg,
  72. IntegralOrderMsgDialog,
  73. ComplaintMsgDialog
  74. },
  75. computed: {
  76. ...mapGetters([
  77. 'sidebar',
  78. 'avatar',
  79. 'device'
  80. ]),
  81. setting: {
  82. get() {
  83. return this.$store.state.settings.showSettings
  84. },
  85. set(val) {
  86. this.$store.dispatch('settings/changeSetting', {
  87. key: 'showSettings',
  88. value: val
  89. })
  90. }
  91. },
  92. topNav: {
  93. get() {
  94. return this.$store.state.settings.topNav
  95. }
  96. }
  97. },
  98. data() {
  99. return {
  100. msgCount: 0,
  101. previousMsgCount: 0,
  102. msg: {
  103. open: false,
  104. title: '通知消息'
  105. },
  106. msgPollingTimer: null,
  107. isFirstCheck: true,
  108. }
  109. },
  110. created() {
  111. this.getMsgCount();
  112. this.startMsgPolling();
  113. },
  114. beforeDestroy() {
  115. this.stopMsgPolling();
  116. },
  117. methods: {
  118. startMsgPolling() {
  119. if (this.msgPollingTimer) {
  120. clearInterval(this.msgPollingTimer);
  121. }
  122. this.msgPollingTimer = setInterval(() => {
  123. this.getMsgCount();
  124. }, 30000);
  125. },
  126. stopMsgPolling() {
  127. if (this.msgPollingTimer) {
  128. clearInterval(this.msgPollingTimer);
  129. this.msgPollingTimer = null;
  130. }
  131. },
  132. checkSpecialMsgs() {
  133. if (this.$refs.integralOrderMsgDialog) {
  134. this.$refs.integralOrderMsgDialog.show();
  135. }
  136. if (this.$refs.complaintMsgDialog) {
  137. this.$refs.complaintMsgDialog.show();
  138. }
  139. },
  140. getMsgCount() {
  141. getMsg().then(response => {
  142. let totalCount = 0;
  143. response.counts.forEach(item => {
  144. totalCount += item.total;
  145. });
  146. this.msgCount = totalCount;
  147. if (this.isFirstCheck) {
  148. this.isFirstCheck = false;
  149. this.$nextTick(() => {
  150. this.checkSpecialMsgs();
  151. });
  152. }
  153. this.previousMsgCount = totalCount;
  154. });
  155. },
  156. openMsg() {
  157. this.msg.open = true;
  158. },
  159. toggleSideBar() {
  160. this.$store.dispatch('app/toggleSideBar')
  161. },
  162. async logout() {
  163. this.$confirm('确定注销并退出系统吗?', '提示', {
  164. confirmButtonText: '确定',
  165. cancelButtonText: '取消',
  166. type: 'warning'
  167. }).then(() => {
  168. this.$store.dispatch('LogOut').then(() => {
  169. location.href = '/index';
  170. })
  171. }).catch(() => {});
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss" scoped>
  177. .navbar {
  178. height: 50px;
  179. overflow: hidden;
  180. position: relative;
  181. background: #fff;
  182. box-shadow: 0 1px 4px rgba(0,21,41,.08);
  183. .hamburger-container {
  184. line-height: 46px;
  185. height: 100%;
  186. float: left;
  187. cursor: pointer;
  188. transition: background .3s;
  189. -webkit-tap-highlight-color:transparent;
  190. &:hover {
  191. background: rgba(0, 0, 0, .025)
  192. }
  193. }
  194. .breadcrumb-container {
  195. float: left;
  196. }
  197. .topmenu-container {
  198. position: absolute;
  199. left: 50px;
  200. }
  201. .errLog-container {
  202. display: inline-block;
  203. vertical-align: top;
  204. }
  205. .right-menu {
  206. float: right;
  207. height: 100%;
  208. line-height: 50px;
  209. &:focus {
  210. outline: none;
  211. }
  212. .right-menu-item {
  213. display: inline-block;
  214. padding: 0 8px;
  215. height: 100%;
  216. font-size: 18px;
  217. color: #5a5e66;
  218. vertical-align: text-bottom;
  219. &.hover-effect {
  220. cursor: pointer;
  221. transition: background .3s;
  222. &:hover {
  223. background: rgba(0, 0, 0, .025)
  224. }
  225. }
  226. }
  227. .msg {
  228. font-size: 20px;
  229. cursor: pointer;
  230. position: relative;
  231. }
  232. .dot {
  233. position: absolute;
  234. top: 5px;
  235. right: -5px;
  236. }
  237. .avatar-container {
  238. margin-right: 30px;
  239. .avatar-wrapper {
  240. margin-top: 5px;
  241. position: relative;
  242. .user-avatar {
  243. cursor: pointer;
  244. width: 40px;
  245. height: 40px;
  246. border-radius: 10px;
  247. }
  248. .el-icon-caret-bottom {
  249. cursor: pointer;
  250. position: absolute;
  251. right: -20px;
  252. top: 25px;
  253. font-size: 12px;
  254. }
  255. }
  256. }
  257. }
  258. }
  259. </style>