Files
tangfamily/public/admin-login.html
2026-06-24 22:13:01 +08:00

92 lines
4.0 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>管理员登录 - 唐氏族谱</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Microsoft YaHei', Arial, sans-serif;
background: #f0f7ee;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.card {
background: #fff;
border-radius: 16px;
padding: 40px 36px 32px;
box-shadow: 0 4px 24px rgba(120,170,100,0.13);
max-width: 360px;
width: 100%;
border-top: 4px solid #8bc34a;
animation: up .4s ease;
}
@keyframes up { from { opacity:0; transform:translateY(16px);} to { opacity:1; transform:translateY(0);} }
.logo { text-align: center; margin-bottom: 28px; }
.logo h1 { font-size: 24px; color: #558b2f; letter-spacing: 1px; margin-bottom: 4px; }
.logo p { color: #aaa; font-size: 13px; }
label { display: block; margin-bottom: 6px; color: #555; font-size: 14px; }
input[type=password] {
width: 100%; padding: 10px 13px; border: 1.5px solid #d4e8c2;
border-radius: 8px; font-size: 15px; background: #f8fdf3;
transition: border-color .2s, box-shadow .2s; margin-bottom: 18px;
}
input[type=password]:focus { outline: none; border-color: #8bc34a; box-shadow: 0 0 0 3px rgba(139,195,74,.15); }
.btn {
width: 100%; padding: 10px; border: none;
border-radius: 8px; font-size: 14px; font-weight: 600;
cursor: pointer; transition: background .2s, transform .15s; margin-bottom: 8px;
}
.btn-primary { background: #8bc34a; color: #fff; }
.btn-primary:hover { background: #7cb342; transform: translateY(-1px); }
.btn-secondary { background: #f1f8e9; color: #558b2f; border: 1.5px solid #c5e1a5; }
.btn-secondary:hover { background: #e8f5e9; }
.error { color: #e57373; font-size: 13px; margin-top: 8px; text-align: center; display: none; }
.error.show { display: block; }
</style>
</head>
<body>
<div class="card">
<div class="logo">
<h1>管理员登录</h1>
<p>唐氏族谱后台管理</p>
</div>
<form id="loginForm">
<label>管理员密码</label>
<input type="password" id="password" placeholder="请输入管理员密码" required>
<button type="submit" class="btn btn-primary">登录</button>
<button type="button" class="btn btn-secondary" onclick="location.href='/'">返回首页</button>
<div class="error" id="error">密码错误,请重试</div>
</form>
</div>
<script>
document.getElementById('loginForm').addEventListener('submit', async e => {
e.preventDefault();
const err = document.getElementById('error');
err.classList.remove('show');
try {
const res = await fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: document.getElementById('password').value, isAdmin: true })
});
const data = await res.json();
if (data.success && data.isAdmin) {
localStorage.setItem('token', data.token);
localStorage.setItem('isAdmin', 'true');
location.href = '/admin.html';
} else {
err.textContent = data.error || '密码错误,请重试';
err.classList.add('show');
document.getElementById('password').value = '';
}
} catch { err.textContent = '连接失败,请重试'; err.classList.add('show'); }
});
</script>
</body>
</html>