Files
Ai_Admin/templates/admin/admin_login.html

155 lines
5.7 KiB
HTML
Raw Normal View History

2024-09-20 04:29:09 +00:00
<!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 {
2024-09-25 12:18:07 +08:00
background: linear-gradient(to right, #e0f7fa, #80deea);
2024-09-20 04:29:09 +00:00
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: 'Arial', sans-serif;
2024-09-25 12:18:07 +08:00
color: #333;
2024-09-20 04:29:09 +00:00
}
.login-container {
width: 400px;
padding: 30px;
2024-09-25 12:18:07 +08:00
background: rgba(255, 255, 255, 0.5);
2024-09-20 04:29:09 +00:00
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
2024-09-25 12:18:07 +08:00
border-radius: 20px;
2024-09-20 04:29:09 +00:00
backdrop-filter: blur(10px);
2024-09-25 12:18:07 +08:00
animation: fadeIn 1s ease-in-out;
position: relative;
2024-09-20 04:29:09 +00:00
}
.login-container h2 {
text-align: center;
margin-bottom: 20px;
2024-09-25 12:18:07 +08:00
color: #333;
2024-09-20 04:29:09 +00:00
}
.layui-btn {
width: 100%;
transition: background 0.3s ease;
}
.layui-btn:hover {
2024-09-25 12:18:07 +08:00
background: #5cb85c;
2024-09-20 04:29:09 +00:00
}
2024-09-25 12:18:07 +08:00
.loading-spinner {
z-index: 99999;
2024-09-20 04:29:09 +00:00
display: none;
2024-09-25 12:18:07 +08:00
border: 4px solid rgba(0, 0, 0, 0.1);
border-radius: 50%;
border-top: 4px solid #5cb85c;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
2024-09-20 04:29:09 +00:00
}
@keyframes fadeIn {
2024-09-25 12:18:07 +08:00
from { opacity: 0; transform: translateY(-20px); }
to { opacity: 1; transform: translateY(0); }
}
.captcha-container {
display: flex;
align-items: center;
justify-content: space-between;
}
.captcha-container .layui-form-label {
flex: 0 0 90px; /* 确保验证码输入框的标签与其他字段一致 */
}
.captcha-container img {
height: 38px;
width: 100px;
cursor: pointer;
}
.captcha-input {
flex-grow: 1;
margin-right: 10px;
2024-09-20 04:29:09 +00:00
}
</style>
</head>
<body>
<div class="login-container">
<h2>管理员登录</h2>
2024-09-25 12:18:07 +08:00
<div class="loading-spinner" id="loadingSpinner"></div>
2024-09-20 04:29:09 +00:00
<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>
2024-09-25 12:18:07 +08:00
<div class="layui-form-item captcha-container">
<label class="layui-form-label">验证码</label>
<input type="text" name="captcha" required lay-verify="required" placeholder="请输入验证码" class="layui-input captcha-input">
<img src="{% url 'captcha_image' %}" alt="验证码" onclick="this.src='{% url 'captcha_image' %}?'+Math.random();">
2024-09-20 04:29:09 +00:00
</div>
2024-09-25 12:18:07 +08:00
<div class="layui-form-item">
<button type="submit" class="layui-btn">登录</button>
2024-09-20 04:29:09 +00:00
</div>
</form>
</div>
2024-09-25 12:18:07 +08:00
2024-09-20 04:29:09 +00:00
<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>
2024-09-25 12:18:07 +08:00
$(document).ready(function() {
2024-09-20 04:29:09 +00:00
var form = layui.form;
2024-09-25 12:18:07 +08:00
var $ = layui.jquery;
2024-09-20 04:29:09 +00:00
var layer = layui.layer;
2024-09-25 12:18:07 +08:00
$('#loginForm').on('submit', function(event) {
event.preventDefault(); // 阻止默认提交行为
$('#loadingSpinner').show(); // 显示加载动画
const username = $('input[name="username"]').val();
const password = $('input[name="password"]').val();
const captcha = $('input[name="captcha"]').val();
2024-09-20 04:29:09 +00:00
$.ajax({
type: 'POST',
2024-09-25 12:18:07 +08:00
url: '{% url "admin_login" %}', // 替换为实际的 URL
2024-09-20 04:29:09 +00:00
contentType: 'application/json',
2024-09-25 12:18:07 +08:00
data: JSON.stringify({ username, password, captcha }),
2024-09-20 04:29:09 +00:00
success: function(response) {
2024-09-25 12:18:07 +08:00
$('#loadingSpinner').hide(); // 隐藏加载动画
layer.msg(response.message); // 使用 Layer.js 显示消息
2024-09-20 04:29:09 +00:00
if (response.code === 200) {
2024-09-25 12:18:07 +08:00
// 登录成功后跳转
setTimeout(function() {
window.location.href = '{% url "admin_home" %}'; // 替换为实际的 URL
}, 1000);
}else if (response.code === 400){
$('img[alt="验证码"]').attr('src', '{% url "captcha_image" %}?'+Math.random());
2024-09-20 04:29:09 +00:00
}
},
2024-09-25 12:18:07 +08:00
error: function(xhr) {
$('#loadingSpinner').hide(); // 隐藏加载动画
const response = xhr.responseJSON;
layer.msg(response.message); // 使用 Layer.js 显示错误消息
2024-09-20 04:29:09 +00:00
}
});
});
});
</script>
2024-09-25 12:18:07 +08:00
2024-09-20 04:29:09 +00:00
</body>
</html>