main-navbar.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <nav class="aui-navbar" :class="`aui-navbar--${$store.state.navbarLayoutType}`">
  3. <div class="aui-navbar__header">
  4. <h1 class="aui-navbar__brand" @click="$router.push({ name: 'home' })">
  5. <a class="aui-navbar__brand-lg adfac" href="javascript:;">
  6. <img src="@/assets/img/logo.png" style="width: 48px;height: 48px;margin-right: 13px;">
  7. {{ $t('brand.mini') }}
  8. </a>
  9. <a class="aui-navbar__brand-mini" href="javascript:;">
  10. <img src="@/assets/img/logo.png" style="width: 48px;height: 48px;">
  11. </a>
  12. </h1>
  13. </div>
  14. <div class="aui-navbar__body">
  15. <el-menu class="aui-navbar__menu mr-auto" mode="horizontal">
  16. <el-menu-item index="1" @click="$store.state.sidebarFold = !$store.state.sidebarFold">
  17. <svg class="icon-svg aui-navbar__icon-menu aui-navbar__icon-menu--switch" aria-hidden="true"><use xlink:href="#icon-outdent"></use></svg>
  18. </el-menu-item>
  19. <el-menu-item index="2" @click="refresh()">
  20. <svg class="icon-svg aui-navbar__icon-menu aui-navbar__icon-menu--refresh" aria-hidden="true"><use xlink:href="#icon-sync"></use></svg>
  21. </el-menu-item>
  22. </el-menu>
  23. <el-menu class="aui-navbar__menu" mode="horizontal">
  24. <el-menu-item index="3" v-if="$hasPermission('sys:notice:all')">
  25. <el-badge :is-dot="messageTip">
  26. <a href="#" @click="myNoticeRouter()"><i class="el-icon-bell"></i></a>
  27. </el-badge>
  28. </el-menu-item>
  29. <el-menu-item index="4" @click="fullscreenHandle()">
  30. <svg class="icon-svg aui-navbar__icon-menu" aria-hidden="true"><use xlink:href="#icon-fullscreen"></use></svg>
  31. </el-menu-item>
  32. <el-menu-item index="5" class="aui-navbar__avatar">
  33. <el-dropdown placement="bottom" :show-timeout="0">
  34. <span class="el-dropdown-link">
  35. <img src="~@/assets/img/avatar.png">
  36. <span>{{ $store.state.user.name }}</span>
  37. <i class="el-icon-arrow-down"></i>
  38. </span>
  39. <el-dropdown-menu slot="dropdown">
  40. <el-dropdown-item @click.native="updatePasswordHandle()">{{ $t('updatePassword.title') }}</el-dropdown-item>
  41. <el-dropdown-item @click.native="logoutHandle()">{{ $t('logout') }}</el-dropdown-item>
  42. </el-dropdown-menu>
  43. </el-dropdown>
  44. </el-menu-item>
  45. </el-menu>
  46. </div>
  47. <!-- 弹窗, 修改密码 -->
  48. <update-password v-if="updatePasswordVisible" ref="updatePassword"></update-password>
  49. </nav>
  50. </template>
  51. <script>
  52. import { messages } from '@/i18n'
  53. import screenfull from 'screenfull'
  54. import UpdatePassword from './main-navbar-update-password'
  55. import { clearLoginInfo } from '@/utils'
  56. var socket = null
  57. export default {
  58. inject: ['refresh'],
  59. data () {
  60. return {
  61. i18nMessages: messages,
  62. updatePasswordVisible: false,
  63. messageTip: false
  64. }
  65. },
  66. components: {
  67. UpdatePassword
  68. },
  69. created () {
  70. var vue = this
  71. socket = new WebSocket(`${window.SITE_CONFIG['socketURL']}`)
  72. socket.onopen = function () {}
  73. socket.onerror = function () {
  74. vue.$notify.error({
  75. title: vue.$t('notice.disconnect'),
  76. message: vue.$t('notice.disconnectMessage')
  77. })
  78. }
  79. socket.onmessage = function (evt) {
  80. const result = JSON.parse(evt.data)
  81. // 如果是有新文本通知,则提示有新通知
  82. if (result.type === 0) {
  83. vue.messageTip = true
  84. vue.$notify({
  85. title: vue.$t('notice.new'),
  86. message: result.msg,
  87. type: 'info',
  88. duration: 5000
  89. })
  90. }
  91. }
  92. // 未读通知数
  93. this.getUnReadCount()
  94. },
  95. methods: {
  96. myNoticeRouter () {
  97. this.$router.replace('notice-notice-user')
  98. },
  99. getUnReadCount () {
  100. // this.$http.get(`/sys/notice/mynotice/unread`).then(({ data: res }) => {
  101. // if (res.code !== 0) {
  102. // return this.$message.error(res.msg)
  103. // }
  104. // if (res.data > 0) {
  105. // this.messageTip = true
  106. // }
  107. // }).catch(() => {})
  108. },
  109. // 全屏
  110. fullscreenHandle () {
  111. if (!screenfull.enabled) {
  112. return this.$message({
  113. message: this.$t('fullscreen.prompt'),
  114. type: 'warning',
  115. duration: 500
  116. })
  117. }
  118. screenfull.toggle()
  119. },
  120. // 修改密码
  121. updatePasswordHandle () {
  122. this.updatePasswordVisible = true
  123. this.$nextTick(() => {
  124. this.$refs.updatePassword.init()
  125. })
  126. },
  127. // 退出
  128. logoutHandle () {
  129. this.$confirm(this.$t('prompt.info', { 'handle': this.$t('logout') }), this.$t('prompt.title'), {
  130. confirmButtonText: this.$t('confirm'),
  131. cancelButtonText: this.$t('cancel'),
  132. type: 'warning'
  133. }).then(() => {
  134. this.$http.post('/logout').then(({ data: res }) => {
  135. if (res.code !== 0) {
  136. return this.$message.error(res.msg)
  137. }
  138. clearLoginInfo()
  139. this.$router.push({ name: 'login' })
  140. }).catch(() => {})
  141. }).catch(() => {})
  142. }
  143. }
  144. }
  145. </script>