<!--
 * @Author: your name
 * @Date: 2021-01-11 11:14:26
 * @LastEditTime: 2022-04-28 18:35:39
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue3-element-admin\src\views\Login.vue
-->
<template>
  <div class="backdrop-layer">
    <div class="head">
      <div class="logo"></div>
      <div class="title">飞鸟智慧巡园平台

      </div>
    </div>
    <div class="ve_container">
      <el-card style="height: 300px" :body-style="{ background: '#ffffff' }">
        <h1>用户登录</h1>
        <transition name="el-fade-in-linear">
          <el-form
              :model="form"
              :rules="rules"
              v-show="!success"
              class="ve_form"
              ref="ref_form"
              :inline="false"
              @keyup.enter="onSubmit"
          >
            <el-form-item prop="phone">
              <el-input
                  size="large"
                  v-model.trim="phone"
                  placeholder="用户名"
              >
                <template #prepend>
                  <el-icon :size="20"><Iphone /></el-icon>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item prop="code">
              <el-input
                  size="large"
                  v-model.trim="code"
                  placeholder="验证码"
              >
                <template #prepend>
                  <el-icon :size="20"><Key /></el-icon>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item>
              <div style="width: 50%;float: left;text-align: left;"><el-checkbox >记住密码</el-checkbox></div>
              <div style="width: 50%;float: left;">
                <el-button
                    class="ve_submit"
                    type="primary"
                    @click="onSubmit"
                >
                  登录
                </el-button>
              </div>
            </el-form-item>
          </el-form>
        </transition>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import {SET_TOKEN, SET_UNAME, SET_USER_INFO} from "@/store/modules/app/type";
import Common from "@/components/Common";
import { ref, reactive, toRefs } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";

const rules = {
  phone: [{ required: true, message: "请输入用户名", trigger: "blur" }]
};

// const rules = {
//   phone: [{ required: true, message: "请输入用户名", trigger: "blur" }]
//   ,
//   code: [{ required: true, message: "请输入验证码", trigger: "blur" }
//   ],
// };

const store = useStore();
const router = useRouter();
const form = reactive({
  "code": "",
  "phone": "游客"
});
const { phone, code } = toRefs(form);
const ref_form = ref(null);
const success = ref(false);
sessionStorage.clear();
store.commit(`app/${SET_TOKEN}`, "");
router.options.isAddDynamicMenuRoutes = false;


const onSubmit = () => {
    ref_form.value.validate(async (valid) => {
        if (valid) {
            const res = await VE_API.system.phoneLogin(form);
            if (res.code == 0) {
                const { token, userName, djiCloudToken } = res.data;
                store.commit(`app/${SET_TOKEN}`, token);
                store.commit(`app/djiCloudToken`, djiCloudToken);
                store.commit(`app/${SET_UNAME}`, userName);
                res.data["token"] = undefined
                res.data["x-auth-token"] = undefined
                res.data["pwd"] = undefined
                store.commit(`app/${SET_USER_INFO}`, JSON.stringify(res.data));
                success.value = true;
                // router.push({ name: "Home" });
                router.push({ name: "warningHome" });
            }
        } else {
            return;
        }
    });
};
</script>

<style lang="scss" scoped>
.ve_container {
  position: absolute;
  z-index: 1;
  width: 400px;
  top: calc(50%);
  left: calc(50% - 250px);
  transform: translateY(-50%);
  transition: all 1s;
  min-height: 273px;
  text-align: center;
  h1 {
    font-size: 24px;
    transition: all 1s;
    font-weight: normal;
    text-align: left;
    margin-bottom: 36px;
  }
  .ve_form {
    .ve_submit {
      width: 100%;
      height: 45px;
      background: #0BC678;
    }
  }
}
.backdrop-layer{
  position: absolute;
  top: 0px;
  bottom: 0px;
  left: 0px;
  right: 0px;
  background: url(@/assets/login_bg.jpg) no-repeat;
  background-size:100% 100%;
  z-index: 1;
  overflow: hidden;
}
.head{
  position: absolute;
  left: 300px;
  top: 100px;
  display: flex;
  align-items: center;
  padding: 50px;
  .title{
    font-size: 30px;
    font-weight: bold;
    color:#006600;
    float: left;
    line-height: 50px;
    margin-left: 20px;
  }
  .logo{
    width: calc(167px * 0.5);
    height: calc(245px * 0.5);
    background: url(@/assets/img/logo-verticle.png) no-repeat;
    background-size:100% 100%;
    float: left;
    z-index: 1000;
  }
}
</style>
