admin-login.html
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<title>管理员登录</title>
<link rel="stylesheet" href="style.css" />
<style>
.login-wrap { max-width: 360px; margin: 15vh auto; padding: 24px; }
.login-wrap h1 { font-size: 18px; margin-bottom: 16px; }
.login-wrap input { width: 100%; margin-bottom: 12px; }
.login-wrap .err { color: #c0392b; font-size: 13px; min-height: 18px; margin-bottom: 8px; }
</style>
</head>
<body>
<div class="login-wrap">
<h1>管理员登录</h1>
<input type="password" id="password" placeholder="管理员口令" autofocus />
<div class="err" id="err"></div>
<button id="loginBtn">登录</button>
</div>
<script>
const params = new URLSearchParams(location.search);
const next = params.get("next") || "/admin.html";
async function login() {
const password = document.getElementById("password").value;
const errBox = document.getElementById("err");
errBox.textContent = "";
try {
const res = await fetch("/api/admin/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ password }),
});
if (!res.ok) {
errBox.textContent = "口令错误";
return;
}
location.href = next;
} catch (e) {
errBox.textContent = "登录请求失败: " + e.message;
}
}
document.getElementById("loginBtn").onclick = login;
document.getElementById("password").addEventListener("keydown", (e) => {
if (e.key === "Enter") login();
});
</script>
</body>
</html>