<template>
  <div class="login">
    <div class="loginav">
      <div class="video">
        <video src="../assets/video/video.mp4" muted autoplay loop></video>
      </div>
      <div class=""></div>
      <div class="loginbox boxall">
        <div class="logo">
          <h1>小型无人机目标检测系统</h1>
          <h2>Small UAV target detection system</h2>
        </div>
        <div class="logintit">用户登录</div>
        <ul class="logininput">
          <li>
            <i><img src="../assets/image/user.png"></i>
            <input class="forminput" v-model.trim="userInfo.username" type="text" placeholder="用户名">
          </li>
          <li>
            <i><img src="../assets/image/password.png"></i>
            <input class="forminput" type="password" v-model.trim="userInfo.password" placeholder="密码">
          </li>
          <div class=" flex1" style="padding: 15px 0;">
            <label> <input type="checkbox" v-model="rememberPassword" class="aui-checkbox" >&nbsp;记住密码</label>
            <a href="#" class="text-primary" @click="register"> 注册新账号</a>
            <a href="#" class="text-primary" @click="setBackApiView">后端接口</a>
          </div>
          <li>
            <a href="#" class="btn btnblock btn-lg btn-block btn-primary" @click="login">登录</a>
          </li>

        </ul>
        <div class="boxfoot"></div>
      </div>
    </div>

    <el-dialog
      title="后端API设置"
      :visible.sync="dialogVisible"
      width="30%"
      :close-on-click-modal="false"
    >
      <el-input v-model="backAPi" placeholder="请输入后端网址"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="setBackApi()">确 定</el-button>
      </span>
    </el-dialog>


  </div>
</template>

<script>
import { PostData } from '@/api';
import {setCookie } from "@/utils/cookie"
import qs from 'qs';
export default {
  data() {
    return {
      userInfo:{
        username:null,
        password:null
      },
      rememberPassword:true,
      backAPi:null,
      dialogVisible:false,
    }
  },
  created() {
    
  },
  mounted(){
    let userInfoString  = localStorage.getItem('userInfo')
    if(userInfoString){
      this.userInfo = qs.parse(userInfoString)
    }
    
    let backAPi = localStorage.getItem("backapi")
    
    if(backAPi){  
      this.backAPi = backAPi
    }else{
      this.backAPi = "http://127.0.0.1:8080"
      localStorage.setItem("backapi",this.backAPi);
    }
  },
  methods: {

    login(){
      if(this.userInfo.username == " " ||this.userInfo.username == null){
        this.$message.warning("请输出用户名")
        return
      }
      if(this.userInfo.password == " " ||this.userInfo.password == null){
        this.$message.warning("请输入密码")
        return
      }

      PostData("/user/login",qs.stringify(this.userInfo)).then(res=>{
        console.log(res)
        if(this.rememberPassword){
          localStorage.setItem('userInfo',qs.stringify(this.userInfo))
          sessionStorage.setItem("X-CSRFToken",res["X-CSRFToken"])
          setCookie("csrftoken",res["X-CSRFToken"])
          this.$router.push("/home")
        }else{
          sessionStorage.setItem("crsf_token","")
          localStorage.setItem('userInfo',"")         
        }
      }).catch(error=>{
        console.log(error)
        this.$message.error("登录失败")
      })

    },
    register(){
      this.$router.push("/register")
    },
    setBackApiView(){
      this.dialogVisible = true
    },
    setBackApi(){

      localStorage.setItem("backapi",this.backAPi);
      this.dialogVisible = false
    }
  },
}
</script>

<style scoped lang="scss">

li {
  list-style-type: none;
}

a {
  text-decoration: none;
  color: #fff;
}



.login {
  background: #000;
  max-width: 1920px;
  margin: 0 auto;
  height: 100%;
  position: relative;
  font-family: "PingFang SC", "Lantinghei SC", "Microsoft YaHei", "HanHei SC", "Helvetica Neue", "Open Sans", Arial, "Hiragino Sans GB", "微软雅黑", STHeiti, "WenQuanYi Micro Hei", SimSun, sans-serif;
}

.login::before {
  position: absolute;
  width: 100%;
  height: 100%;
  background: url(../assets/image/bg.png) no-repeat left center;
  content: "";
  left: 0;
  top: 0;
  z-index: 100;
  pointer-events: none;
}

.loginbg {
  background-image: linear-gradient(300deg, #004491, #1e88e5);
  position: absolute;
  width: 100%;
  height: 50%;
  left: 0;
  top: 0;
  z-index: 0
}

.loginav {
  max-width: 1300px;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  z-index: 10;
  box-shadow: 0 0 30px rgba(0, 0, 0, .1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.video {
  position: absolute;
  width: 1200px;
  left: 0px;
  padding-bottom: 40px;
  pointer-events: none;
}

.video video {
  width: 100%;
}

.video::before {
  position: absolute;
  content: "";
  width: 200px;
  height: 100%;
  background: #000;
  right: 0;
  top: 0;
}

.logotit {
  text-align: center;
  padding: 40px 0;
  font-size: 30px
}

.loginbox {
  padding: 30px 0 50px 0;
  width: 600px;
  padding: 30px 50px;
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

.logininput .forminput {
  border: 2px solid rgba(32, 163, 245, .4);
  font-family: "PingFang SC", "Lantinghei SC", "Microsoft YaHei", "HanHei SC", "Helvetica Neue", "Open Sans", Arial, "Hiragino Sans GB", "微软雅黑", STHeiti, "WenQuanYi Micro Hei", SimSun, sans-serif;
  display: block;
  padding-left: 50px;
  font-size: 18px;
  color: #fff;
  width: 100%;
  line-height: 48px;
  outline: 0;
  text-indent: 1px;
  background: rgba(32, 163, 245, .1);
}

input::input-placeholder {
  color: #fff;
}

::-webkit-input-placeholder {
  color: #fff;
}


.flex1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.flex1 label {
  color: #fff;
  display: flex;
  align-items: center;
}

.logininput>li {
  display: block;
  padding: 15px 0;
  position: relative;
}

.logininput li>i {
  position: absolute;
  height: 100%;
  left: 15px;
  top: 0;
  display: flex;
  align-items: center;
}

.logintit {
  color: #00bff4;
  text-align: center;
  position: relative;
  padding: 25px 0;
  font-size: 24px
}

.btn-primary {
  background: #20a3f5;
  display: block;
  text-align: center;
  color: #fff;
  line-height: 48PX;
  font-size: 24px;
}

.btn-primary:hover {
  background: #137bd6
}

.copyright {
  position: fixed;
  width: 100%;
  left: 0;
  bottom: 10px;
  text-align: center;
  color: #006b95;
  font-size: 12px
}

.logo {
  position: absolute;
  top: -120px;
  width: 100%;
  left: 0;
  text-align: center;
  color: #fff;
}

.logo h1,
.logo h2 {
  background: linear-gradient(90deg, #009ef3, #00e9d0);
  background-size: cover;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-fill-color: transparent;
}

.logo h1 {
  font-weight: bolder;
  font-size: 48px;
  font-family: "Microsoft YaHei", "HanHei SC";
  letter-spacing: 2px;
}

.logo h2 {
  font-size: 30px;
  text-transform: uppercase;
  font-weight: lighter;
  letter-spacing: 2px;
}

.boxall {
  border: 2px solid #186baf;
  background: rgba(32, 163, 245, .1);
  position: relative;
  transform: scale(.7);
  opacity: 0;
  animation: shows 1s forwards;
}

@keyframes shows {
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.boxall:before,
.boxall:after {
  position: absolute;
  width: 30px;
  height: 30px;
  content: "";
  border-top: 3px solid #20a3f5;
  top: -2px;
}

.boxall:before,
.boxfoot:before {
  border-left: 3px solid #20a3f5;
  left: -2px;
}

.boxall:after,
.boxfoot:after {
  border-right: 3px solid #20a3f5;
  right: -2px;
}

.boxfoot {
  position: absolute;
  bottom: 0;
  width: 100%;
  left: 0;
}

.boxfoot:before,
.boxfoot:after {
  position: absolute;
  width: 30px;
  height: 30px;
  content: "";
  border-bottom: 3px solid #20a3f5;
  bottom: -2px;
}


.aui-checkbox,
input[type=radio] {
  width: 24px;
  height: 24px;
  background: rgba(32, 163, 245, .1);
  border: solid 2px rgba(32, 163, 245, .5);
  margin: 0;
  padding: 0;
  position: relative;
  cursor: default;
  -webkit-appearance: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-transition: background-color ease .1s;
  transition: background-color ease .1s;
  flex-shrink: 0;
  border-radius: 0;
}

.aui-checkbox,
input[type=radio] {
  margin: 0 3px 0 0 !important;
  position: relative;
}

.aui-checkbox:checked,
input[type=radio]:checked {
  text-align: center;
  background-clip: padding-box;
}

.aui-checkbox:checked:after,
.aui-checkbox:checked:before,
input[type=radio]:checked:after,
input[type=radio]:checked:before {
  content: '';
  width: 10px;
  height: 5px;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-left: -6px;
  margin-top: -5px;
  background: 0 0;
  border: 2px solid #439aff;
  border-top: none;
  border-right: none;
  z-index: 2;
  -webkit-border-radius: 0;
  border-radius: 0;
  -webkit-transform: rotate(-45deg);
  transform: rotate(-45deg)
}

.aui-checkbox:disabled,
input[type=radio]:disabled {
  background-color: #f5f5f5;
  border: solid 1px #ddd
}

.aui-checkbox:disabled:after,
.aui-checkbox:disabled:before,
input[type=radio]:disabled:after,
input[type=radio]:disabled:before {
  content: '';
  width: .5rem;
  height: .3rem;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-left: -.25rem;
  margin-top: -.4rem;
  background: 0 0;
  border: 1px solid #fff;
  border-top: none;
  border-right: none;
  z-index: 2;
  -webkit-border-radius: 0;
  border-radius: 0;
  -webkit-transform: rotate(-45deg);
  transform: rotate(-45deg)
}

input[type="radio"] {
  border-radius: 20px;
}

input {
  outline: none !important;
}



@media (max-width: 1200px) {
  .loginav {
    justify-content: center;
  }

  .video {
    display: none;
  }

  .loginbox {
    width: 96%;
  }

  .logo h1 {
    font-size: 30px;
  }

  .logo h2 {
    font-size: 20px;
  }

  .loginbox {
    padding: 30px;
  }
}
</style>