52 lines
1.9 KiB
HTML
Executable File
52 lines
1.9 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>登录 - Linux 系统运维监控</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
</head>
|
|
<body class="bg-gray-100 font-sans flex items-center justify-center h-screen">
|
|
<div class="bg-white p-8 rounded shadow-md w-full max-w-md">
|
|
<h1 class="text-2xl font-bold mb-6 text-center">登录</h1>
|
|
<div>
|
|
<div class="mb-6">
|
|
<label class="block text-gray-700 mb-2" for="password">密码</label>
|
|
<input id="password" type="password" class="w-full px-3 py-2 border rounded" placeholder="请输入密码">
|
|
</div>
|
|
<button id="login" class="w-full bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">登录</button>
|
|
<p id="error" class="text-red-500 mt-4 hidden"></p>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.getElementById('login').addEventListener('click', async () => {
|
|
const password = document.getElementById('password').value;
|
|
const errorEl = document.getElementById('error');
|
|
|
|
try {
|
|
const response = await fetch('/api/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ password })
|
|
});
|
|
|
|
const data = await response.json();
|
|
if (response.ok) {
|
|
console.log('Login successful, redirecting to /');
|
|
window.location.href = '/';
|
|
} else {
|
|
errorEl.textContent = data.error || '登录失败';
|
|
errorEl.classList.remove('hidden');
|
|
}
|
|
} catch (error) {
|
|
console.error('Login error:', error);
|
|
errorEl.textContent = '网络错误';
|
|
errorEl.classList.remove('hidden');
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |