<template>
  <el-menu class="navbar" mode="horizontal">
    <hamburger class="hamburger-container" :toggleClick="toggleSideBar" :isActive="sidebar.opened"></hamburger>
    <breadcrumb></breadcrumb>
    <el-dropdown class="avatar-container" trigger="click">
      <div class="avatar-wrapper">
        <img class="user-avatar" :src="avatar?avatar:headerInfo">
        <p class="user-name">{{name}}</p>
        <i class="el-icon-caret-bottom"></i>
      </div>
      <el-dropdown-menu class="user-dropdown" slot="dropdown">
        <router-link class="inlineBlock" to="/">
          <el-dropdown-item>
            首页
          </el-dropdown-item>
        </router-link>
        <el-dropdown-item divided>
          <span @click="logout" style="display:block;">退出</span>
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </el-menu>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import headerInfo from './images/header.png'
export default {
  components: {
    Breadcrumb,
    Hamburger
  },
  data(){
    return {
      headerInfo
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name'
    ])
  },
  mounted(){
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('ToggleSideBar')
    },
    logout() {
      this.$store.dispatch('LogOut').then(() => {
        this.$router.push('/login')
       // 为了重新实例化vue-router对象 避免bug
        // console.log(location.hostname+'/mall')
        // location.href = location.hostname+'/mall'
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.navbar {
  height: 50px;
  line-height: 50px;
  border-radius: 0px !important;
  .hamburger-container {
    line-height: 58px;
    height: 50px;
    float: left;
    padding: 0 10px;
  }
  .screenfull {
    position: absolute;
    right: 90px;
    top: 16px;
    color: red;
  }
  .avatar-container {
    height: 50px;
    display: inline-block;
    position: absolute;
    right: 35px;
    .avatar-wrapper {
      display: flex;
      flex-direction: row;
      align-items: center;
      cursor: pointer;
      // margin-top: 5px;
      position: relative;
      .user-name {
        margin: 0px 5px;

      }
      .user-avatar {
        width: 40px;
        height: 40px;
        border-radius: 10px;
        position: relative;
        top:-4px;
      }
      .el-icon-caret-bottom {
        line-height: 50px;
        font-size: 12px;
        margin-left: 5px;
      }
    }
  }
}
</style>

