<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>[[${prj_name}]]</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/layui/css/login.css}">
    <link rel="icon" th:href="@{/image/sgl.png}" sizes="32x32">
    <script th:src="@{/layui/layui.js}"></script>
    <script th:src="@{/layui/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/js/common.js}"></script>
    <script th:src="@{/js/rem.js}"></script>
    <style>
        .layadmin-user-login-main{
            background-color: #0070FE;
            border-radius: 5px;
        }
    </style>
    <script>
        <!-- 解决登录页面嵌套问题 -->
        if (window != top){
            top.location.href = location.href;
        }
    </script>
</head>

<body>
<div class="contain">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2 style="color:#FFFFFF;font-size: 6rem;font-weight: 900;">登录</h2>
        </div>

        <div class="layui-row">
            <form class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                    <input type="text" name="username" id="username" lay-verify="required" placeholder="用户名" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="password" lay-verify="required" placeholder="密码" class="layui-input">
                </div>

                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                            <input type="text" name="vercode" id="vercode" lay-verify="required" placeholder="验证码"  class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <img src="/getCode" class="layadmin-user-login-codeimg" onclick="refreshCode();" id="code_img">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <span style="color: white;float: right;">忘记密码请联系管理员</span>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" style="background: #FF8B25;margin-top: 2rem;" lay-submit="" lay-filter="login">登 录</button>
                </div>
            </form>
        </div>
    </div>
    <div class="Girl">
        <img th:src="@{/image/loginGirl.svg}">
    </div>
    <div class="Boy">
        <img th:src="@{/image/loginBoy.svg}">
    </div>
</div>


<script>
    layui.use(['form','layer','jquery'], function(){
        var $ = layui.jquery,
            form = layui.form;
    +
        form.on("submit(login)",function () {
            var username = $("#username").val();
            var password = $("#password").val();
            var param = {};

            var vercode = $("#vercode").val();
            param.username = username;
            param.password = password;
            param.vercode = vercode;
            $.ajax({
                url:"/login",
                type:"post",
                dataType:"json",
                contentType: "application/json; charset=UTF-8",
                data:JSON.stringify(param),
                success:function(data){
                    if(data.errCode == '0'){
                        window.location.href = "/index";
                    }else{
                        layer.msg(data.errMsg,{time:1000});
                    }
                },
                error:function(){

                }
            })
            return false;
        });
    });

    function refreshCode(){
        $("#code_img").attr("src","/getCode?d"+new Date().getTime());
    }
</script>
</body>
</html>