<template>
  <el-container class="home">
    <el-header>
      <div>
        <img src="../assets/image/logo.png" alt />
        <span>测试平台</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
          :default-active="activePath"
          background-color="#525e70"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
        >
          <el-submenu :index="1">
            <template slot="title">
              <i class="el-icon-s-check"></i>
              <span>自动化测试</span>
            </template>
            <el-menu-item index="/project" @click="saveNavState('/project')">
              <template slot="title">
                <span>项目管理</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/case" @click="saveNavState('/case')">
              <template slot="title">
                <span>接口管理</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/report" @click="saveNavState('/report')">
              <template slot="title">
                <span>测试报告</span>
              </template>
            </el-menu-item>
          </el-submenu>
          <el-submenu :index="2">
            <template slot="title">
              <i class="el-icon-s-data"></i>
              <span>数据工厂</span>
            </template>
            <el-menu-item index="/checkOldLoanData" @click="saveNavState('/checkOldLoanData')">
              <template slot="title">
                <span>查数据</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/genNewLoanData" @click="saveNavState('/genNewLoanData')">
              <template slot="title">
                <span>造数据</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      activePath: '',
      selectNamespace: '',
      // namespace
      nsOptions: [
        { label: 'qa', value: 'qa' },
        { label: 'qa2', value: 'qa2' }
      ]
    }
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/')
    },
    saveNavState(curPath) {
      this.activePath = curPath
      window.sessionStorage.setItem('activePath', curPath)
    }
  },
  created() {
    if (window.sessionStorage.getItem('env') === null) {
      this.$router.push('/')
    }
    this.activePath = window.sessionStorage.getItem('activePath')
  }
}
</script>

<style lang="less" scoped>
.home {
  height: 100%;
}
.el-header {
  background-color: #2a2961;
  display: flex;
  justify-content: space-between;
  color: #333;
  text-align: center;
  align-items: center;
  line-height: 60px;
  > div {
    display: flex;
    span {
      font-size: 22px;
      color: #ffffff;
      margin-left: 20px;
    }
    > img {
      height: 40px;
      width: 70px;
      margin-top: 12px;
    }
  }
}

.el-aside {
  background-color: #525e70;
  height: 100%;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #e9eef3;
}
</style>
