165 lines
5.2 KiB
HTML
165 lines
5.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>登录 - 南日AI</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body {
|
|
font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
|
|
background: #d8e4ec;
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 40px;
|
|
}
|
|
.header {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
height: 56px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 0 24px;
|
|
background: rgba(255,255,255,0.5);
|
|
}
|
|
.header-title { font-size: 18px; font-weight: 600; color: #333; }
|
|
.login-box {
|
|
background: #fff;
|
|
border: 1px solid #b8d4e3;
|
|
border-radius: 12px;
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
|
|
padding: 40px;
|
|
width: 100%;
|
|
max-width: 380px;
|
|
}
|
|
.login-title {
|
|
font-size: 24px;
|
|
font-weight: 600;
|
|
color: #333;
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
font-size: 14px;
|
|
color: #555;
|
|
margin-bottom: 8px;
|
|
}
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 12px 14px;
|
|
font-size: 14px;
|
|
border: 1px solid #b8d4e3;
|
|
border-radius: 8px;
|
|
outline: none;
|
|
transition: border-color 0.2s;
|
|
background: #fff;
|
|
}
|
|
.form-group input:focus {
|
|
border-color: #3498db;
|
|
}
|
|
.error-msg {
|
|
color: #e74c3c;
|
|
font-size: 13px;
|
|
margin-bottom: 12px;
|
|
text-align: center;
|
|
}
|
|
.btn-login {
|
|
width: 100%;
|
|
padding: 14px;
|
|
font-size: 16px;
|
|
font-weight: 500;
|
|
color: #fff;
|
|
background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
|
|
border: none;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
}
|
|
.btn-login:hover {
|
|
opacity: 0.9;
|
|
}
|
|
.btn-login:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<header class="header">
|
|
<span class="header-title">南日AI</span>
|
|
</header>
|
|
|
|
<div class="login-box">
|
|
<h1 class="login-title">登录</h1>
|
|
{% if error %}
|
|
<p class="error-msg">{{ error }}</p>
|
|
{% endif %}
|
|
<form id="loginForm" method="POST" action="/login">
|
|
<div class="form-group">
|
|
<label>用户名</label>
|
|
<input type="text" name="username" placeholder="请输入用户名" required autofocus>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>密码</label>
|
|
<input type="password" name="password" placeholder="请输入密码" required>
|
|
</div>
|
|
<button type="submit" class="btn-login" id="btnLogin">登录</button>
|
|
</form>
|
|
</div>
|
|
<script>
|
|
(function() {
|
|
fetch('/api/auth/check', { credentials: 'same-origin' })
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(res) {
|
|
if (res.logged_in && res.redirect) {
|
|
window.location.href = res.redirect;
|
|
}
|
|
})
|
|
.catch(function() {});
|
|
})();
|
|
document.getElementById('loginForm').onsubmit = function(e) {
|
|
e.preventDefault();
|
|
var btn = document.getElementById('btnLogin');
|
|
btn.disabled = true;
|
|
btn.textContent = '登录中...';
|
|
var form = e.target;
|
|
var fd = new FormData(form);
|
|
fetch(form.action, {
|
|
method: 'POST',
|
|
body: fd,
|
|
headers: { 'X-Requested-With': 'XMLHttpRequest' }
|
|
})
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(res) {
|
|
if (res.success) {
|
|
window.location.href = res.redirect || '/admin';
|
|
} else {
|
|
var errEl = document.querySelector('.error-msg');
|
|
if (!errEl) {
|
|
errEl = document.createElement('p');
|
|
errEl.className = 'error-msg';
|
|
form.insertBefore(errEl, form.firstChild);
|
|
}
|
|
errEl.textContent = res.error || '登录失败';
|
|
btn.disabled = false;
|
|
btn.textContent = '登录';
|
|
}
|
|
})
|
|
.catch(function() {
|
|
form.submit();
|
|
});
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|