<template>
  <div id="Header">
    <el-row>
      <el-col :span="24" class="main header">
        <el-col :span="24" class="one">
          <el-col :span="8" 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="16" class="right">
            <!-- <notice v-if="user.lab_id"></notice> -->
            <i class="el-icon-refresh" v-if="$dev_env" @click="toRefresh()"></i>
            <i class="el-icon-user-solid"></i>
            <span>{{ user.name || '游客' }}</span>
            <!-- <span>游客</span> -->
            <el-button type="danger" size="mini" @click="logout">退出登录</el-button>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const _ = require('lodash');
const { siteInfo } = require('./data/site');
import { mapState, mapMutations, createNamespacedHelpers } from 'vuex';
import bus from './bus';
export default {
  name: 'Header',
  props: {},
  components: {},
  data: function () {
    return { collapse: false, siteInfo: siteInfo, options: {} };
  },
  created() {
    const { options } = this.$router;
    this.$set(this, `options`, options);
  },
  methods: {
    ...mapMutations(['deleteUser']),
    // 侧边栏折叠
    collapseChage() {
      this.collapse = !this.collapse;
      bus.$emit('collapse', this.collapse);
    },
    // 退出登录
    logout() {
      this.deleteUser();
      // 路由也得删除,但是没有删除路由的API,所以用replace来替换下
      const base = _.get(this.$router, 'options.base', '');
      window.location.replace(`/${base}/login`);
      // this.$router.push('/login');
    },
    toRefresh() {
      this.$emit('refresh');
    },
  },
  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;
      word-break: keep-all;
      white-space: nowrap;
      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>
