<template>
  <a-dropdown>
    <div class="header-avatar" style="cursor: pointer">
      <a-avatar
        class="avatar"
        size="small"
        shape="circle"
        :src="process + userInfo.headSculpture"
      />
      <!-- {{ process + userInfo.headSculpture }} -->
      <span class="name">{{ userInfo.name }}</span>
    </div>
    <a-menu :class="['avatar-menu']" slot="overlay">
      <a-menu-item @click="logout">
        <a-icon style="margin-right: 8px" type="poweroff" />
        <span>退出登录</span>
      </a-menu-item>
    </a-menu>
  </a-dropdown>
</template>

<script>
import { mapState } from "vuex";
import { logout } from "@/services/user";

export default {
  name: "HeaderAvatar",
  data() {
    return {
      process: process.env.VUE_APP_BASE_URL,
    };
  },
  computed: {
    ...mapState("setting", ["userInfo"]),
  },
  created() {},
  methods: {
    logout() {
      logout();
      // this.$router.push('/login')
      // console.log(this.process);
      window.location.href = this.process + "/#/login";
    },
  },
};
</script>

<style lang="less">
.header-avatar {
  display: inline-flex;
  .avatar,
  .name {
    align-self: center;
  }
  .avatar {
    margin-right: 8px;
  }
  .name {
    font-weight: 500;
  }
}
.avatar-menu {
  width: 150px;
}
</style>
