feat 搭建架构骨架
This commit is contained in:
287
src/views/login/register.vue
Normal file
287
src/views/login/register.vue
Normal file
@@ -0,0 +1,287 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { PasswordStrength, SmsCodeInput } 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 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('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
if (!/^\d{6}$/.test(code.value)) {
|
||||
ElMessage.warning('请输入6位验证码')
|
||||
return
|
||||
}
|
||||
if (!isValidPassword(password.value)) {
|
||||
ElMessage.warning('密码长度应为6-20位')
|
||||
return
|
||||
}
|
||||
if (password.value !== confirmPassword.value) {
|
||||
ElMessage.warning('两次输入的密码不一致')
|
||||
return
|
||||
}
|
||||
if (!agree.value) {
|
||||
ElMessage.warning('请先阅读并同意《用户协议》和《隐私政策》')
|
||||
return
|
||||
}
|
||||
const ok = await userStore.register({
|
||||
phone: phone.value,
|
||||
code: code.value,
|
||||
password: password.value,
|
||||
confirmPassword: confirmPassword.value,
|
||||
agree: agree.value,
|
||||
})
|
||||
if (ok) {
|
||||
redirectTimer = window.setTimeout(() => {
|
||||
void router.push('/login')
|
||||
}, 3000)
|
||||
}
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (redirectTimer !== null) window.clearTimeout(redirectTimer)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="auth-page">
|
||||
<aside class="auth-page__brand">
|
||||
<div class="auth-page__brand-inner">
|
||||
<p class="auth-page__logo">
|
||||
虫子智造研发一体化平台
|
||||
</p>
|
||||
<p class="auth-page__slogan">
|
||||
安全 · 高效 · 可控
|
||||
</p>
|
||||
<RouterLink class="auth-page__guest" to="/">
|
||||
游客模式 →
|
||||
</RouterLink>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<main class="auth-page__main">
|
||||
<div class="auth-page__card">
|
||||
<h1 class="auth-page__title">
|
||||
注册账号
|
||||
</h1>
|
||||
|
||||
<form class="auth-page__form" @submit.prevent="onRegister">
|
||||
<input
|
||||
v-model="phone"
|
||||
class="auth-page__input"
|
||||
type="text"
|
||||
placeholder="请输入手机号"
|
||||
maxlength="11"
|
||||
autocomplete="tel"
|
||||
>
|
||||
<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位)"
|
||||
autocomplete="new-password"
|
||||
>
|
||||
<PasswordStrength :password="password" />
|
||||
</div>
|
||||
<input
|
||||
v-model="confirmPassword"
|
||||
class="auth-page__input"
|
||||
type="password"
|
||||
placeholder="确认密码"
|
||||
autocomplete="new-password"
|
||||
>
|
||||
<label class="auth-page__agree">
|
||||
<input v-model="agree" type="checkbox">
|
||||
<span>已阅读并同意《用户协议》和《隐私政策》</span>
|
||||
</label>
|
||||
<button class="auth-page__submit" type="submit">
|
||||
注 册
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p class="auth-page__switch">
|
||||
已有账号?<RouterLink class="auth-page__link" to="/login">立即登录</RouterLink>
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.auth-page {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
background: @bg-color;
|
||||
|
||||
&__brand {
|
||||
flex: 0 0 44%;
|
||||
.flex(row, center, center);
|
||||
background: linear-gradient(135deg, @primary-color 0%, #1b4fd8 100%);
|
||||
color: @white;
|
||||
}
|
||||
|
||||
&__brand-inner {
|
||||
.flex(column, flex-start);
|
||||
gap: @spacing-lg;
|
||||
padding: @spacing-xxl;
|
||||
}
|
||||
|
||||
&__logo {
|
||||
font-size: 32px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 2px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
&__slogan {
|
||||
font-size: @font-size-xl;
|
||||
opacity: 0.85;
|
||||
letter-spacing: 6px;
|
||||
}
|
||||
|
||||
&__guest {
|
||||
margin-top: @spacing-xl;
|
||||
padding: @spacing-sm @spacing-base;
|
||||
border: 1px solid rgba(255, 255, 255, 0.6);
|
||||
border-radius: @radius-base;
|
||||
color: @white;
|
||||
font-size: @font-size-base;
|
||||
text-decoration: none;
|
||||
transition: background 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
&__main {
|
||||
flex: 1;
|
||||
.flex(row, center, center);
|
||||
padding: @spacing-xl;
|
||||
}
|
||||
|
||||
&__card {
|
||||
.flex(column, flex-start);
|
||||
gap: @spacing-base;
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
padding: @spacing-xl @spacing-lg;
|
||||
border-radius: @radius-lg;
|
||||
background: @white;
|
||||
box-shadow: @shadow-lg;
|
||||
}
|
||||
|
||||
&__title {
|
||||
font-size: @font-size-xl;
|
||||
font-weight: 600;
|
||||
color: @heading-color;
|
||||
}
|
||||
|
||||
&__form {
|
||||
.flex(column, flex-start);
|
||||
gap: @spacing-base;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&__pwd-wrap {
|
||||
.flex(column, flex-start);
|
||||
gap: @spacing-xs;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&__input {
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
padding: 0 @spacing-base;
|
||||
border: 1px solid @border-color;
|
||||
border-radius: @radius-base;
|
||||
background: @bg-color-light;
|
||||
font-size: @font-size-base;
|
||||
color: @heading-color;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
box-sizing: border-box;
|
||||
|
||||
&:focus {
|
||||
border-color: @primary-color;
|
||||
}
|
||||
|
||||
&::placeholder {
|
||||
color: @text-color-secondary;
|
||||
}
|
||||
}
|
||||
|
||||
&__agree {
|
||||
.flex(row, flex-start);
|
||||
gap: @spacing-xs;
|
||||
font-size: @font-size-sm;
|
||||
color: @text-color-secondary;
|
||||
cursor: pointer;
|
||||
|
||||
input {
|
||||
margin-top: 2px;
|
||||
accent-color: @primary-color;
|
||||
}
|
||||
}
|
||||
|
||||
&__submit {
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
border: none;
|
||||
border-radius: @radius-base;
|
||||
background: @primary-color;
|
||||
color: @white;
|
||||
font-size: @font-size-lg;
|
||||
letter-spacing: 2px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: @primary-hover;
|
||||
}
|
||||
}
|
||||
|
||||
&__switch {
|
||||
text-align: center;
|
||||
font-size: @font-size-base;
|
||||
color: @text-color-secondary;
|
||||
}
|
||||
|
||||
&__link {
|
||||
color: @primary-color;
|
||||
|
||||
&:hover {
|
||||
color: @primary-hover;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user