<template>
  <div class="navbar">
    <div class="line"></div>
    <hamburger
      id="hamburger-container"
      :is-active="sidebar.opened"
      class="hamburger-container"
      @toggleClick="toggleSideBar"
    />

    <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav" />

    <div class="right-menu">
      <screenfull id="screenfull" class="right-menu-item hover-effect" />

      <el-tooltip content="退出" placement="bottom" effect="light">
        <i class="quit el-icon-switch-button" @click="logout"></i>
      </el-tooltip>

      <div class="right-line"></div>
      <div class="ava-img">
        <img src="@/assets/touxiang.png" alt="" />
        <span>{{ $store.state.user.username }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import TopNav from "@/components/TopNav";
import Hamburger from "@/components/Hamburger";
import Screenfull from "@/components/Screenfull";
import Search from "@/components/HeaderSearch";
import SizeSelect from "@/components/SizeSelect";

export default {
  components: {
    Hamburger,
    TopNav,
    Screenfull,
    SizeSelect,
    Search
  },
  computed: {
    ...mapGetters(["sidebar", "avatar"]),
    topNav: {
      get() {
        return this.$store.state.settings.topNav;
      }
    }
  },
  data() {
    return {};
  },
  created() {},
  methods: {
    toggleSideBar() {
      this.$store.dispatch("app/toggleSideBar");
    },

    async logout() {
      await this.$store.dispatch("user/logout");
      this.$router.push(`/login`);
    }
  }
};
</script>

<style lang="scss" scoped>
$bg_color : #3C64DC;
// 顶部右侧图标颜色
.navbar .right-menu .right-color .svg-icon,
i {
  color: $bg_color;
}
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  .line {
    float: left;
    width: 1px;
    height: 32px;
    border: 1px solid #a0a0a0;
    margin-top: 8px;
  }
  .hamburger-container {
    line-height: 50px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }
  }
  .topmenu-container {
    position: absolute;
    left: 50px;
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;
    overflow: hidden;
    vertical-align: middle;
    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: $bg_color;
      vertical-align: text-bottom;
      cursor: pointer;
    }

    .avatar-container {
      margin-right: 10px;

      .avatar-wrapper {
        position: relative;

        .user-avatar {
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
  }
}
.quit {
  vertical-align: 0.6em;
  font-size: 23px;
  font-weight: 800;
  cursor: pointer;
  margin-left: 10px;
}
.right-line {
  display: inline-block;
  margin: 0 20px 8px;
  width: 1px;
  height: 26px;
  border: 1px solid #a0a0a0;
}
.ava-img {
  display: inline-block;
  vertical-align: 1em;
  margin-right: 20px;

  img {
    width: 28px;
    vertical-align: middle;
    margin-right: 5px;
    padding-bottom: 3px;
  }
}
</style>
