<template>
  <div class="login">
    <div>
      <div class="avatar-box">
        <img src="../assets/img/icon/u44.png" alt="" />
      </div>
      <van-form @submit="onSubmit">
        <van-field
          border
          v-model="formData.username"
          name="用户名"
          placeholder="请输入用户名"
          :rules="[{ required: true, message: '请输入用户名' }]"
        />
        <van-field
          border
          v-model="formData.password"
          type="password"
          name="密码"
          placeholder="请输入密码"
          :rules="[{ required: true, message: '请输入密码' }]"
        />
        <van-cell value="忘记密码">
          <!-- 使用 title 插槽来自定义标题 -->
          <template #title>
            <div style="display: flex;align-items: center;">
              <van-checkbox class="custom-title" icon-size="15" v-model="checked" shape="square">记住密码</van-checkbox>
            </div>
          </template>
        </van-cell>
<!--        <div>-->
<!--          <van-checkbox v-model="checked" shape="square">记住密码</van-checkbox>-->
<!--          <a href=""> 忘记密码 </a>-->
<!--        </div>-->
        <div style="margin: 16px;">
          <van-button block type="info" native-type="submit">登录</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>2
// 请求接口
import {login} from '@/api/public.js'
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      wechat: `${this.$cdn}/wx/640.gif`,
      formData:{
        username:'admin',
        password:'Admin1234',
      },
      pattern: /\d{6}/,
      checked:false
    }
  },
  computed: {
    ...mapGetters(['userName'])
  },
  mounted() {

  },
  methods: {
    onSubmit(){
      login(this.formData).then(res => {
        console.log(res,'res')
        sessionStorage.setItem('access_token',res.data.access_token);
        this.$router.replace('/home');
      })
    },
  }
}
</script>

<style scoped lang="scss">
.login {
  height: 100vh;
  background: url("../assets/img/登录背景2_app.png") top left no-repeat #edfcff;
  background-size: 100% auto;
  display: flex;
  justify-content: center;
  align-items: center;
  > div {
    width: 450px;
    padding: 30px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #fff;
    border-radius: 10px;
    .avatar-box {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 150px;
      height: 150px;
      border-radius: 100%;
      border: 1px solid #ccc;
    }
  }
  h2 {
    letter-spacing: 10px;
    text-align: center;
  }
}
</style>
