124 lines
4.6 KiB
HTML
Executable File
124 lines
4.6 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>管理员登录</title>
|
|
<link rel="stylesheet" href="https://file.guimiaokeji.com/layui/css/layui.css">
|
|
<style>
|
|
body {
|
|
background: linear-gradient(to right, #6a11cb, #2575fc);
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
margin: 0;
|
|
font-family: 'Arial', sans-serif;
|
|
color: #fff;
|
|
}
|
|
.login-container {
|
|
width: 400px;
|
|
padding: 30px;
|
|
background: rgba(255, 255, 255, 0.1);
|
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
|
border-radius: 10px;
|
|
animation: fadeIn 1s ease-in-out;
|
|
backdrop-filter: blur(10px);
|
|
text-align: center;
|
|
}
|
|
.login-container h2 {
|
|
text-align: center;
|
|
margin-bottom: 20px;
|
|
color: #fff;
|
|
}
|
|
.layui-btn {
|
|
width: 100%;
|
|
transition: background 0.3s ease;
|
|
}
|
|
.layui-btn:hover {
|
|
background: linear-gradient(45deg, #3b82ec, #2196f3);
|
|
}
|
|
.loading {
|
|
display: none;
|
|
}
|
|
@keyframes fadeIn {
|
|
from {
|
|
opacity: 0;
|
|
transform: translateY(-20px);
|
|
}
|
|
to {
|
|
opacity: 1;
|
|
transform: translateY(0);
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<h2>管理员登录</h2>
|
|
<form class="layui-form" id="loginForm">
|
|
{% csrf_token %}
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">用户名</label>
|
|
<div class="layui-input-block">
|
|
<input type="text" name="username" required lay-verify="required" placeholder="请输入用户名" class="layui-input">
|
|
</div>
|
|
</div>
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">密码</label>
|
|
<div class="layui-input-block">
|
|
<input type="password" name="password" required lay-verify="required" placeholder="请输入密码" class="layui-input">
|
|
</div>
|
|
</div>
|
|
<div class="layui-form-item">
|
|
<button class="layui-btn layui-btn-normal" lay-submit lay-filter="login">登录</button>
|
|
</div>
|
|
<div id="error-msg" style="display: none;">
|
|
<p style="color: red;">用户名或密码错误</p>
|
|
</div>
|
|
<div class="loading">
|
|
<div class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop" style="font-size: 40px;"></div>
|
|
<p>登录中,请稍候...</p>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<script src="https://file.guimiaokeji.com/layui/jquery-3.6.0.min.js"></script>
|
|
<script src="https://file.guimiaokeji.com/layui/layui.js"></script>
|
|
<script>
|
|
layui.use(['form', 'layer'], function() {
|
|
var form = layui.form;
|
|
var layer = layui.layer;
|
|
|
|
form.on('submit(login)', function(data) {
|
|
document.querySelector('.loading').style.display = 'block';
|
|
document.getElementById('loginForm').style.display = 'none';
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '{% url "admin_login" %}',
|
|
data: JSON.stringify(data.field),
|
|
contentType: 'application/json',
|
|
success: function(response) {
|
|
document.querySelector('.loading').style.display = 'none';
|
|
if (response.code === 200) {
|
|
layer.msg(response.message, {icon: 1, time: 2000}, function() {
|
|
window.location.href = '{% url "admin_home" %}';
|
|
});
|
|
} else {
|
|
document.getElementById('loginForm').style.display = 'block';
|
|
layer.msg(response.message, {icon: 2, time: 2000});
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
document.querySelector('.loading').style.display = 'none';
|
|
document.getElementById('loginForm').style.display = 'block';
|
|
layer.msg('登录失败,请稍后重试。', {icon: 2, time: 2000});
|
|
}
|
|
});
|
|
|
|
return false; // 阻止表单跳转。如果需要表单跳转,去掉这段即可。
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|