Files
xbxs/templates/login.html
2025-12-14 22:21:03 +08:00

55 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<title>登录</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="min-h-screen flex items-center justify-center bg-gray-100">
<div class="w-full max-w-sm bg-white rounded-xl shadow-lg p-8">
<h2 class="text-2xl font-bold text-center mb-6">登录</h2>
<div class="space-y-4">
<input id="username" type="text" placeholder="用户名"
class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring" />
<input id="password" type="password" placeholder="密码"
class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring" />
<button onclick="login()"
class="w-full bg-blue-600 text-white py-2 rounded-lg hover:bg-blue-700 transition">
登录
</button>
</div>
<p id="error" class="text-red-500 text-sm mt-4 hidden"></p>
</div>
<script>
async function login() {
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;
const res = await fetch("/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ username, password }),
});
if (res.ok) {
window.location.href = "/home";
} else {
document.getElementById("error").innerText = "登录失败";
document.getElementById("error").classList.remove("hidden");
}
}
</script>
</body>
</html>