1<!DOCTYPE html>
2<html lang="zh-CN">
3<head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>用户注册 - 智能家居生态系统</title>
7 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
8 <style>
9 * {
10 margin: 0;
11 padding: 0;
12 box-sizing: border-box;
13 font-family: "Segoe UI", sans-serif;
14 }
15
16 body {
17 background-color: #f0f2f5;
18 min-height: 100vh;
19 display: flex;
20 align-items: center;
21 justify-content: center;
22 padding: 20px;
23 background-image: radial-gradient(circle 800px at 10% 20%, rgba(59, 130, 246, 0.08), transparent 60%),
24 radial-gradient(circle 700px at 90% 80%, rgba(14, 165, 233, 0.08), transparent 60%);
25 }
26
27 /* 全新卡片样式 */
28 .register-card {
29 width: 100%;
30 max-width: 720px;
31 background: #fff;
32 border-radius: 20px;
33 box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
34 overflow: hidden;
35 border: 1px solid rgba(0,0,0,0.05);
36 }
37
38 /* 顶部标题栏 */
39 .card-header {
40 background: linear-gradient(90deg, #0ea5e9, #3b82f6);
41 padding: 28px 24px;
42 text-align: center;
43 color: white;
44 }
45
46 .card-header h2 {
47 font-weight: 600;
48 font-size: 24px;
49 margin-bottom: 6px;
50 }
51
52 .card-header p {
53 opacity: 0.9;
54 font-size: 14px;
55 }
56
57 /* 表单区域 */
58 .card-body {
59 padding: 36px 40px;
60 }
61
62 /* 表单项样式 */
63 .form-item {
64 margin-bottom: 26px;
65 }
66
67 .form-item label {
68 display: block;
69 margin-bottom: 10px;
70 font-weight: 500;
71 color: #333;
72 font-size: 15px;
73 }
74
75 .form-control {
76 height: 48px;
77 border-radius: 10px;
78 border: 1px solid #dcdfe6;
79 padding: 0 16px;
80 font-size: 15px;
81 transition: all 0.25s ease;
82 }
83
84 .form-control:focus {
85 border-color: #0ea5e9;
86 box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
87 outline: none;
88 }
89
90 /* 提示文字 */
91 .form-tip {
92 margin-top: 6px;
93 font-size: 13px;
94 min-height: 18px;
95 }
96
97 .tip-error {
98 color: #f43f5e;
99 }
100
101 .tip-success {
102 color: #10b981;
103 }
104
105 /* 按钮 */
106 .btn-submit {
107 width: 100%;
108 height: 50px;
109 border-radius: 10px;
110 background: linear-gradient(90deg, #0ea5e9, #3b82f6);
111 color: white;
112 font-weight: 500;
113 font-size: 16px;
114 border: none;
115 transition: all 0.25s ease;
116 margin-top: 10px;
117 }
118
119 .btn-submit:hover {
120 transform: translateY(-2px);
121 box-shadow: 0 6px 16px rgba(14, 165, 233, 0.25);
122 color: white;
123 }
124
125 /* 移动端适配 */
126 @media (max-width: 576px) {
127 .card-body {
128 padding: 28px 24px;
129 }
130 }
131 </style>
132</head>
133<body>
134
135<div class="register-card">
136 <!-- 顶部标题 -->
137 <div class="card-header">
138 <h2>账号注册</h2>
139
140 </div>
141
142 <!-- 表单区域 -->
143 <div class="card-body">
144 <form id="registerForm">
145 <!-- 用户名 -->
146 <div class="form-item">
147 <label>用户名</label>
148 <input type="text" class="form-control" id="username" placeholder="请输入3-20位用户名">
149 <div class="form-tip" id="usernameTip"></div>
150 </div>
151
152 <!-- 密码 -->
153 <div class="form-item">
154 <label>登录密码</label>
155 <input type="password" class="form-control" id="password" placeholder="请输入至少6位密码">
156 <div class="form-tip" id="passwordTip"></div>
157 </div>
158
159 <!-- 确认密码 -->
160 <div class="form-item">
161 <label>确认密码</label>
162 <input type="password" class="form-control" id="confirmPwd" placeholder="请再次输入密码">
163 <div class="form-tip" id="confirmTip"></div>
164 </div>
165
166 <!-- 注册按钮 -->
167 <button type="submit" class="btn-submit">立即注册</button>
168 </form>
169 </div>
170</div>
171
172<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
173<script>
174 // 获取元素
175 const username = document.getElementById('username');
176 const password = document.getElementById('password');
177 const confirmPwd = document.getElementById('confirmPwd');
178 const form = document.getElementById('registerForm');
179
180 // 提示元素
181 const usernameTip = document.getElementById('usernameTip');
182 const passwordTip = document.getElementById('passwordTip');
183 const confirmTip = document.getElementById('confirmTip');
184
185 // 验证状态
186 let uOk = false, pOk = false, cOk = false;
187
188 // 用户名验证
189 function checkName() {
190 const val = username.value.trim();
191 if (!val) {
192 usernameTip.className = 'form-tip tip-error';
193 usernameTip.textContent = '用户名不能为空';
194 uOk = false;
195 } else if (val.length < 3 || val.length > 20) {
196 usernameTip.className = 'form-tip tip-error';
197 usernameTip.textContent = '长度必须在3-20位之间';
198 uOk = false;
199 } else {
200 usernameTip.className = 'form-tip tip-success';
201 usernameTip.textContent = '用户名可用';
202 uOk = true;
203 }
204 }
205
206 // 密码验证
207 function checkPwd() {
208 const val = password.value;
209 if (!val) {
210 passwordTip.className = 'form-tip tip-error';
211 passwordTip.textContent = '密码不能为空';
212 pOk = false;
213 } else if (val.length < 6) {
214 passwordTip.className = 'form-tip tip-error';
215 passwordTip.textContent = '密码长度至少6位';
216 pOk = false;
217 } else {
218 passwordTip.className = 'form-tip tip-success';
219 passwordTip.textContent = '密码格式正确';
220 pOk = true;
221 }
222 checkConfirm();
223 }
224
225 // 确认密码
226 function checkConfirm() {
227 const pwd = password.value;
228 const cpwd = confirmPwd.value;
229 if (!cpwd) {
230 confirmTip.className = 'form-tip tip-error';
231 confirmTip.textContent = '请确认密码';
232 cOk = false;
233 } else if (pwd !== cpwd) {
234 confirmTip.className = 'form-tip tip-error';
235 confirmTip.textContent = '两次输入密码不一致';
236 cOk = false;
237 } else {
238 confirmTip.className = 'form-tip tip-success';
239 confirmTip.textContent = '密码一致';
240 cOk = true;
241 }
242 }
243
244 // 实时监听
245 username.addEventListener('input', checkName);
246 password.addEventListener('input', checkPwd);
247 confirmPwd.addEventListener('input', checkConfirm);
248
249 // 提交
250 form.addEventListener('submit', e => {
251 e.preventDefault();
252 checkName();
253 checkPwd();
254 checkConfirm();
255
256 if (uOk && pOk && cOk) {
257 alert('注册信息验证成功!');
258 // 这里可以继续写提交接口逻辑
259 }
260 });
261</script>
262
263</body>
264</html>