Compare commits

..

2 Commits

Author SHA1 Message Date
55902aa8b6 fix: 移除验证码功能(暂时隐藏)
- 移除验证码输入框和发送验证码按钮
- 移除验证码验证逻辑
- 保留手机号格式验证(11位中国手机号)
- 保留手机号唯一性检查
- 注册字段:用户名、手机号(必填)、邮箱(可选)、密码
2026-04-27 11:31:44 +08:00
295218b4e4 feat: 注册增加手机号验证和邮箱
- 手机号输入(必填,11位中国手机号格式验证)
- 验证码机制(模拟,6位随机码,5分钟有效期)
- 发送验证码按钮(60秒倒计时)
- 验证码输入框
- 邮箱输入(可选,格式验证)
- 手机号唯一性检查(防止重复注册)
2026-04-27 11:26:51 +08:00
3 changed files with 100 additions and 5 deletions

View File

@@ -1391,7 +1391,7 @@ function renderProfilePage() {
</div>
<div class="profile-footer">
<p>AI助手 v3.3.1</p>
<p>AI助手 v3.4.1</p>
<p>基于智谱 GLM-4.5-Air</p>
</div>
</div>
@@ -1560,6 +1560,14 @@ function showRegisterPage() {
<label>用户名</label>
<input type="text" id="registerUsername" placeholder="请输入用户名3-20字符" autocomplete="username">
</div>
<div class="auth-input-group">
<label>手机号 <span class="required">*</span></label>
<input type="tel" id="registerPhone" placeholder="请输入手机号" maxlength="11" autocomplete="tel">
</div>
<div class="auth-input-group">
<label>邮箱 <span class="optional">(可选)</span></label>
<input type="email" id="registerEmail" placeholder="请输入邮箱(可选)" autocomplete="email">
</div>
<div class="auth-input-group">
<label>密码</label>
<input type="password" id="registerPassword" placeholder="请输入密码6-20字符" autocomplete="new-password">
@@ -1604,18 +1612,56 @@ function showRegisterPage() {
document.getElementById('registerPasswordConfirm')?.addEventListener('keydown', (e) => {
if (e.key === 'Enter') handleRegister();
});
// 手机号输入限制(只允许数字)
const phoneInput = document.getElementById('registerPhone');
if (phoneInput) {
phoneInput.addEventListener('input', (e) => {
e.target.value = e.target.value.replace(/\D/g, '');
});
}
}
// 验证手机号格式
function validatePhone(phone) {
// 中国手机号11位以1开头
const phoneRegex = /^1[3-9]\d{9}$/;
return phoneRegex.test(phone);
}
// 验证邮箱格式
function validateEmail(email) {
if (!email) return true; // 可选,空值有效
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
function handleRegister() {
const username = document.getElementById('registerUsername')?.value.trim();
const phone = document.getElementById('registerPhone')?.value.trim();
const email = document.getElementById('registerEmail')?.value.trim();
const password = document.getElementById('registerPassword')?.value;
const passwordConfirm = document.getElementById('registerPasswordConfirm')?.value;
// 验证用户名
if (!username || username.length < 3 || username.length > 20) {
showToast('用户名需要3-20个字符');
return;
}
// 验证手机号
if (!validatePhone(phone)) {
showToast('请输入正确的手机号');
return;
}
// 验证邮箱(可选)
if (!validateEmail(email)) {
showToast('请输入正确的邮箱格式');
return;
}
// 验证密码
if (!password || password.length < 6 || password.length > 20) {
showToast('密码需要6-20个字符');
return;
@@ -1633,9 +1679,17 @@ function handleRegister() {
return;
}
// 检查手机号是否已注册
if (users.find(u => u.phone === phone)) {
showToast('该手机号已注册');
return;
}
// 注册新用户
const newUser = {
username,
phone,
email: email || '',
password,
registeredAt: Date.now()
};
@@ -1644,7 +1698,7 @@ function handleRegister() {
localStorage.setItem('registeredUsers', JSON.stringify(users));
// 自动登录
currentUser = { username: newUser.username, registeredAt: newUser.registeredAt };
currentUser = { username: newUser.username, phone: newUser.phone, registeredAt: newUser.registeredAt };
saveCurrentUser();
showToast('注册成功');

View File

@@ -8,12 +8,12 @@
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>AI助手</title>
<link rel="stylesheet" href="style.css?v=3.3.1">
<link rel="stylesheet" href="style.css?v=3.4.1">
<link rel="manifest" href="manifest.json">
</head>
<body>
<div id="app"></div>
<script src="marked.min.js?v=3.3.1"></script>
<script src="app.js?v=3.3.1"></script>
<script src="marked.min.js?v=3.4.1"></script>
<script src="app.js?v=3.4.1"></script>
</body>
</html>

View File

@@ -753,6 +753,47 @@ body {
border-color: var(--primary);
}
.auth-input-group .required {
color: #e53e3e;
font-size: 12px;
}
.auth-input-group .optional {
color: var(--text-light);
font-size: 12px;
}
/* 手机号输入框布局 */
.phone-input-wrapper {
display: flex;
gap: 8px;
}
.phone-input-wrapper input {
flex: 1;
}
.send-code-btn {
padding: 12px 16px;
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 10px;
font-size: 14px;
cursor: pointer;
white-space: nowrap;
transition: opacity 0.2s;
}
.send-code-btn:hover {
opacity: 0.9;
}
.send-code-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.auth-submit-btn {
width: 100%;
padding: 14px;