办学质量监测教学评价系统
shenrongliang
2025-06-13 11d86cc6c26bb4f709e407acadf4805c2024e79f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<script setup lang="ts">
import { ref, reactive, computed } from "vue";
import { useRouter } from "vue-router";
import {
  NButton, NInput, NSpin, NText, useMessage,
  NIcon, useThemeVars
} from "naive-ui";
import {
  PersonOutline,
  LockClosedOutline,
  KeyOutline,
  LogInOutline
} from '@vicons/ionicons5';
 
import { doRegist, getVerificationCode } from '@/api/user'
import { useI18n } from "vue-i18n";
 
const { t } = useI18n();
const router = useRouter();
const message = useMessage();
const themeVars = useThemeVars();
 
// 表单状态管理
const registerForm = reactive({
  username: '',
  code: '',
  password: '',
  confirmPassword: ''
});
 
// 加载状态管理
const registerLoading = ref(false);
const pageLoading = ref(false);
 
// 表单验证
const formErrors = reactive({
  username: '',
  email: '',
  code: '',
  password: '',
  confirmPassword: ''
});
 
// 验证表单
function validateForm() {
  let isValid = true;
  
  // 用户名验证
  if (!registerForm.username) {
    formErrors.username = t('register.invalid_account');
    isValid = false;
  } else if (registerForm.username.length < 3) {
    formErrors.username = t('register.usernameTooShort');
    isValid = false;
  } else {
    formErrors.username = '';
  }
 
  // 邮箱验证
  if (!registerForm.username) {
    formErrors.email = t('register.enter_email');
    isValid = false;
  } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(registerForm.username)) {
    formErrors.email = t('register.invalidEmail');
    isValid = false;
  } else {
    formErrors.email = '';
  }
 
  // 验证码验证
  if (!registerForm.code) {
    formErrors.code = t('register.codeRequired');
    isValid = false;
  } else {
    formErrors.code = '';
  }
 
  // 密码验证
  if (!registerForm.password) {
    formErrors.password = t('register.passwordRequired');
    isValid = false;
  } else if (registerForm.password.length < 6) {
    formErrors.password = t('register.passwordTooShort');
    isValid = false;
  } else {
    formErrors.password = '';
  }
 
  // 确认密码验证
  if (!registerForm.confirmPassword) {
    formErrors.confirmPassword = t('register.confirmPasswordRequired');
    isValid = false;
  } else if (registerForm.password !== registerForm.confirmPassword) {
    formErrors.confirmPassword = t('register.passwordMismatch');
    isValid = false;
  } else {
    formErrors.confirmPassword = '';
  }
 
  return isValid;
}
 
// 用户注册
async function handleRegister(e: MouseEvent) {
  e.preventDefault();
  if (!validateForm()) return;
 
  try {
    registerLoading.value = true;
    await doRegist(
      registerForm.username,
      registerForm.password,
      registerForm.code,
    );
    message.success(t("register.registration_success"));
    router.push("/login");
  } catch (error: any) {
    message.error(error.message || t("register.registration_failed"));
  } finally {
    registerLoading.value = false;
  }
}
 
// 验证码发送相关
const isSending = ref(false);
const countdown = ref(60);
const codeButtonText = computed(() => {
  return isSending.value ? `${countdown.value}s` : t('register.get_verification_code');
});
 
async function sendVerificationCode() {
  // 验证邮箱
  if (!registerForm.username) {
    message.error("用户名不能为空!");
    return;
  } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(registerForm.username)) {
     message.error("请输入正确的邮箱!");
    return;
  }
 
  if (isSending.value) return;
 
  try {
    isSending.value = true;
    await getVerificationCode(registerForm.username);
    message.success(t('register.send_success'));
    
    // 开始倒计时
    countdown.value = 60;
    const timer = setInterval(() => {
      countdown.value--;
      if (countdown.value <= 0) {
        clearInterval(timer);
        isSending.value = false;
      }
    }, 1000);
  } catch (error: any) {
    message.error(error.message || t("register.sendCodeFailed"));
    isSending.value = false;
  }
}
 
// 计算背景样式,适配暗黑模式
const brandSectionStyle = computed(() => {
  const isDark = themeVars.value.bodyColor.startsWith('#1') ||
    themeVars.value.bodyColor.startsWith('#2') ||
    themeVars.value.bodyColor.startsWith('#3');
 
  return {
    background: isDark
      ? 'linear-gradient(135deg, #003b8e, #0058d9)'
      : 'linear-gradient(135deg, #1867c0, #5cbbf6)'
  };
});
</script>
 
<template>
  <div class="login-container">
    <NSpin :show="pageLoading">
      <div class="login-content">
        <!-- 左侧品牌区域 -->
        <div class="brand-section" :style="brandSectionStyle">
          <div class="brand-content">
            <h1 class="brand-title">AI知识库系统</h1>
            <p class="brand-description">
              企业级智能知识管理平台,助力数字化转型
            </p>
          </div>
        </div>
 
        <!-- 右侧注册表单 -->
        <div class="form-wrapper">
  
          <div class="login-methods">
            <div class="active-method">{{ $t("register.create_account") }}</div>
          </div>
 
          <div class="form-content">
            <!-- 用户名输入 -->
            <div class="input-group">
              <div class="input-label-row">
                <NText strong class="input-label">
                  {{ $t("register.email") }}
                </NText>
                <div v-if="formErrors.username" class="error-message">{{ formErrors.username }}</div>
              </div>
              <NInput v-model:value="registerForm.username" :placeholder="$t('register.enter_email')" round clearable
                class="custom-input" :status="formErrors.username ? 'error' : undefined">
                <template #prefix>
                  <NIcon :component="PersonOutline" />
                </template>
              </NInput>
            </div>
 
            <!-- 验证码输入 -->
            <div class="input-group">
              <div class="input-label-row">
                <NText strong class="input-label">
                  {{ $t("register.verification_code") }}
                </NText>
                <div v-if="formErrors.code" class="error-message">{{ formErrors.code }}</div>
              </div>
              <div class="verification-code-row">
                <NInput v-model:value="registerForm.code" :placeholder="$t('register.enter_verification_code')" round
                  class="verification-input" :status="formErrors.code ? 'error' : undefined">
                  <template #prefix>
                    <NIcon :component="KeyOutline" />
                  </template>
                </NInput>
                <NButton :disabled="isSending" @click="sendVerificationCode" class="send-code-button">
                  {{ codeButtonText }}
                </NButton>
              </div>
            </div>
 
            <!-- 密码输入 -->
            <div class="input-group">
              <div class="input-label-row">
                <NText strong class="input-label">
                  {{ $t("register.password") }}
                </NText>
                <div v-if="formErrors.password" class="error-message">{{ formErrors.password }}</div>
              </div>
              <NInput v-model:value="registerForm.password" type="password" :placeholder="$t('register.enter_password')" round
                show-password-on="click" class="custom-input" :status="formErrors.password ? 'error' : undefined">
                <template #prefix>
                  <NIcon :component="LockClosedOutline" />
                </template>
              </NInput>
            </div>
 
            <!-- 确认密码输入 -->
            <div class="input-group">
              <div class="input-label-row">
                <NText strong class="input-label">
                  {{ $t("register.confirm_password") }}
                </NText>
                <div v-if="formErrors.confirmPassword" class="error-message">{{ formErrors.confirmPassword }}</div>
              </div>
              <NInput v-model:value="registerForm.confirmPassword" type="password" :placeholder="$t('register.enter_confirm_password')" round
                show-password-on="click" class="custom-input" :status="formErrors.confirmPassword ? 'error' : undefined">
                <template #prefix>
                  <NIcon :component="LockClosedOutline" />
                </template>
              </NInput>
            </div>
 
            <!-- 注册按钮 -->
            <div class="action-buttons">
              <NButton type="primary" block :loading="registerLoading" @click="handleRegister" class="register-button">
                <template #icon>
                  <NIcon :component="LogInOutline" />
                </template>
                {{ $t("register.register") }}
              </NButton>
            </div>
 
            <!-- 返回登录 -->
            <div class="login-prompt">
              {{ $t("register.if_account") }}
              <NButton text type="primary" @click="router.push('/login')">
                {{ $t("register.go_login") }}
              </NButton>
            </div>
          </div>
        </div>
      </div>
    </NSpin>
  </div>
</template>
 
<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--n-body-color);
  padding: 20px;
}
 
.login-content {
  display: flex;
  width: 900px;
  max-width: 100%;
  min-height: 500px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}
 
html.dark .login-content {
  outline: 2px solid rgb(17, 19, 17) !important;
}
 
/* 左侧品牌区域 */
.brand-section {
  flex: 1;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  position: relative;
  overflow: hidden;
}
 
.brand-content {
  position: relative;
  z-index: 2;
  text-align: center;
}
 
.brand-title {
  font-size: 2.5rem;
  font-weight: bold;
  margin-bottom: 1rem;
  color: white;
}
 
.brand-description {
  font-size: 1.1rem;
  opacity: 0.9;
  max-width: 300px;
  margin: 0 auto;
  color: rgba(255, 255, 255, 0.9);
}
 
/* 右侧表单区域 */
.form-wrapper {
  flex: 1;
  background: var(--n-color-modal);
  padding: 40px;
  display: flex;
  flex-direction: column;
}
 
.form-title {
  text-align: center;
  margin-bottom: 1.5rem;
}
 
.login-methods {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
}
 
.active-method {
  font-size: 16px;
  font-weight: 500;
  color: var(--n-text-color);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--n-primary-color);
}
 
.form-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}
 
.input-group {
  margin-bottom: 1.5rem;
}
 
.input-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
 
.input-label {
  font-size: 14px;
}
 
.error-message {
  font-size: 12px;
  color: var(--n-error-color);
}
 
.custom-input {
  transition: all 0.3s ease;
}
 
.verification-code-row {
  display: flex;
  gap: 10px;
}
 
.verification-input {
  flex: 1;
}
 
.send-code-button {
  min-width: 100px;
}
 
.action-buttons {
  margin-bottom: 1.5rem;
}
 
.register-button {
  height: 40px;
  font-size: 16px;
}
 
.login-prompt {
  text-align: center;
  font-size: 14px;
  color: var(--n-text-color-3);
  margin-top: auto;
  padding-top: 1rem;
}
 
/* 响应式设计 */
@media (max-width: 768px) {
  .login-content {
    flex-direction: column;
    width: 100%;
  }
 
  .brand-section {
    padding: 30px;
    min-height: 150px;
  }
 
  .form-wrapper {
    padding: 30px 20px;
  }
 
  .brand-title {
    font-size: 2rem;
  }
  
  .verification-code-row {
    flex-direction: column;
    gap: 10px;
  }
  
  .send-code-button {
    width: 100%;
  }
}
</style>