main-navbar.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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:;">小猪认养</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: 'theme' })">
  21. <template slot="title">
  22. <!-- <el-badge value="new"> -->
  23. <icon-svg name="shezhi" class="el-icon-setting"></icon-svg>
  24. <!-- </el-badge> -->
  25. </template>
  26. </el-menu-item>
  27. <!-- <el-menu-item index="2">
  28. <el-badge value="hot">
  29. <a href="https://www.renren.io/" target="_blank">官方社区</a>
  30. </el-badge>
  31. </el-menu-item>
  32. <el-submenu index="3">
  33. <template slot="title">Git源码</template>
  34. <el-menu-item index="2-1"><a href="https://github.com/renrenio/renren-fast-vue" target="_blank">前端</a></el-menu-item>
  35. <el-menu-item index="2-2"><a href="https://gitee.com/renrenio/renren-fast" target="_blank">后台</a></el-menu-item>
  36. <el-menu-item index="2-3"><a href="https://gitee.com/renrenio/renren-generator" target="_blank">代码生成器</a></el-menu-item>
  37. </el-submenu> -->
  38. <el-menu-item class="site-navbar__avatar" index="3">
  39. <el-dropdown :show-timeout="0" placement="bottom">
  40. <span class="el-dropdown-link">
  41. <img src="~@/assets/img/avatar.png" :alt="userName">{{ userName }}
  42. </span>
  43. <el-dropdown-menu slot="dropdown">
  44. <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item>
  45. <el-dropdown-item @click.native="logoutHandle()">退出</el-dropdown-item>
  46. </el-dropdown-menu>
  47. </el-dropdown>
  48. </el-menu-item>
  49. </el-menu>
  50. </div>
  51. <!-- 弹窗, 修改密码 -->
  52. <update-password v-if="updatePassowrdVisible" ref="updatePassowrd"></update-password>
  53. </nav>
  54. </template>
  55. <script>
  56. import UpdatePassword from './main-navbar-update-password'
  57. import { clearLoginInfo } from '@/utils'
  58. export default {
  59. data () {
  60. return {
  61. updatePassowrdVisible: false
  62. }
  63. },
  64. components: {
  65. UpdatePassword
  66. },
  67. computed: {
  68. navbarLayoutType: {
  69. get () { return this.$store.state.common.navbarLayoutType }
  70. },
  71. sidebarFold: {
  72. get () { return this.$store.state.common.sidebarFold },
  73. set (val) { this.$store.commit('common/updateSidebarFold', val) }
  74. },
  75. mainTabs: {
  76. get () { return this.$store.state.common.mainTabs },
  77. set (val) { this.$store.commit('common/updateMainTabs', val) }
  78. },
  79. userName: {
  80. get () { return this.$store.state.user.name }
  81. }
  82. },
  83. methods: {
  84. // 修改密码
  85. updatePasswordHandle () {
  86. this.updatePassowrdVisible = true
  87. this.$nextTick(() => {
  88. this.$refs.updatePassowrd.init()
  89. })
  90. },
  91. // 退出
  92. logoutHandle () {
  93. this.$confirm(`确定进行[退出]操作?`, '提示', {
  94. confirmButtonText: '确定',
  95. cancelButtonText: '取消',
  96. type: 'warning'
  97. }).then(() => {
  98. this.$http({
  99. url: this.$http.adornUrl('/sys/logout'),
  100. method: 'post',
  101. data: this.$http.adornData()
  102. }).then(({data}) => {
  103. if (data && data.code === 0) {
  104. clearLoginInfo()
  105. this.$router.push({ name: 'login' })
  106. }
  107. })
  108. }).catch(() => {})
  109. }
  110. }
  111. }
  112. </script>