<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
>
<head>
    <meta charset="utf-8"/>
    <title>登录</title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <link rel="stylesheet" media="all" href="/plugins/layui/css/layui.css"/>
    <link rel="stylesheet" media="all" href="/css/login.css"/>
    <link rel="shortcut icon" type="image/x-icon" href="/img/favicon.ico"/>

    <style type="text/css">
        html, body {
            background: url('/img/lockBg.jpg') fixed center center;
        }
    </style>
</head>
<body>

<div class="login">
    <h1>后台管理登录</h1>
    <form class="layui-form" action="/admin/login" method="post">
        <div class="layui-form-item">
            <input class="layui-input" id="userName" name="userName" placeholder="用户名" lay-verify="required" type="text"
                   autocomplete="off"/>
        </div>
        <div class="layui-form-item">
            <input class="layui-input" id="password" name="password" placeholder="密码" lay-verify="required"
                   type="password" autocomplete="off"/>
        </div>
        <div class="layui-form-item form_code">
            <input class="layui-input" name="randomcode" placeholder="验证码" lay-verify="required" type="text"
                   autocomplete="off"/>
            <div class="code"><img src="/kaptcha" onclick="random(this)" width="116" height="36" id="vdc"
                                   title="看不清,点击换一张"/></div>
        </div>
        <button class="layui-btn login_btn" lay-submit lay-filter="login">登录</button>
        <input id="rememberMe" name="rememberMe" type="checkbox" value="true" title="记住我"/>
    </form>
</div>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script th:inline="javascript">

    layui.use(['element', 'form', 'layer'], function () {
        var form = layui.form, layer = layui.layer, $ = layui.jquery;

        form.on('submit(login)', function (data) {
            $.ajax({
                url: data.form.action,
                type: data.form.method,
                data: $(".layui-form").serialize(),
                dataType: 'json',
                success: function (data) {
                    if (data.code == 0) {
                        location.href = "/admin/index";
                    } else {
                        layer.msg(data.msg, {time: 1000});
                        $('.login_btn').attr('disabled',false);
                        $("#vdc").trigger("click");
                    }
                }
            });
            return false;
        });

    });

    //跳出 iframe 框架
    if (window != top)
        top.location.href = location.href;

    //获取验证码
    function random(tmp) {
        tmp.src = "/kaptcha?_" + Date.now();
    }
</script>
</body>
</html>