userInfo.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div class="user-info">
  3. <img class="avatar" :src="userAvatar" alt="" />
  4. <div class="nickName">{{userNickName}}</div>
  5. <i class="iconfont icon-show_drop-down"></i>
  6. <ul class="menu">
  7. <li><span @click="onClickPersonalCenter">个人中心</span></li>
  8. <li><span class="warn" @click="onClickLogout" >退出登录</span></li>
  9. </ul>
  10. </div>
  11. </template>
  12. <script>
  13. import { mapGetters } from 'vuex'
  14. export default {
  15. data() {
  16. return {
  17. }
  18. },
  19. computed: {
  20. ...mapGetters([
  21. 'userAvatar',
  22. 'userNickName'
  23. ]),
  24. },
  25. methods: {
  26. onClickPersonalCenter() {
  27. window.location.href = '/#/information'
  28. },
  29. onClickLogout() {
  30. localStorage.setItem('token', '')
  31. localStorage.setItem('info', '')
  32. window.location.href = '/#/'
  33. }
  34. },
  35. mounted() {
  36. }
  37. }
  38. </script>
  39. <style lang="less" scoped>
  40. .user-info {
  41. display: flex;
  42. align-items: center;
  43. position: relative;
  44. height: 80%;
  45. .avatar {
  46. width: 32px;
  47. height: 32px;
  48. border-radius: 50%;
  49. border: 1px solid rgba(0, 0, 0, 0.05);
  50. margin-right: 8px;
  51. object-fit: cover;
  52. }
  53. .nickName {
  54. color: #323233;
  55. font-size: 14px;
  56. margin-right: 5px;
  57. }
  58. .icon-show_drop-down {
  59. color: #323233;
  60. font-size: 12px;
  61. transform: scale(0.583) translateX(-35%);
  62. }
  63. &:hover {
  64. .menu {
  65. display: block;
  66. }
  67. }
  68. .menu {
  69. display: none;
  70. position: absolute;
  71. padding: 0 16px;
  72. background: #fff;
  73. box-shadow: 0px 2px 12px 0px rgba(50, 50, 51, 0.12);
  74. top: 50px;
  75. right: -10px;
  76. &:hover{
  77. display: block;
  78. }
  79. // 菜单的箭头
  80. &::before {
  81. border: 7px solid transparent;
  82. border-bottom: 7px solid #fff;
  83. width: 0;
  84. height: 0px;
  85. content: "";
  86. display: inline-block;
  87. position: absolute;
  88. top: -14px;
  89. right: 12px;
  90. }
  91. li {
  92. display: block;
  93. padding: 11px 20px;
  94. border-bottom: solid 1px #EBEDF0;
  95. &:last-child {
  96. border-bottom: none;
  97. }
  98. span {
  99. font-size: 16px;
  100. color: #323233;
  101. cursor: pointer;
  102. word-break: keep-all;
  103. &.warn {
  104. color: #FA5555;
  105. }
  106. }
  107. }
  108. }
  109. }
  110. </style>