<template>
  <div id="Header">
    <el-row>
      <el-col :span="24" class="main header">
        <el-col :span="24" class="one">
          <el-col :span="12" class="left">
            <span @click="collapseChage">
              <i v-if="!collapse" class="el-icon-s-fold"></i>
              <i v-else class="el-icon-s-unfold"></i>
            </span>
            <span>{{ siteInfo.zhTitle }}-管理中心</span>
          </el-col>
          <el-col :span="12" class="right">
            <i class="el-icon-user-solid"></i>
            <span>{{ user.name || '游客' }}</span>
            <el-button type="danger" size="mini" @click="logout">退出登录</el-button>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const { siteInfo } = require('../../layout/deploy/site');
import { mapState, createNamespacedHelpers } from 'vuex';
import bus from './bus';
export default {
  name: 'Header',
  props: {},
  components: {},
  data: function() {
    return { collapse: false, siteInfo: siteInfo };
  },
  created() {},
  methods: {
    // 侧边栏折叠
    collapseChage() {
      this.collapse = !this.collapse;
      bus.$emit('collapse', this.collapse);
    },
    // 退出登录
    logout() {
      localStorage.removeItem('token');
      this.$router.push('/login');
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  mounted() {
    if (document.body.clientWidth < 1500) {
      this.collapseChage();
    }
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    height: 60px;
    border-bottom: 1px solid #f1f1f1;
    padding: 0 10px;
    .left {
      line-height: 60px;
      span {
        display: inline-block;
        margin: 0 10px;
        font-size: 22px;
        color: #ffffff;
        font-weight: bold;
        font-family: cursive;
      }
    }
    .right {
      text-align: right;
      line-height: 60px;
      i {
        position: relative;
        top: 5px;
        margin: 0px 15px;
        font-size: 30px;
        color: #fff;
      }
      span {
        color: #fff;
        font-size: 16px;
        padding: 0 15px 0 0px;
      }
    }
  }
}
</style>
