恢复修改的数据
This commit is contained in:
@@ -2,45 +2,30 @@
|
||||
import { onBeforeUnmount, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { PasswordStrength, SmsCodeInput } from '@/components'
|
||||
import { PasswordStrength } from '@/components'
|
||||
import { useUserStore } from '@/stores/modules/user'
|
||||
import { isPhone, isValidPassword } from '@/utils/validate'
|
||||
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
|
||||
const phone = ref('')
|
||||
const code = ref('')
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
const confirmPassword = ref('')
|
||||
const agree = ref(false)
|
||||
|
||||
let redirectTimer: number | null = null
|
||||
|
||||
async function onGetCode(): Promise<void> {
|
||||
if (!isPhone(phone.value)) {
|
||||
ElMessage.warning('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await userStore.sendSmsCode(phone.value)
|
||||
}
|
||||
catch {
|
||||
// 失败提示已由 store 统一弹出,此处仅避免未处理的 rejection
|
||||
}
|
||||
}
|
||||
|
||||
async function onRegister(): Promise<void> {
|
||||
if (!isPhone(phone.value)) {
|
||||
ElMessage.warning('手机号格式不正确')
|
||||
if (!username.value.trim()) {
|
||||
ElMessage.warning('请输入账号')
|
||||
return
|
||||
}
|
||||
if (!/^\d{6}$/.test(code.value)) {
|
||||
ElMessage.warning('请输入6位验证码')
|
||||
if (username.value.trim().length < 2 || username.value.trim().length > 30) {
|
||||
ElMessage.warning('账号长度应为2-30位')
|
||||
return
|
||||
}
|
||||
if (!isValidPassword(password.value)) {
|
||||
ElMessage.warning('密码长度应为6-20位')
|
||||
if (password.value.length < 5 || password.value.length > 30) {
|
||||
ElMessage.warning('密码长度应为5-30位')
|
||||
return
|
||||
}
|
||||
if (password.value !== confirmPassword.value) {
|
||||
@@ -52,11 +37,9 @@ async function onRegister(): Promise<void> {
|
||||
return
|
||||
}
|
||||
const ok = await userStore.register({
|
||||
phone: phone.value,
|
||||
code: code.value,
|
||||
username: username.value.trim(),
|
||||
password: password.value,
|
||||
confirmPassword: confirmPassword.value,
|
||||
agree: agree.value,
|
||||
})
|
||||
if (ok) {
|
||||
redirectTimer = window.setTimeout(() => {
|
||||
@@ -94,20 +77,19 @@ onBeforeUnmount(() => {
|
||||
|
||||
<form class="auth-page__form" @submit.prevent="onRegister">
|
||||
<input
|
||||
v-model="phone"
|
||||
v-model="username"
|
||||
class="auth-page__input"
|
||||
type="text"
|
||||
placeholder="请输入手机号"
|
||||
maxlength="11"
|
||||
autocomplete="tel"
|
||||
placeholder="请输入账号(2-30位)"
|
||||
maxlength="30"
|
||||
autocomplete="username"
|
||||
>
|
||||
<SmsCodeInput v-model:code="code" @get-code="onGetCode" />
|
||||
<div class="auth-page__pwd-wrap">
|
||||
<input
|
||||
v-model="password"
|
||||
class="auth-page__input"
|
||||
type="password"
|
||||
placeholder="设置密码(6-20位)"
|
||||
placeholder="设置密码(5-30位)"
|
||||
autocomplete="new-password"
|
||||
>
|
||||
<PasswordStrength :password="password" />
|
||||
|
||||
Reference in New Issue
Block a user