4 changed files with 401 additions and 8 deletions
@ -0,0 +1,202 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="zh-CN"> |
|||
<head> |
|||
<meta charset="UTF-8"> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> |
|||
<title>登录</title> |
|||
<style> |
|||
* { |
|||
margin: 0; |
|||
padding: 0; |
|||
box-sizing: border-box; |
|||
} |
|||
|
|||
body { |
|||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; |
|||
background-color: #f5f5f5; |
|||
color: #333; |
|||
min-height: 100vh; |
|||
display: flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
} |
|||
|
|||
.container { |
|||
max-width: 400px; |
|||
width: 90%; |
|||
background-color: white; |
|||
border-radius: 8px; |
|||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); |
|||
padding: 24px; |
|||
} |
|||
|
|||
.header { |
|||
text-align: center; |
|||
margin-bottom: 24px; |
|||
} |
|||
|
|||
.header h1 { |
|||
font-size: 24px; |
|||
font-weight: 600; |
|||
color: #28a745; |
|||
margin-bottom: 8px; |
|||
} |
|||
|
|||
.header p { |
|||
font-size: 14px; |
|||
color: #666; |
|||
} |
|||
|
|||
.form-group { |
|||
margin-bottom: 16px; |
|||
} |
|||
|
|||
.form-group label { |
|||
display: block; |
|||
margin-bottom: 6px; |
|||
font-size: 14px; |
|||
font-weight: 500; |
|||
color: #333; |
|||
} |
|||
|
|||
.form-group input { |
|||
width: 100%; |
|||
padding: 12px; |
|||
border: 1px solid #ced4da; |
|||
border-radius: 4px; |
|||
font-size: 14px; |
|||
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; |
|||
} |
|||
|
|||
.form-group input:focus { |
|||
outline: none; |
|||
border-color: #28a745; |
|||
box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25); |
|||
} |
|||
|
|||
.btn { |
|||
width: 100%; |
|||
padding: 12px; |
|||
border: none; |
|||
border-radius: 4px; |
|||
font-size: 16px; |
|||
font-weight: 500; |
|||
cursor: pointer; |
|||
transition: background-color 0.15s ease-in-out; |
|||
} |
|||
|
|||
.btn-primary { |
|||
background-color: #28a745; |
|||
color: white; |
|||
} |
|||
|
|||
.btn-primary:hover { |
|||
background-color: #218838; |
|||
} |
|||
|
|||
.error-message { |
|||
background-color: #f8d7da; |
|||
color: #721c24; |
|||
padding: 12px; |
|||
border-radius: 4px; |
|||
margin-bottom: 16px; |
|||
font-size: 14px; |
|||
display: none; |
|||
} |
|||
|
|||
.success-message { |
|||
background-color: #d4edda; |
|||
color: #155724; |
|||
padding: 12px; |
|||
border-radius: 4px; |
|||
margin-bottom: 16px; |
|||
font-size: 14px; |
|||
display: none; |
|||
} |
|||
</style> |
|||
</head> |
|||
<body> |
|||
<div class="container"> |
|||
<div class="header"> |
|||
<h1>登录</h1> |
|||
<p>请输入您的用户名和密码</p> |
|||
</div> |
|||
|
|||
<div class="error-message" id="errorMessage"></div> |
|||
<div class="success-message" id="successMessage"></div> |
|||
|
|||
<form id="loginForm"> |
|||
<div class="form-group"> |
|||
<label for="userName">用户名</label> |
|||
<input type="text" id="userName" name="userName" required> |
|||
</div> |
|||
<div class="form-group"> |
|||
<label for="password">密码</label> |
|||
<input type="password" id="password" name="password" required> |
|||
</div> |
|||
<button type="submit" class="btn btn-primary">登录</button> |
|||
</form> |
|||
</div> |
|||
|
|||
<script> |
|||
// 显示错误信息 |
|||
function showError(message) { |
|||
const errorElement = document.getElementById('errorMessage'); |
|||
const successElement = document.getElementById('successMessage'); |
|||
errorElement.textContent = message; |
|||
errorElement.style.display = 'block'; |
|||
successElement.style.display = 'none'; |
|||
} |
|||
|
|||
// 显示成功信息 |
|||
function showSuccess(message) { |
|||
const errorElement = document.getElementById('errorMessage'); |
|||
const successElement = document.getElementById('successMessage'); |
|||
successElement.textContent = message; |
|||
successElement.style.display = 'block'; |
|||
errorElement.style.display = 'none'; |
|||
} |
|||
|
|||
// 表单提交处理 |
|||
document.getElementById('loginForm').addEventListener('submit', function(e) { |
|||
e.preventDefault(); |
|||
|
|||
const userName = document.getElementById('userName').value.trim(); |
|||
const password = document.getElementById('password').value; |
|||
|
|||
// 验证输入 |
|||
if (!userName || !password) { |
|||
showError('请输入用户名和密码'); |
|||
return; |
|||
} |
|||
|
|||
// 发送登录请求 |
|||
fetch('/login', { |
|||
method: 'POST', |
|||
headers: { |
|||
'Content-Type': 'application/x-www-form-urlencoded' |
|||
}, |
|||
body: new URLSearchParams({ |
|||
userName: userName, |
|||
password: password |
|||
}) |
|||
}) |
|||
.then(response => response.json()) |
|||
.then(data => { |
|||
if (data.success) { |
|||
// 登录成功,保存用户信息到本地存储 |
|||
localStorage.setItem('userInfo', JSON.stringify(data.user)); |
|||
// 跳转到邀请页面 |
|||
window.location.href = 'invite.html'; |
|||
} else { |
|||
showError(data.error || '登录失败,请重试'); |
|||
} |
|||
}) |
|||
.catch(error => { |
|||
console.error('登录失败:', error); |
|||
showError('网络错误,请重试'); |
|||
}); |
|||
}); |
|||
</script> |
|||
</body> |
|||
</html> |
|||
Loading…
Reference in new issue