Files
diary-system/frontend/login.html

150 lines
4.6 KiB
HTML
Raw Normal View History

<!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: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.auth-card {
background: white;
padding: 40px;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0,0,0,0.2);
width: 100%;
max-width: 400px;
}
.auth-card h1 {
color: #667eea;
font-size: 2em;
text-align: center;
margin-bottom: 10px;
}
.auth-card h2 {
color: #333;
font-size: 1.5em;
text-align: center;
margin-bottom: 30px;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
color: #555;
font-weight: 500;
margin-bottom: 8px;
}
.form-group input {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 1em;
}
.form-group input:focus {
outline: none;
border-color: #667eea;
}
.btn-primary {
width: 100%;
padding: 12px;
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
border: none;
border-radius: 5px;
font-size: 1.1em;
font-weight: 600;
cursor: pointer;
}
.btn-primary:hover {
opacity: 0.9;
}
.error {
background: #fee;
color: #c00;
padding: 10px;
border-radius: 5px;
margin-bottom: 20px;
text-align: center;
}
.success {
background: #efe;
color: #0a0;
padding: 10px;
border-radius: 5px;
margin-bottom: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="auth-card">
<h1>⚡ 码神的日记系统</h1>
<h2>登录</h2>
<div id="message"></div>
<form id="loginForm">
<div class="form-group">
<label>用户名</label>
<input type="text" id="username" required placeholder="请输入用户名" />
</div>
<div class="form-group">
<label>密码</label>
<input type="password" id="password" required placeholder="请输入密码" />
</div>
<button type="submit" class="btn-primary">登录</button>
</form>
<p style="text-align: center; margin-top: 20px; color: #666;">
默认账号beijixing / beijixing123
</p>
</div>
<script>
const API_BASE = '/api';
document.getElementById('loginForm').addEventListener('submit', async (e) => {
e.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
const messageDiv = document.getElementById('message');
try {
const res = await fetch(`${API_BASE}/auth/login/`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
const data = await res.json();
if (res.ok) {
messageDiv.innerHTML = `<div class="success">✅ 登录成功!正在跳转...</div>`;
setTimeout(() => {
window.location.href = '/dashboard.html';
}, 1000);
} else {
messageDiv.innerHTML = `<div class="error">❌ ${data.message || '登录失败'}</div>`;
}
} catch (err) {
messageDiv.innerHTML = `<div class="error">❌ 网络错误:${err.message}</div>`;
}
});
</script>
</body>
</html>