<template>
  <el-container class="home">
    <el-header>
      <div class="left">
        <img src="../assets/image/logo.png" alt @click="gotoMain()"/>
        <span @click="gotoMain()">测试平台</span>
      </div>
      <div class="right">
        <el-tag>当前环境：{{ env }}</el-tag>
        <el-button type="primary" @click="logout">退出</el-button>>
      </div>
      <!-- <el-tag type="info" effect="dark">当前环境：{{ env }}</el-tag>
      <el-button type="info" @click="logout">退出</el-button> -->
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu :default-active="activePath" background-color="#525E7D" text-color="#fff" active-text-color="#ffd04b" router>
          <el-submenu :index="1+''">
            <template slot="title">
              <i class="el-icon-money"></i>
              <span>现金分期</span>
            </template>
            <el-menu-item index="/xyqb/getLoanData" @click="saveNavState('/xyqb/getLoanData')">
              <template slot="title">
                <i class="el-icon-watermelon"></i>
                <span>捞数据</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/xyqb/genLoanData" @click="saveNavState('/xyqb/genLoanData')">
              <template slot="title">
                <i class="el-icon-cherry"></i>
                <span>造数据</span>
              </template>
            </el-menu-item>
          </el-submenu>
          <el-submenu :index="2+''">
            <template slot="title">
              <i class="el-icon-s-shop"></i>
              <span>消费分期</span>
            </template>
            <el-menu-item index="/vcc/checkData" @click="saveNavState('/vcc/checkData')">
              <template slot="title">
                <i class="el-icon-pear"></i>
                <span>查数据</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/vcc/getData" @click="saveNavState('/vcc/getData')">
              <template slot="title">
                <i class="el-icon-grape"></i>
                <span>捞数据</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/vcc/genData" @click="saveNavState('/vcc/genData')">
              <template slot="title">
                <i class="el-icon-apple"></i>
                <span>造数据</span>
              </template>
            </el-menu-item>
          </el-submenu>
          <el-submenu :index="3+''">
            <template slot="title">
              <i class="el-icon-s-shop"></i>
              <span>Mock</span>
            </template>
            <el-menu-item index="/mock/list" @click="saveNavState('/mock/list')">
              <template slot="title">
                <i class="el-icon-pear"></i>
                <span>mock</span>
              </template>
            </el-menu-item>
          </el-submenu>
          <el-submenu :index="4+''">
            <template slot="title">
              <i class="el-icon-s-shop"></i>
              <span>小工具</span>
            </template>
            <el-menu-item index="/effect/kdsp/decrypt" @click="saveNavState('/effect/kdsp/decrypt')">
              <template slot="title">
                <i class="el-icon-pear"></i>
                <span>kdsp解密</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/effect/jenkins/build" @click="saveNavState('/effect/jenkins/build')">
              <template slot="title">
                <i class="el-icon-pear"></i>
                <span>构建记录</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/effect/whitelist" @click="saveNavState('/effect/whitelist')">
              <template slot="title">
                <i class="el-icon-pear"></i>
                <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: '',
      env: window.sessionStorage.getItem('env')
    }
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/')
    },
    saveNavState(curPath) {
      this.activePath = curPath
      // window.sessionStorage.setItem('activePath', curPath)
      window.localStorage.setItem('activePath', curPath)
    },
    gotoMain() {
      if (this.$route.path !== '/main') {
        this.$router.push('/main')
      }
    }
  },
  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;
  background-color: #001528;
  display: flex;
  justify-content: space-between;
  color: #333;
  text-align: center;
  align-items: center;
  line-height: 60px;
  > .left {
    display: flex;
    > span {
      font-size: 22px;
      color: #ffffff;
      margin-left: 20px;
    }
    > img {
      height: 34px;
      width: 70px;
      margin-top: 16px;
    }
  }
}

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

.el-main {
  background-color: #e9eef3;
}

.right {
  display: flex;
  margin-top: 20px;
  > .el-tag {
    margin-top: 5px;
    margin-right: 15px;
  }
  > .el-button {
    height: 40px;
  }
}
</style>
