Family-Tree/gateway/templates/register.html
jdysya 92956b84ab feat(register): 优化移动设备适配并添加密码匹配验证
- 修改移动端响应式布局,确保页面在小屏设备上的可用性
- 添加密码匹配错误提示,提高用户注册体验
- 实现密码输入实时验证和表单提交前验证
2025-02-17 10:35:54 +08:00

278 lines
8.5 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>
<style>
:root {
--primary-color: #2c3e50;
--accent-color: #42b983;
--error-color: #e74c3c;
}
body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
background: #f5f5f5;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 2rem;
margin: 0;
}
.login-container {
background: white;
padding: 2.5rem;
border-radius: 12px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 500px;
margin-top: 4rem;
}
h1 {
color: var(--primary-color);
text-align: center;
margin-bottom: 2rem;
font-size: 1.8rem;
}
.form-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin-bottom: 1rem;
}
label {
color: var(--primary-color);
font-weight: 500;
}
input, .form-select {
padding: 0.8rem;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 1rem;
transition: border-color 0.3s ease;
}
input:focus, .form-select:focus {
outline: none;
border-color: var(--accent-color);
box-shadow: 0 0 0 2px rgba(66, 185, 131, 0.2);
}
/* 修改移动端响应式布局 */
@media (max-width: 480px) {
body {
padding: 1rem;
}
.login-container {
padding: 1.5rem;
margin-top: 2rem;
width: calc(100% - 2rem); /* 确保容器不会超出屏幕 */
}
.form-group-row {
grid-template-columns: 1fr; /* 移动端单列布局 */
gap: 0.5rem;
}
input, select {
font-size: 16px; /* 防止iOS自动放大输入框 */
}
}
/* 统一表单元素样式 */
.form-select {
padding: 0.8rem;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 1rem;
transition: border-color 0.3s ease;
background: white url("data:image/svg+xml,%3csvg...") no-repeat right 0.75rem center/8px 10px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
/* 统一错误提示样式 */
.error-message {
background: #fee;
color: var(--error-color);
padding: 1rem;
border-radius: 6px;
border: 1px solid #ffd6d6;
margin-top: 1rem;
text-align: center;
}
/* 复用登录页样式,新增部分样式 */
.login-container {
max-width: 500px;
}
.form-group-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
}
.login-link {
text-align: center;
margin-top: 1.5rem;
}
.login-link a {
color: var(--accent-color);
text-decoration: none;
}
/* 美化按钮样式 */
button {
background: var(--accent-color);
color: white;
padding: 0.8rem;
border: none;
border-radius: 6px;
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: background 0.3s ease;
width: 100%;
margin-top: 1rem;
}
button:hover {
background: #3aa876;
}
/* 美化选择框样式 */
select {
width: 100%;
padding: 0.8rem;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 1rem;
color: var(--primary-color);
background: white;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%232c3e50' d='M6 8.825L1.175 4 2.238 2.938 6 6.7l3.763-3.763L10.825 4z'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 0.8rem center;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
}
select:focus {
outline: none;
border-color: var(--accent-color);
box-shadow: 0 0 0 2px rgba(66, 185, 131, 0.2);
}
select:hover {
border-color: var(--accent-color);
}
/* 修改选择框的placeholder颜色 */
select option:first-child {
color: #999;
}
/* 移除之前重复的样式 */
.form-select {
display: none;
}
/* 添加密码匹配提示样式 */
.password-match-error {
color: var(--error-color);
font-size: 0.875rem;
margin-top: 0.25rem;
display: none;
}
.password-match-error.show {
display: block;
}
</style>
</head>
<body>
<div class="login-container">
<h1>新用户注册</h1>
<form action="/register" method="post" id="registerForm">
<div class="form-group">
<label for="fullname">真实姓名</label>
<input type="text" id="fullname" name="fullname" required
placeholder="请输入真实姓名">
</div>
<div class="form-group">
<label for="mobile">手机号码</label>
<input type="tel" id="mobile" name="mobile" required
pattern="[0-9]{11}"
placeholder="请输入11位手机号">
</div>
<div class="form-group">
<label for="password">登录密码</label>
<input type="password" id="password" name="password" required
minlength="6"
placeholder="至少6位密码">
</div>
<div class="form-group">
<label for="confirmPassword">确认密码</label>
<input type="password" id="confirmPassword" name="confirmPassword" required
minlength="6"
placeholder="请再次输入密码">
<div class="password-match-error">两次输入的密码不一致</div>
</div>
<div class="form-group">
<label for="region">所在地区</label>
<select name="region" id="region" required>
<option value="">请选择所在地区</option>
{{ range .regions }}
<option value="{{ .ID }}" {{ if eq .ID $.form.region }}selected{{ end }}>{{ .Name }}</option>
{{ end }}
</select>
</div>
<button type="submit">立即注册</button>
<div class="login-link">
已有账号?<a href="/login">立即登录</a>
</div>
</form>
{{ if .error }}
<p class="error-message">{{ .error }}</p>
{{ end }}
</div>
<script>
const form = document.getElementById('registerForm');
const password = document.getElementById('password');
const confirmPassword = document.getElementById('confirmPassword');
const errorDiv = document.querySelector('.password-match-error');
// 实时检查密码匹配
function checkPasswords() {
if (confirmPassword.value && password.value !== confirmPassword.value) {
errorDiv.classList.add('show');
return false;
}
errorDiv.classList.remove('show');
return true;
}
confirmPassword.addEventListener('input', checkPasswords);
password.addEventListener('input', checkPasswords);
// 表单提交验证
form.addEventListener('submit', function(e) {
if (!checkPasswords()) {
e.preventDefault();
}
});
</script>
</body>
</html>