index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <el-dropdown @command="handleCommand">
  3. <span class="avatar-dropdown">
  4. <!--<el-avatar class="user-avatar" :src="avatar"></el-avatar>-->
  5. <img class="user-avatar" :src="avatar" alt="" />
  6. <div class="user-name">
  7. {{ username }}
  8. <i class="el-icon-arrow-down el-icon--right"></i>
  9. </div>
  10. </span>
  11. <el-dropdown-menu slot="dropdown">
  12. <el-dropdown-item command="github">github地址</el-dropdown-item>
  13. <el-dropdown-item command="gitee" divided>码云地址</el-dropdown-item>
  14. <el-dropdown-item command="pro" divided>pro付费版地址</el-dropdown-item>
  15. <el-dropdown-item command="plus" divided>plus付费版地址</el-dropdown-item>
  16. <el-dropdown-item command="logout" divided>退出登录</el-dropdown-item>
  17. </el-dropdown-menu>
  18. </el-dropdown>
  19. </template>
  20. <script>
  21. import { mapGetters } from 'vuex'
  22. import { recordRoute } from '@/config'
  23. export default {
  24. name: 'VabAvatar',
  25. computed: {
  26. ...mapGetters({
  27. avatar: 'user/avatar',
  28. username: 'user/username',
  29. }),
  30. },
  31. methods: {
  32. handleCommand(command) {
  33. switch (command) {
  34. case 'logout':
  35. this.logout()
  36. break
  37. case 'personalCenter':
  38. this.personalCenter()
  39. break
  40. case 'github':
  41. window.open('https://github.com/chuzhixin/vue-admin-beautiful')
  42. break
  43. case 'gitee':
  44. window.open('https://gitee.com/chu1204505056/vue-admin-beautiful')
  45. break
  46. case 'pro':
  47. window.open(
  48. 'https://vue-admin-beautiful.com/admin-pro/?hmsr=homeAd&hmpl=&hmcu=&hmkw=&hmci='
  49. )
  50. break
  51. case 'plus':
  52. window.open(
  53. 'https://vue-admin-beautiful.com/admin-plus/?hmsr=homeAd&hmpl=&hmcu=&hmkw=&hmci='
  54. )
  55. }
  56. },
  57. personalCenter() {
  58. this.$router.push('/personalCenter/personalCenter')
  59. },
  60. logout() {
  61. this.$baseConfirm(
  62. '您确定要退出' + this.$baseTitle + '吗?',
  63. null,
  64. async () => {
  65. await this.$store.dispatch('user/logout')
  66. if (recordRoute) {
  67. const fullPath = this.$route.fullPath
  68. this.$router.push(`/login?redirect=${fullPath}`)
  69. } else {
  70. this.$router.push('/login')
  71. }
  72. }
  73. )
  74. },
  75. },
  76. }
  77. </script>
  78. <style lang="scss" scoped>
  79. .avatar-dropdown {
  80. display: flex;
  81. align-content: center;
  82. align-items: center;
  83. justify-content: center;
  84. justify-items: center;
  85. height: 50px;
  86. padding: 0;
  87. .user-avatar {
  88. width: 40px;
  89. height: 40px;
  90. cursor: pointer;
  91. border-radius: 50%;
  92. }
  93. .user-name {
  94. position: relative;
  95. margin-left: 5px;
  96. margin-left: 5px;
  97. cursor: pointer;
  98. }
  99. }
  100. </style>