仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ templates/tdesign/spa/src/account/views/RegisterView.vue 8.1 KB · 341 行 原始文件
Z zfhsh first commit 2 个月前
1<template>
2 <div class="td-login">
3 <!-- 左侧背景图区 -->
4 <div class="login-banner">
5 <img :src="bgImg" alt="" class="banner-img" />
6 <div class="banner-overlay"></div>
7 <div class="banner-content">
8 <h1 class="banner-title">{{ siteName }}</h1>
9 <p class="banner-subtitle">用户中心 · 创建你的专属账号</p>
10 <ul class="banner-features">
11 <li><i class="mdi mdi-account-plus-outline"></i> 快速注册</li>
12 <li><i class="mdi mdi-shield-check-outline"></i> 密码加密存储</li>
13 <li><i class="mdi mdi-email-outline"></i> 支持邮箱与 QQ 绑定</li>
14 </ul>
15 </div>
16 </div>
17
18 <!-- 右侧注册卡片区 -->
19 <div class="login-side">
20 <div class="login-card">
21 <div class="brand">
22 <h2>{{ siteName }}</h2>
23 <p class="sub">用户中心 · 创建账号</p>
24 </div>
25
26 <t-form ref="formRef" :data="form" :rules="rules" :label-width="0" @submit="onSubmit">
27 <t-form-item name="username">
28 <t-input v-model="form.username" placeholder="用户名(3~32位字母、数字或下划线)" clearable size="large" maxlength="32" @enter="onSubmit">
29 <template #prefix-icon><i class="mdi mdi-account"></i></template>
30 </t-input>
31 </t-form-item>
32 <t-form-item name="password">
33 <t-input
34 v-model="form.password"
35 type="password"
36 placeholder="密码(至少6位)"
37 size="large"
38 @enter="onSubmit"
39 >
40 <template #prefix-icon><i class="mdi mdi-lock"></i></template>
41 </t-input>
42 </t-form-item>
43 <t-form-item name="password2">
44 <t-input
45 v-model="form.password2"
46 type="password"
47 placeholder="确认密码"
48 size="large"
49 @enter="onSubmit"
50 >
51 <template #prefix-icon><i class="mdi mdi-lock"></i></template>
52 </t-input>
53 </t-form-item>
54 <t-form-item name="email">
55 <t-input v-model="form.email" placeholder="邮箱(选填)" clearable size="large" @enter="onSubmit">
56 <template #prefix-icon><i class="mdi mdi-email-outline"></i></template>
57 </t-input>
58 </t-form-item>
59 <t-form-item name="qq">
60 <t-input v-model="form.qq" placeholder="QQ(选填)" clearable size="large" maxlength="12" @enter="onSubmit">
61 <template #prefix-icon><i class="mdi mdi-qqchat"></i></template>
62 </t-input>
63 </t-form-item>
64 <t-form-item>
65 <t-button theme="primary" type="submit" block size="large" :loading="loading">
66 注 册
67 </t-button>
68 </t-form-item>
69 </t-form>
70
71 <p class="switch-note">
72 已有账号?
73 <router-link to="/login" class="switch-link">直接登录</router-link>
74 </p>
75
76 <p v-if="footer" class="footer-note" v-html="footer"></p>
77 </div>
78 </div>
79 </div>
80</template>
81
82<script setup>
83import { reactive, ref, onMounted } from 'vue'
84import { useRouter } from 'vue-router'
85import { MessagePlugin } from 'tdesign-vue-next'
86import { accountRegister, getMe } from '@/account/api/auth'
87import bgImg from '@/shared/assets/login-bg.webp'
88
89const router = useRouter()
90const boot = window.__TD_BOOT__ || {}
91const siteName = boot.siteName || 'MNBT'
92const footer = boot.footer || ''
93
94const formRef = ref()
95const loading = ref(false)
96
97const form = reactive({
98 username: '',
99 password: '',
100 password2: '',
101 email: '',
102 qq: '',
103})
104
105const rules = {
106 username: [
107 { required: true, message: '请输入用户名', trigger: 'blur' },
108 {
109 pattern: /^[a-zA-Z0-9_]{3,32}$/,
110 message: '用户名为3~32位字母、数字或下划线',
111 trigger: 'blur',
112 },
113 ],
114 password: [
115 { required: true, message: '请输入密码', trigger: 'blur' },
116 { min: 6, message: '密码至少6个字符', trigger: 'blur' },
117 ],
118 password2: [
119 { required: true, message: '请再次输入密码', trigger: 'blur' },
120 {
121 validator: (val) => val === form.password,
122 message: '两次输入的密码不一致',
123 trigger: 'blur',
124 },
125 ],
126 email: [
127 {
128 validator: (val) => val === '' || /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(val),
129 message: '邮箱格式不正确',
130 trigger: 'blur',
131 },
132 ],
133 qq: [
134 {
135 validator: (val) => val === '' || /^[0-9]{5,12}$/.test(val),
136 message: 'QQ号格式不正确',
137 trigger: 'blur',
138 },
139 ],
140}
141
142async function onSubmit({ validateResult }) {
143 if (validateResult !== true) return
144 loading.value = true
145 const res = await accountRegister(form)
146 loading.value = false
147 if (res.ok) {
148 MessagePlugin.success('注册成功,正在跳转…')
149 const me = await getMe()
150 window.__TD_BOOT__ = { ...boot, loggedIn: true, accountUser: me.ok ? me.data.user : null }
151 router.replace('/dashboard')
152 return
153 }
154}
155
156onMounted(() => {
157 if (boot.loggedIn && boot.accountUser) {
158 router.replace('/dashboard')
159 }
160})
161</script>
162
163<style scoped>
164.td-login {
165 min-height: 100vh;
166 display: grid;
167 grid-template-columns: 1fr 480px;
168 background: #f5f7fa;
169}
170
171/* ============== 左侧背景图区 ============== */
172.login-banner {
173 position: relative;
174 overflow: hidden;
175 min-height: 100vh;
176}
177.banner-img {
178 position: absolute;
179 inset: 0;
180 width: 100%;
181 height: 100%;
182 object-fit: cover;
183 z-index: 0;
184}
185.banner-overlay {
186 position: absolute;
187 inset: 0;
188 background: linear-gradient(
189 135deg,
190 rgba(0, 30, 80, 0.65) 0%,
191 rgba(0, 50, 130, 0.45) 50%,
192 rgba(20, 80, 180, 0.35) 100%
193 );
194 z-index: 1;
195}
196.banner-content {
197 position: absolute;
198 left: 0;
199 right: 0;
200 bottom: 0;
201 padding: 60px;
202 z-index: 2;
203 color: #fff;
204 animation: banner-fade-in 0.8s ease-out;
205}
206.banner-title {
207 margin: 0;
208 font-size: 38px;
209 font-weight: 700;
210 letter-spacing: -0.02em;
211 text-shadow: 0 2px 16px rgba(0, 0, 0, 0.25);
212}
213.banner-subtitle {
214 margin: 12px 0 28px;
215 font-size: 15px;
216 opacity: 0.92;
217 text-shadow: 0 1px 8px rgba(0, 0, 0, 0.2);
218}
219.banner-features {
220 list-style: none;
221 margin: 0;
222 padding: 0;
223 display: flex;
224 flex-wrap: wrap;
225 gap: 18px;
226}
227.banner-features li {
228 display: flex;
229 align-items: center;
230 gap: 6px;
231 font-size: 13px;
232 opacity: 0.88;
233}
234.banner-features i {
235 font-size: 18px;
236 color: #4fc3f7;
237}
238
239@keyframes banner-fade-in {
240 from { opacity: 0; transform: translateY(20px); }
241 to { opacity: 1; transform: translateY(0); }
242}
243
244/* ============== 右侧注册卡片区 ============== */
245.login-side {
246 display: grid;
247 place-items: center;
248 padding: 32px;
249 min-height: 100vh;
250 background: #fff;
251}
252.login-card {
253 width: min(400px, 100%);
254 animation: card-fade-in 0.6s ease-out;
255}
256@keyframes card-fade-in {
257 from { opacity: 0; transform: translateX(20px); }
258 to { opacity: 1; transform: translateX(0); }
259}
260.brand {
261 margin-bottom: 28px;
262}
263.brand h2 {
264 margin: 0;
265 font-size: 24px;
266 font-weight: 700;
267 letter-spacing: -0.02em;
268 color: var(--td-text);
269}
270.sub {
271 margin: 8px 0 0;
272 font-size: 13px;
273 color: var(--td-text-secondary);
274}
275.switch-note {
276 margin: 20px 0 0;
277 text-align: center;
278 font-size: 13px;
279 color: var(--td-text-secondary);
280}
281.switch-link {
282 color: var(--td-brand);
283 font-weight: 500;
284}
285.footer-note {
286 margin: 16px 0 0;
287 text-align: center;
288 font-size: 12px;
289 color: var(--td-text-secondary);
290}
291
292/* ============== 响应式 ============== */
293@media (max-width: 960px) {
294 .td-login {
295 grid-template-columns: 1fr;
296 }
297 .login-banner {
298 min-height: 260px;
299 max-height: 34vh;
300 }
301 .banner-content {
302 padding: 32px;
303 }
304 .banner-title {
305 font-size: 26px;
306 }
307 .banner-subtitle {
308 margin: 8px 0 16px;
309 font-size: 13px;
310 }
311 .banner-features {
312 gap: 12px;
313 }
314 .banner-features li {
315 font-size: 12px;
316 }
317 .login-side {
318 padding: 24px;
319 min-height: auto;
320 }
321}
322
323@media (max-width: 600px) {
324 .login-banner {
325 min-height: 180px;
326 max-height: 28vh;
327 }
328 .banner-content {
329 padding: 20px;
330 }
331 .banner-title {
332 font-size: 20px;
333 }
334 .banner-features {
335 display: none;
336 }
337 .login-side {
338 padding: 20px 16px;
339 }
340}
341</style>