<template>
  <div class="user-info">
      <!-- <img class="avatar" :src="userAvatar" alt="" /> -->
      <div class="nickName">{{ userNickName }}</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>
import { mapGetters } from "vuex";
import { logout } from "@/api";

export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters(["userAvatar", "userNickName"]),
  },
  methods: {
    onClickPersonalCenter() {
      window.location.href = "/#/information";
    },
    onClickLogout() {
      this.$confirm({
        title: "退出登录",
        content: "确定要退出登录吗？",
        okText: "确定",
        ok: () => {
          logout(() => {
            localStorage.setItem("token", "");
            localStorage.setItem("userInfo", "");
            window.location.href = "/material.html#/login";
          });
        },
      });
    },
  },
  mounted() {},
};
</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;
    object-fit: cover;
  }
  .nickName {
    color: #323233;
    font-size: 14px;
    margin-right: 5px;
  }
  .icon-show_drop-down {
    color: #323233;
    font-size: 12px;
    transform: scale(0.583) translateX(-35%);
  }
  &: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: -10px;
    &: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;
        }
      }
    }
  }
  .loginAndRegis {
    font-size: 14px;
    color: #323233;
    span {
      cursor: pointer;
      padding: 0 5px;
    }
  }
}
</style>
