<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登入 - Telegram bot 后台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/login.css" media="all">
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="app">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>登入 - Bot</h2>
            <p>——&nbsp;&nbsp;&nbsp;&nbsp;Telegram bot 后台</p>
        </div>
        <div 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"></label>
                <input autocomplete="off" type="text" v-model="form.username" name="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"></label>
                <input autocomplete="off" type="password" v-model="form.password" name="password" lay-verify="required" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="submit">登 入</button>
            </div>
        </div>
    </div>

</div>
<script src="/layuiadmin/layui/layui.js"></script>
<script src="/static/js/vue.js"></script>
<script>
    const {createApp} = Vue;
    layui.config({
        base: '/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'user', 'form', 'layer'], function () {
        const $ = layui.$, form = layui.form, layer = layui.layer;
        createApp({
            created() {
                form.render();
                form.on('submit(submit)', () => {
                    this.login();
                });
            },
            data() {
                return {
                    form: {
                        username: '',
                        password: ""
                    }
                }
            },
            methods: {
                login() {
                    $.ajax({
                        url: "/admin/login",
                        method: "POST",
                        data: this.form,
                        success: (res) => {
                            if (res.code === 0) {
                                localStorage.setItem('token', res.data.token);
                                localStorage.setItem('userInfo', JSON.stringify(res.data.userInfo));
                                top.location.href = "/home";
                            } else {
                                layer.alert(res.msg);
                            }
                        }
                    });
                }
            }
        }).mount('#app');
    });
</script>
</body>
</html>
