46 lines
2.2 KiB
HTML
46 lines
2.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>OPC 工作台 · 登录</title>
|
||
<script src="https://cdn.tailwindcss.com"></script>
|
||
</head>
|
||
<body class="min-h-screen bg-slate-50 flex items-center justify-center">
|
||
<div class="bg-white rounded-2xl shadow-lg p-8 w-full max-w-sm mx-4">
|
||
<div class="text-center mb-6">
|
||
<h1 class="text-2xl font-bold text-slate-800">OPC 工作台</h1>
|
||
<p class="text-sm text-slate-400 mt-1">请输入账号密码登录</p>
|
||
</div>
|
||
<form id="loginForm" onsubmit="doLogin(event)" class="grid gap-4">
|
||
<label class="block">
|
||
<span class="text-xs font-medium text-slate-500">账号</span>
|
||
<input name="username" required class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm" placeholder="admin / kepu / keyan / yihuan" autofocus>
|
||
</label>
|
||
<label class="block">
|
||
<span class="text-xs font-medium text-slate-500">密码</span>
|
||
<input name="password" type="password" required class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm">
|
||
</label>
|
||
<p id="loginError" class="text-red-500 text-xs hidden"></p>
|
||
<button type="submit" class="btn w-full bg-slate-800 text-white rounded-lg py-2.5 text-sm font-medium hover:bg-slate-700">登 录</button>
|
||
</form>
|
||
<p class="text-xs text-slate-400 text-center mt-6">默认管理员:qiukai / yxcowork2026</p>
|
||
</div>
|
||
<script>
|
||
async function doLogin(e) {
|
||
e.preventDefault();
|
||
const form = e.currentTarget;
|
||
const data = Object.fromEntries(new FormData(form).entries());
|
||
try {
|
||
const res = await (await fetch("/api/auth/login", { method: "POST", headers: {"Content-Type":"application/json"}, body: JSON.stringify(data) })).json();
|
||
if (res.error) { document.querySelector("#loginError").textContent = res.error; document.querySelector("#loginError").classList.remove("hidden"); return; }
|
||
window.location.href = "/";
|
||
} catch (err) {
|
||
document.querySelector("#loginError").textContent = "网络错误,请重试";
|
||
document.querySelector("#loginError").classList.remove("hidden");
|
||
}
|
||
}
|
||
</script>
|
||
</body>
|
||
</html>
|