<template>
  <div class="main">
    <div class="container">
      <h3 class="title">测试平台</h3>
      <el-select v-model="namespace" placeholder="请选择环境" @change="handleSelectChange" style="width: 100%; margin-top: 20px">
        <el-option v-for="item in nsOptions" :key="item.key" :label="item.desc" :value="item.key"></el-option>
      </el-select>
      <el-button type="primary" style="width: 100%; margin-top: 40px;" @click="login">登录</el-button>
    </div>
  </div>
</template>

<script>
import { getNamespaceList } from '@/api/getXyqbData/'
export default {
  data() {
    return {
      namespace: '',
      nsOptions: []
    }
  },
  methods: {
    //   给store.state.env赋值
    handleSelectChange() {
      window.sessionStorage.setItem('env', this.namespace)
    },
    login() {
      if (this.namespace === '') {
        return this.$message.error('请先选择环境')
      }
      this.$router.push('/main')
    },
    getNamespaceList() {
      getNamespaceList().then((resp) => {
        this.nsOptions = resp.data.data
      })
    }
  },
  created() {
    this.getNamespaceList()
  }
}
</script>

<style lang="less" scoped>
.main {
  position: fixed;
  height: 100%;
  width: 100%;
  background-color: #2d3a4b;
  .container {
    height: 300px;
    width: 500px;
    margin: 200px auto;
    padding: 20px;
  }
}
.title {
  text-align: center;
  font-size: 26px;
  color: #ffffff;
}

.area {
  margin-top: 40px;
}
</style>
