<template>
  <div class="user-avatar-dropdown">
    <div class="userName" v-if="isLogin">
      {{ userName }}
    </div>
    <Dropdown @on-click="handleClick" v-if="isLogin">
      <Avatar class="login" v-if="isLogin" icon="md-person"></Avatar>
      <!-- <Avatar class="logout" v-else icon="md-person"></Avatar> -->
      <!-- <DropdownMenu slot="list" class="dropDownClass">
        <DropdownItem name="logout">退出登录</DropdownItem>
      </DropdownMenu> -->
    </Dropdown>
    <!-- <FullScreen class="vertical" v-model="isFullScreen"></FullScreen> -->
    <div class="quit_box">
      <div class="quit" v-if="isLogin" @click="logout()">
        <Icon class="quit_icon" type="md-log-out" :size="24" />
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";
import FullScreen from "../fullscreen";
import { getToken } from "@/libs/util";

export default {
  name: "User",
  inject: ["reload"],
  props: {
    userName: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      // 全屏标志位
      isFullScreen: false,
    };
  },
  computed: {
    isLogin() {
      return getToken();
    },
  },
  components: {
    FullScreen,
  },
  methods: {
    ...mapActions(["handleLogOut"]),
    logout() {
      this.handleLogOut().then(() => {
        this.reload();
      });
    },
    handleClick(name) {
      switch (name) {
        case "logout":
          this.logout();
          break;
      }
    },
  },
};
</script>
<style lang="less" scoped>
.user-avatar-dropdown {
  display: flex;
  flex-direction: row-reverse;
  .vertical {
    display: inline-block;
    margin-right: 10px;
  }
  .login {
    background-color: #2d8cf0;
  }
  .logout {
    background-color: #cccccc;
  }
  .userName {
    display: inline-block;
    margin-left: 10px;
    width: 105px;
    height: 100%;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    color: #515a6e;
    font-size: 18px;
    font-weight: bold;
  }
}
.quit_box {
  height: 64px;
  display: flex;
  align-items: center;
  .quit {
    width: 24px;
    height: 24px;
    line-height: 24px;
    border-radius: 50%;
    background-color: #ed4014;
    margin-right: 10px;
    position: relative;
    cursor: pointer;
    .quit_icon {
      position: absolute;
      top: 0;
      left: 0;
      color: #fff;
    }
  }
}
</style>
