<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
</head>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>login</title>
    <script src="../static/jquery-3.5.1.min.js"></script>
    <style>
        .login__back{
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            background: url('../static/back.png');
            background-position: center center;
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-size: cover;
        }
        .login__form{
            /* width: 460px;
            height: 410px; */
            width: 410px;
            height: 350px;
            background: url('../static/form.png');
            background-position: center center;
            background-repeat: no-repeat;
            background-size: cover;
            padding: 60px 30px;
            color: rgba(255, 255, 255, 1);
            position: relative;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
        }
        .login__form h2{
            font-size: 28px;
            line-height: 25px;
            text-align: center;
            margin-bottom: 10px;
        }
        .login__form p{
            font-size: 12px;
            text-align: center;
            margin-bottom: 36px;
        }
        .login__form form{
            padding: 0 40px;
            display: flex;
            flex-direction: column;
            background: transparent;
        }
        form input{
            height: 40px;
            margin-bottom: 18px;
            border-radius: 6px;
            color: #FFFFFF;
            padding: 0 16px;
            border: 1px solid rgba(255, 255, 255, 0.5);
            background: transparent;
        }
        form input:focus-within{
            outline: 0;
            border: 1px solid #08EBFE;
        }
        button{
            height: 46px;
            border: none;
            border-radius: 6px;
            background: linear-gradient(0deg, #08EBFE 0%, #28BAC1 100%);
            margin-top: 20px;
            color: #FFFFFF;
            font-size: 16px;
        }
        .form__code{
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 18px;
        }
        .form__code input{
            width: calc(100% - 152px);
            margin-bottom: 0;
        }
        .form__code img{
            width: 100px;
            height: 42px;
            cursor: pointer;
        }
        .login__form .form__tips{
            margin: 0;
            height: 0;
            position: relative;
            top: -14px;
        }
        .form__tips.is--error{
            color: red
        }
    </style>
</head>
<body>
<div class="login__back">
    <div class="login__form">
        <h2>拓恒统一登录平台</h2>
        <p>TUOHENG LOGIN PLATFORM</p>
        <form th:action="@{/login}" method="post">
            <input name="username" placeholder="请输入用户名" type="text"/>
            <input name="password" placeholder="请输入密码" type="password"/>
            <div class="form__code">
                <input name="validateCode" placeholder="请输入验证码" />
                <input id="codekey" name="codekey" type="hidden"/>
                <img class="code__img" src="" />
            </div>
            <div class="form__tips is--error" th:if="${param.error}">
                用户名密码错误，请重新输入！
            </div>
            <div class="form__tips is--error" th:if="${param.validerror}">
                验证码错误，请重新输入！
            </div>
            <div class="form__tips is--error" th:if="${param.expirecode}">
                验证码已过期，请重新输入！
            </div>
            <button type="submit">登 录</button>
        </form>
    </div>
</div>
<!--绑定点击事件 -->
<script>
    const imgDom = document.querySelector('.code__img')
    imgDom.onclick = function() {
        $.ajax({
            url : "/vercode",//后台请求的数据
            dataType: 'json', //数据格式
            type : "post",//请求方式
            async : true,//是否异步请求
            success : function(data) {   //如果请求成功，返回数据。
                var tt = data.data;   //第一个data代表json,第二个data代表json里的数组或对象
                $('.code__img').attr('src', tt.captcha);
                $('#codekey').val(tt.codeKey);
            },
            error : function (arg1) {
                alert("加载数据失败");
                console.log(arg1);
            }
        })
    }

    $(document).ready(function() {
        $.ajax({
            url : "/vercode",//后台请求的数据
            dataType: 'json', //数据格式
            type : "post",//请求方式
            async : true,//是否异步请求
            success : function(data) {   //如果请求成功，返回数据。
                var tt = data.data;   //第一个data代表json,第二个data代表json里的数组或对象
                $('.code__img').attr('src', tt.captcha);
                $('#codekey').val(tt.codeKey);
            },
            error : function (arg1) {
                alert("加载数据失败");
                console.log(arg1);
            }
        })
    })


</script>
</body>
</html>