userInfo.vue 2.5 KB

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