<template>
  <div class="user-info">
    <img class="avatar" :src="head" alt="" />
    <div class="nickName">{{nickName}}</div>
    <i class="iconfont icon-show_drop-down"></i>
    <ul class="menu">
      <li><span @click="onClickPersonalCenter">个人中心</span></li>
      <li><span class="warn" @click="onClickLogout" >退出登录</span></li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      nickName: '',
      head: '',
    }
  },
  methods: {
    onClickPersonalCenter() {
      window.location.href = '/#/information'
    },
    onClickLogout() {
      // localStorage.removeItem('address')
      // localStorage.removeItem('token')
      // localStorage.removeItem('info')
      // localStorage.removeItem('currentName')
      localStorage.setItem('token', '')
      window.location.href = '/#/'
    }
  },
  mounted() {
    const userInfo = JSON.parse(localStorage.getItem('info'))
    this.nickName = userInfo.nickName
    this.head = userInfo.head
  }
}

</script>

<style lang="less" scoped>
.user-info {
  display: flex;
  align-items: center;
  position: relative;
  height: 80%;
  .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.05);
    margin-right: 8px;
  }
  .nickName {
    color: #323233;
    font-size: 14px;
    margin-right: 5px;
  }
  .icon-show_drop-down {
    color: #323233;
    font-size: 10px;
  }
  &:hover {
    .menu {
      display: block;
    }
  }
  .menu {
    display: none;
    position: absolute;
    padding: 0 16px;
    background: #fff;
    box-shadow: 0px 2px 12px 0px rgba(50, 50, 51, 0.12);
    top: 50px;
    right: -14px;
    &:hover{
      display: block;
    }
    // 菜单的箭头
    &::before {
      border: 7px solid transparent;
      border-bottom: 7px solid #fff;
      width: 0;
      height: 0px;
      content: "";
      display: inline-block;
      position: absolute;
      top: -14px;
      right: 12px;
    }
    li {
      display: block;
      padding: 11px 20px;
      border-bottom: solid 1px #EBEDF0;
      &:last-child {
        border-bottom: none;
      }
      span {
        font-size: 16px;
        color: #323233;
        cursor: pointer;
        word-break: keep-all;
        &.warn {
          color: #FA5555;
        }  
      }
    }
  }
}
</style>