<template>
  <a-dropdown>
    <div class="header-avatar" style="cursor: pointer">
      <a-avatar class="avatar" size="small" shape="circle" :src="user.avatar"/>
      <span class="name">{{user.nickname}}</span>
    </div>
    <a-menu :class="['avatar-menu']" slot="overlay">
      <a-menu-item @click="adminUser">
        <a-icon type="user"/>
        <span>用户管理</span>
      </a-menu-item>
      <a-menu-divider />
      <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 {mapGetters} from 'vuex' // 加载vuex的mapGetters辅助函数
import {logout} from '@/services/base/user' // 加载退出登录的接口

export default {
  name: 'HeaderAvatar', // 组件名称 头部头像
  computed: {
    ...mapGetters('account', ['user']), // 获取用户信息
  },
  methods: {
    adminUser(){
      this.$router.push('/AdminUser/AdminUserList');
    },
    logout() { // 退出登录
      logout() // 调用退出登录接口
      this.$router.push('/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>
