index.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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="logout" divided>退出登录</el-dropdown-item>
  15. </el-dropdown-menu>
  16. </el-dropdown>
  17. </template>
  18. <script>
  19. import { mapGetters } from "vuex";
  20. import { recordRoute } from "@/config/settings";
  21. export default {
  22. name: "Avatar",
  23. computed: {
  24. ...mapGetters({
  25. avatar: "user/avatar",
  26. username: "user/username",
  27. }),
  28. },
  29. methods: {
  30. handleCommand(command) {
  31. switch (command) {
  32. case "logout":
  33. this.logout();
  34. break;
  35. case "personalCenter":
  36. this.personalCenter();
  37. break;
  38. case "github":
  39. window.open("https://github.com/chuzhixin/vue-admin-beautiful");
  40. break;
  41. case "gitee":
  42. window.open("https://gitee.com/chu1204505056/vue-admin-beautiful");
  43. break;
  44. }
  45. },
  46. personalCenter() {
  47. this.$router.push("/personalCenter/personalCenter");
  48. },
  49. logout() {
  50. this.$baseConfirm(
  51. "您确定要退出" + this.$baseTitle + "吗?",
  52. null,
  53. async () => {
  54. await this.$store.dispatch("user/logout");
  55. if (recordRoute) {
  56. const fullPath = this.$route.fullPath;
  57. this.$router.push(`/login?redirect=${fullPath}`);
  58. } else {
  59. this.$router.push("/login");
  60. }
  61. }
  62. );
  63. },
  64. },
  65. };
  66. </script>
  67. <style lang="scss" scoped>
  68. .avatar-dropdown {
  69. display: flex;
  70. align-content: center;
  71. align-items: center;
  72. justify-content: center;
  73. justify-items: center;
  74. height: 50px;
  75. padding: 0;
  76. .user-avatar {
  77. width: 40px;
  78. height: 40px;
  79. cursor: pointer;
  80. border-radius: 50%;
  81. }
  82. .user-name {
  83. position: relative;
  84. margin-left: 5px;
  85. margin-left: 5px;
  86. font-weight: 600;
  87. cursor: pointer;
  88. }
  89. }
  90. </style>