Files
yixiaogao/frontend/register.html
2025-11-26 14:32:55 +08:00

701 lines
22 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>用户注册 - 易搜高</title>
<meta name="keywords" content="用户注册,易搜高,自媒体监控">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.register-container {
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
overflow: hidden;
width: 100%;
max-width: 900px;
min-height: 600px;
display: flex;
animation: slideUp 0.6s ease-out;
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.register-left {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 60px 40px;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
position: relative;
overflow: hidden;
}
.register-left::before {
content: '';
position: absolute;
top: -50%;
right: -50%;
width: 200%;
height: 200%;
background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
animation: rotate 30s linear infinite;
}
@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.register-left h1 {
font-size: 2.5em;
margin-bottom: 20px;
font-weight: 700;
position: relative;
z-index: 1;
}
.register-left p {
font-size: 1.1em;
line-height: 1.6;
opacity: 0.9;
margin-bottom: 30px;
position: relative;
z-index: 1;
}
.feature-list {
list-style: none;
position: relative;
z-index: 1;
}
.feature-list li {
padding: 10px 0;
display: flex;
align-items: center;
gap: 10px;
}
.feature-list li::before {
content: '✓';
background: rgba(255, 255, 255, 0.2);
width: 20px;
height: 20px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
}
.register-right {
flex: 1;
padding: 60px 40px;
display: flex;
flex-direction: column;
justify-content: center;
}
.register-header {
text-align: center;
margin-bottom: 40px;
}
.register-header h2 {
font-size: 2em;
color: #2c3e50;
margin-bottom: 10px;
font-weight: 600;
}
.register-header p {
color: #7f8c8d;
font-size: 1em;
}
.form-group {
margin-bottom: 25px;
}
.form-group label {
display: block;
margin-bottom: 8px;
color: #495057;
font-weight: 500;
font-size: 14px;
}
.form-group input {
width: 100%;
padding: 15px 20px;
border: 2px solid #e9ecef;
border-radius: 10px;
font-size: 16px;
transition: all 0.3s ease;
background: #f8f9fa;
}
.form-group input:focus {
outline: none;
border-color: #667eea;
background: white;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.form-group input::placeholder {
color: #adb5bd;
}
.password-group {
position: relative;
}
.password-toggle {
position: absolute;
right: 15px;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
color: #6c757d;
cursor: pointer;
font-size: 18px;
padding: 5px;
}
.password-toggle:hover {
color: #667eea;
}
.register-btn {
width: 100%;
padding: 15px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 10px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.register-btn::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
transition: left 0.5s;
}
.register-btn:hover::before {
left: 100%;
}
.register-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}
.register-btn:active {
transform: translateY(0);
}
.terms-agree {
margin: 20px 0 30px;
font-size: 14px;
color: #6c757d;
display: flex;
align-items: flex-start;
gap: 8px;
}
.terms-agree input[type="checkbox"] {
margin-top: 2px;
accent-color: #667eea;
}
.terms-agree a {
color: #667eea;
text-decoration: none;
}
.terms-agree a:hover {
text-decoration: underline;
}
.login-link {
text-align: center;
color: #6c757d;
font-size: 14px;
}
.login-link a {
color: #667eea;
text-decoration: none;
font-weight: 600;
}
.login-link a:hover {
text-decoration: underline;
}
.back-to-home {
position: absolute;
top: 20px;
left: 20px;
background: rgba(255, 255, 255, 0.2);
color: white;
border: 1px solid rgba(255, 255, 255, 0.3);
padding: 10px 20px;
border-radius: 25px;
text-decoration: none;
font-size: 14px;
transition: all 0.3s;
display: flex;
align-items: center;
gap: 8px;
z-index: 10;
}
.back-to-home:hover {
background: rgba(255, 255, 255, 0.3);
transform: translateY(-2px);
text-decoration: none;
color: white;
}
/* 响应式设计 */
@media (max-width: 768px) {
.register-container {
flex-direction: column;
max-width: 400px;
min-height: auto;
}
.register-left {
padding: 40px 30px;
min-height: 200px;
}
.register-left h1 {
font-size: 2em;
}
.register-right {
padding: 40px 30px;
}
.register-header h2 {
font-size: 1.5em;
}
}
/* 错误提示样式 */
.error-message {
background: #f8d7da;
color: #721c24;
padding: 12px 16px;
border-radius: 8px;
margin-bottom: 20px;
border: 1px solid #f5c6cb;
font-size: 14px;
display: none;
}
.success-message {
background: #d4edda;
color: #155724;
padding: 12px 16px;
border-radius: 8px;
margin-bottom: 20px;
border: 1px solid #c3e6cb;
font-size: 14px;
display: none;
}
/* 表单字段验证状态 */
.form-group.invalid input {
border-color: #dc3545;
background-color: #fff5f5;
}
.form-group.invalid .validation-message {
display: block;
}
.validation-message {
color: #dc3545;
font-size: 12px;
margin-top: 5px;
display: none;
}
</style>
</head>
<body>
<a href="frontend.html" class="back-to-home">
← 返回首页
</a>
<div class="register-container">
<div class="register-left">
<h1>🔍 易搜高</h1>
<p>专业的自媒体文章监控平台,让您轻松掌握行业动态</p>
<ul class="feature-list">
<li>实时监控多个自媒体平台</li>
<li>智能筛选热门文章</li>
<li>数据可视化分析</li>
<li>个性化推荐系统</li>
</ul>
</div>
<div class="register-right">
<div class="register-header">
<h2>创建账号</h2>
<p>加入我们,开启您的自媒体监控之旅</p>
</div>
<div class="error-message" id="errorMessage"></div>
<div class="success-message" id="successMessage"></div>
<form id="registerForm">
<div class="form-group" id="usernameGroup">
<label for="username">用户名</label>
<input type="text" id="username" name="username" placeholder="请设置用户名" required>
<div class="validation-message" id="usernameError"></div>
</div>
<div class="form-group" id="emailGroup">
<label for="email">电子邮箱</label>
<input type="email" id="email" name="email" placeholder="请输入邮箱地址" required>
<div class="validation-message" id="emailError"></div>
</div>
<div class="form-group" id="passwordGroup">
<label for="password">密码</label>
<div class="password-group">
<input type="password" id="password" name="password" placeholder="请设置密码" required>
<button type="button" class="password-toggle" onclick="togglePassword('password')">👁️</button>
</div>
<div class="validation-message" id="passwordError"></div>
</div>
<div class="form-group" id="confirmPasswordGroup">
<label for="confirmPassword">确认密码</label>
<div class="password-group">
<input type="password" id="confirmPassword" name="confirmPassword" placeholder="请再次输入密码" required>
<button type="button" class="password-toggle" onclick="togglePassword('confirmPassword')">👁️</button>
</div>
<div class="validation-message" id="confirmPasswordError"></div>
</div>
<div class="terms-agree">
<input type="checkbox" id="agreeTerms" name="agreeTerms" required>
<label for="agreeTerms">
我已阅读并同意 <a href="#" onclick="showTerms(event)">服务条款</a><a href="#" onclick="showPrivacy(event)">隐私政策</a>
</label>
</div>
<button type="submit" class="register-btn">注册账号</button>
</form>
<div class="login-link">
已有账号?<a href="login.html">立即登录</a>
</div>
</div>
</div>
<script>
// 密码显示/隐藏切换
function togglePassword(inputId) {
const passwordInput = document.getElementById(inputId);
const toggleBtn = passwordInput.parentElement.querySelector('.password-toggle');
if (passwordInput.type === 'password') {
passwordInput.type = 'text';
toggleBtn.textContent = '🙈';
} else {
passwordInput.type = 'password';
toggleBtn.textContent = '👁️';
}
}
// 显示错误消息
function showError(message) {
const errorDiv = document.getElementById('errorMessage');
const successDiv = document.getElementById('successMessage');
errorDiv.textContent = message;
errorDiv.style.display = 'block';
successDiv.style.display = 'none';
// 3秒后自动隐藏
setTimeout(() => {
errorDiv.style.display = 'none';
}, 3000);
}
// 显示成功消息
function showSuccess(message) {
const errorDiv = document.getElementById('errorMessage');
const successDiv = document.getElementById('successMessage');
successDiv.textContent = message;
successDiv.style.display = 'block';
errorDiv.style.display = 'none';
// 3秒后自动隐藏
setTimeout(() => {
successDiv.style.display = 'none';
}, 3000);
}
// 显示字段验证错误
function showFieldError(fieldId, message) {
const group = document.getElementById(fieldId + 'Group');
const errorElement = document.getElementById(fieldId + 'Error');
group.classList.add('invalid');
errorElement.textContent = message;
errorElement.style.display = 'block';
}
// 清除字段验证错误
function clearFieldError(fieldId) {
const group = document.getElementById(fieldId + 'Group');
const errorElement = document.getElementById(fieldId + 'Error');
group.classList.remove('invalid');
errorElement.style.display = 'none';
}
// 验证用户名
function validateUsername(username) {
if (!username || username.trim().length === 0) {
showFieldError('username', '请输入用户名');
return false;
}
if (username.length < 3 || username.length > 20) {
showFieldError('username', '用户名长度必须在3-20个字符之间');
return false;
}
if (!/^[a-zA-Z0-9_]+$/.test(username)) {
showFieldError('username', '用户名只能包含字母、数字和下划线');
return false;
}
clearFieldError('username');
return true;
}
// 验证邮箱
function validateEmail(email) {
if (!email || email.trim().length === 0) {
showFieldError('email', '请输入邮箱地址');
return false;
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
showFieldError('email', '请输入有效的邮箱地址');
return false;
}
clearFieldError('email');
return true;
}
// 验证密码
function validatePassword(password) {
if (!password) {
showFieldError('password', '请设置密码');
return false;
}
if (password.length < 8) {
showFieldError('password', '密码长度不能少于8位');
return false;
}
if (!/^(?=.*[a-zA-Z])(?=.*[0-9])/.test(password)) {
showFieldError('password', '密码必须包含字母和数字');
return false;
}
clearFieldError('password');
return true;
}
// 验证确认密码
function validateConfirmPassword(confirmPassword) {
const password = document.getElementById('password').value;
if (!confirmPassword) {
showFieldError('confirmPassword', '请确认密码');
return false;
}
if (confirmPassword !== password) {
showFieldError('confirmPassword', '两次输入的密码不一致');
return false;
}
clearFieldError('confirmPassword');
return true;
}
// 添加实时验证
document.getElementById('username').addEventListener('input', function() {
validateUsername(this.value);
});
document.getElementById('email').addEventListener('input', function() {
validateEmail(this.value);
});
document.getElementById('password').addEventListener('input', function() {
validatePassword(this.value);
// 当密码改变时,验证确认密码
if (document.getElementById('confirmPassword').value) {
validateConfirmPassword(document.getElementById('confirmPassword').value);
}
});
document.getElementById('confirmPassword').addEventListener('input', function() {
validateConfirmPassword(this.value);
});
// 注册表单提交
document.getElementById('registerForm').addEventListener('submit', function(e) {
e.preventDefault();
const username = document.getElementById('username').value.trim();
const email = document.getElementById('email').value.trim();
const password = document.getElementById('password').value;
const confirmPassword = document.getElementById('confirmPassword').value;
const agreeTerms = document.getElementById('agreeTerms').checked;
// 验证所有字段
let isValid = true;
if (!validateUsername(username)) isValid = false;
if (!validateEmail(email)) isValid = false;
if (!validatePassword(password)) isValid = false;
if (!validateConfirmPassword(confirmPassword)) isValid = false;
if (!agreeTerms) {
showError('请阅读并同意服务条款和隐私政策');
isValid = false;
}
if (!isValid) {
return;
}
// 实际注册请求
const registerBtn = document.querySelector('.register-btn');
registerBtn.textContent = '注册中...';
registerBtn.disabled = true;
// 准备请求数据
const registerData = {
username: username,
email: email,
password: password
};
// 调用后端注册API
fetch('http://localhost:8000/api/user/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(registerData)
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应异常');
}
return response.json();
})
.then(data => {
// 检查响应状态
if (data.code === 200) {
// 注册成功
showSuccess('注册成功!正在跳转到登录页面...');
// 延迟跳转到登录页
setTimeout(() => {
window.location.href = 'login.html';
}, 1500);
} else {
// 注册失败,显示错误信息
showError(data.msg || '注册失败,请稍后重试');
registerBtn.textContent = '注册账号';
registerBtn.disabled = false;
}
})
.catch(error => {
// 捕获网络或其他错误
console.error('注册请求失败:', error);
showError('注册失败,请稍后重试');
registerBtn.textContent = '注册账号';
registerBtn.disabled = false;
});
});
// 显示服务条款
function showTerms(e) {
e.preventDefault();
showError('服务条款功能开发中...');
}
// 显示隐私政策
function showPrivacy(e) {
e.preventDefault();
showError('隐私政策功能开发中...');
}
// Enter键提交表单
document.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
document.getElementById('registerForm').dispatchEvent(new Event('submit'));
}
});
</script>
</body>
</html>