<template>
  <div class="card_userinfo">
    <!-- 用户头像 -->
    <img class="header-portrait" src="../../assets/icon_my.png" alt="用户头像">
    <!-- 用户名下拉菜单 -->
    <el-dropdown @command="handleCommand">
      <span class="el-dropdown-link">
        {{username}}
        <i class="el-icon-caret-bottom"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="loginout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
  import Bus from './bus';
  import Cookies from "js-cookie";
  import {
    mapActions
  } from 'vuex'
  export default {
    name: "UserInfo",
    data() {
      return {
        username: localStorage.getItem('username')
      }
    },
    methods: {
      ...mapActions(['Login', 'Logout']),
      // 用户名下拉菜单选择事件
      handleCommand(command) {
        const {
          Logout
        } = this
        if ('loginout' == command) {
          Logout().then((res) => {
            localStorage.removeItem('T_tokey');
            localStorage.removeItem('username');
            this.$router.push('/login');
          })
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  .card_userinfo {
    display: flex;
    align-items: center;
  }

  .header-portrait {
    width: 28px;
    flex: none;
    margin: 0 5px;
    vertical-align: middle;
  }

  .el-dropdown-link {
    color: white;
    cursor: pointer;
    font-family: system-ui;
    font-size: 20px;
  }

  .el-dropdown-menu {
    background: linear-gradient(0, #0cb9e2, #1774c3) !important;
    border: none !important;
    padding: unset !important;

    .el-dropdown-menu__item {
      color: #fff !important;
      letter-spacing: 2px !important;
    }
  }

  .el-dropdown-menu__item:focus,
  .el-dropdown-menu__item:not(.is-disabled):hover {
    background: none !important;
  }

  ::v-deep .popper__arrow {
    border-bottom-color: #1774c3 !important;
  }

  ::v-deep .popper__arrow:after {
    border-bottom-color: #1774c3 !important;
  }
</style>
