main-navbar.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <nav class="site-navbar" :class="'site-navbar--' + navbarLayoutType">
  3. <div class="site-navbar__header">
  4. <h1 class="site-navbar__brand" @click="$router.push({ name: 'home' })">
  5. <a class="site-navbar__brand-lg" href="javascript:;">MZ 云平台</a>
  6. <a class="site-navbar__brand-mini" href="javascript:;">木之云</a>
  7. </h1>
  8. </div>
  9. <div class="site-navbar__body clearfix">
  10. <el-menu
  11. class="site-navbar__menu"
  12. mode="horizontal">
  13. <el-menu-item class="site-navbar__switch" index="0" @click="sidebarFold = !sidebarFold">
  14. <icon-svg name="zhedie"></icon-svg>
  15. </el-menu-item>
  16. </el-menu>
  17. <el-menu
  18. class="site-navbar__menu site-navbar__menu--right"
  19. mode="horizontal">
  20. <el-menu-item index="1" @click="$router.push({ name: 'msgCenter' })">
  21. <template slot="title">
  22. <el-badge :value="cnt" :hidden="cnt < 1">
  23. <icon-svg name="lingdang" class="el-icon-lingdang"></icon-svg>
  24. </el-badge>
  25. </template>
  26. </el-menu-item>
  27. <el-menu-item index="0" @click="previewPic">
  28. <template slot="title">
  29. <el-badge value="">
  30. <icon-svg name="minprogram" class="el-icon-setting"></icon-svg>
  31. </el-badge>
  32. </template>
  33. </el-menu-item>
  34. <el-menu-item index="2" @click="$router.push({ name: 'theme' })">
  35. <template slot="title">
  36. <el-badge value="">
  37. <icon-svg name="shezhi" class="el-icon-setting"></icon-svg>
  38. </el-badge>
  39. </template>
  40. </el-menu-item>
  41. <el-menu-item class="site-navbar__avatar" index="3">
  42. <el-dropdown :show-timeout="0" placement="bottom">
  43. <span class="el-dropdown-link">
  44. <img src="~@/assets/img/avatar.png" :alt="userName">{{ userName }}
  45. </span>
  46. <el-dropdown-menu slot="dropdown">
  47. <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item>
  48. <el-dropdown-item @click.native="logoutHandle()">退出</el-dropdown-item>
  49. </el-dropdown-menu>
  50. </el-dropdown>
  51. </el-menu-item>
  52. </el-menu>
  53. </div>
  54. <!-- 弹窗, 修改密码 -->
  55. <update-password v-if="updatePasswordVisible" ref="updatePassowrd"></update-password>
  56. <Msg ref="msgDialog" @noticeAdded="noticeAdded"/>
  57. <youli-component v-if="previewVisible" ref="preview"/>
  58. </nav>
  59. </template>
  60. <script>
  61. import UpdatePassword from './main-navbar-update-password'
  62. import Msg from './common/msg'
  63. import { clearLoginInfo } from '@/utils'
  64. import PreviewComponent from '@/views/modules/common/preview-component'
  65. import YouliComponent from '@/views/modules/common/youli-component'
  66. export default {
  67. data () {
  68. return {
  69. updatePasswordVisible: false,
  70. cnt: 0,
  71. previewVisible: false
  72. }
  73. },
  74. components: {
  75. YouliComponent,
  76. PreviewComponent,
  77. UpdatePassword,
  78. Msg
  79. },
  80. computed: {
  81. navbarLayoutType: {
  82. get () { return this.$store.state.common.navbarLayoutType }
  83. },
  84. sidebarFold: {
  85. get () { return this.$store.state.common.sidebarFold },
  86. set (val) { this.$store.commit('common/updateSidebarFold', val) }
  87. },
  88. mainTabs: {
  89. get () { return this.$store.state.common.mainTabs },
  90. set (val) { this.$store.commit('common/updateMainTabs', val) }
  91. },
  92. userName: {
  93. get () { return this.$store.state.user.name }
  94. }
  95. },
  96. methods: {
  97. // 修改密码
  98. updatePasswordHandle () {
  99. this.updatePasswordVisible = true
  100. this.$nextTick(() => {
  101. this.$refs.updatePassowrd.init()
  102. })
  103. },
  104. // 退出
  105. logoutHandle () {
  106. this.$confirm(`确定进行[退出]操作?`, '提示', {
  107. confirmButtonText: '确定',
  108. cancelButtonText: '取消',
  109. type: 'warning'
  110. }).then(() => {
  111. clearLoginInfo()
  112. this.$router.push({ name: 'login' })
  113. // this.$http({
  114. // url: this.$http.adornUrl('/sys/logout'),
  115. // method: 'post',
  116. // data: this.$http.adornData()
  117. // }).then(({data}) => {
  118. // if (data && data.code === 0) {
  119. // clearLoginInfo()
  120. // this.$router.push({ name: 'login' })
  121. // }
  122. // })
  123. }).catch(() => {})
  124. },
  125. // 通知数量变化
  126. noticeAdded (num) {
  127. this.cnt = num
  128. },
  129. // 小程序图片预览
  130. previewPic () {
  131. this.previewVisible = true
  132. this.$nextTick(() => {
  133. this.$refs.preview.init()
  134. })
  135. }
  136. }
  137. }
  138. </script>