<template>
  <div class="body">
    <el-card class="login-card">
      <div class="login-card-logo">
        <img class="login-card-logo" src="../assets/logo.jpg" alt="logo"/>
      </div>
      <el-form :model="loginForm" ref="loginFormRef" label-width="60px" size="large">
        <el-form-item prop="username" label="用户名">
          <el-input :prefix-icon="UserFilled" v-model="loginForm.username" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item prop="password" label="密码">
          <el-input :prefix-icon="Lock" type="password" v-model="loginForm.password" show-password placeholder="密码"/>
        </el-form-item>
        <div class="dialog-footer" style="display: flex;justify-content: center">
          <el-button type="primary" @click="onSubmit">登录</el-button>
        </div>
      </el-form>

    </el-card>
  </div>
</template>
<script setup lang="ts">
import {reactive} from "vue";
import {Lock, UserFilled} from "@element-plus/icons-vue";
import {arkLogin, LoginInfo} from "../api/Login.ts";
import router from "../router";


let loginForm = reactive(LoginInfo.Create())
//初始化检查，是否已经登录
if (localStorage.getItem("token")) {
  router.push({path:"/back/base"})
}

function onSubmit() {
  arkLogin(loginForm).then(res => {
    if (res.code == 200) {
      localStorage.setItem("token", res.data.token)
      router.push({path:"/back/base"})
    }
  })
}

</script>
<style scoped>
.body {
  width: 100VW;
  height: 100VH;
  display: flex;
  justify-content: center;
  flex-direction: column;
  transform: translateY(-100px);

  .login-card {
    width: 380px;
    height: 300px;
    margin: 0 auto;

    .login-card-logo {
      display: flex;
      justify-content: center;
      align-items: center;

      img {
        margin: 8px 0 25px;
      }
    }
  }
}
</style>