264 lines
6.3 KiB
Vue
264 lines
6.3 KiB
Vue
<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 {
|
||
}
|
||
}
|
||
|
||
async function onReset(): 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.resetPassword({
|
||
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 reset">
|
||
<aside class="auth-page__brand">
|
||
<h1 class="auth-page__logo">
|
||
虫子智造研发<br>一体化平台
|
||
</h1>
|
||
<p class="auth-page__key">
|
||
chongzizhizaoyanfayitihuaPINGTAI
|
||
</p>
|
||
<p class="auth-page__slogan">
|
||
安全 · 高效 · 可控
|
||
</p>
|
||
</aside>
|
||
|
||
<RouterLink class="auth-page__guest" to="/">
|
||
游客模式
|
||
</RouterLink>
|
||
|
||
<main class="auth-page__main">
|
||
<div class="auth-page__card">
|
||
<h2 class="auth-page__title">
|
||
找回密码
|
||
</h2>
|
||
<p class="auth-page__subtitle">
|
||
使用手机号重新设置您的密码
|
||
</p>
|
||
|
||
<form class="reset__form" @submit.prevent="onReset">
|
||
<div class="reset__field">
|
||
<label class="reset__label" for="reset-phone">手机号</label>
|
||
<input
|
||
id="reset-phone"
|
||
v-model="phone"
|
||
class="reset__input"
|
||
type="text"
|
||
placeholder="请输入手机号"
|
||
maxlength="11"
|
||
autocomplete="tel"
|
||
>
|
||
</div>
|
||
|
||
<div class="reset__field">
|
||
<label class="reset__label" for="reset-code">验证码</label>
|
||
<SmsCodeInput id="reset-code" v-model:code="code" @get-code="onGetCode" />
|
||
</div>
|
||
|
||
<div class="reset__field">
|
||
<label class="reset__label" for="reset-password">设置密码</label>
|
||
<input
|
||
id="reset-password"
|
||
v-model="password"
|
||
class="reset__input"
|
||
type="password"
|
||
placeholder="请设置6-20位密码"
|
||
autocomplete="new-password"
|
||
>
|
||
<PasswordStrength :password="password" />
|
||
</div>
|
||
|
||
<div class="reset__field">
|
||
<label class="reset__label" for="reset-confirm">确认密码</label>
|
||
<input
|
||
id="reset-confirm"
|
||
v-model="confirmPassword"
|
||
class="reset__input"
|
||
type="password"
|
||
placeholder="请设置6-20位密码"
|
||
autocomplete="new-password"
|
||
>
|
||
</div>
|
||
|
||
<label class="reset__agree">
|
||
<input v-model="agree" type="checkbox">
|
||
<span>已阅读并同意<em>《用户协议》</em>和<em>《隐私政策》</em></span>
|
||
</label>
|
||
|
||
<button class="reset__submit" type="submit">
|
||
确认修改
|
||
</button>
|
||
</form>
|
||
|
||
<p class="reset__switch">
|
||
已有账号?<RouterLink class="auth-page__link" to="/login">立即登录</RouterLink>
|
||
</p>
|
||
</div>
|
||
</main>
|
||
</div>
|
||
</template>
|
||
|
||
<style lang="less" scoped>
|
||
// 找回密码与注册同为 4 字段布局(手机号/验证码/设置密码/确认密码),
|
||
// 间距规则与设计稿 #39 注册页一致。
|
||
.reset {
|
||
&__form {
|
||
.flex(column, flex-start, stretch);
|
||
margin: 26px 0 0;
|
||
width: 100%;
|
||
}
|
||
|
||
&__field {
|
||
.flex(column, flex-start, stretch);
|
||
gap: 6px;
|
||
width: 100%;
|
||
}
|
||
|
||
// 字段盒 = 标签17 + gap6 + 输入框40 = 63px;63 + 19 = 82px 字段间距
|
||
&__field + &__field {
|
||
margin-top: 19px;
|
||
}
|
||
|
||
&__label {
|
||
font-size: 13px;
|
||
font-weight: 500;
|
||
line-height: 17px;
|
||
color: #1f2937;
|
||
text-align: center;
|
||
}
|
||
|
||
&__input {
|
||
width: 100%;
|
||
height: 40px;
|
||
padding: 0 12px;
|
||
border: 1px solid #dde1e7;
|
||
border-radius: @radius-sm;
|
||
background: @white;
|
||
font-size: 13px;
|
||
color: #1f2937;
|
||
outline: none;
|
||
transition: border-color 0.2s;
|
||
box-sizing: border-box;
|
||
|
||
&:focus {
|
||
border-color: @primary-strong;
|
||
}
|
||
|
||
&::placeholder {
|
||
color: #1f2937;
|
||
}
|
||
}
|
||
|
||
&__agree {
|
||
.flex(row, flex-start, center);
|
||
gap: 8px;
|
||
margin-top: 21px;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
line-height: 16px;
|
||
color: #6b7280;
|
||
cursor: pointer;
|
||
|
||
input {
|
||
flex-shrink: 0;
|
||
width: 14px;
|
||
height: 14px;
|
||
margin: 0;
|
||
accent-color: @primary-strong;
|
||
}
|
||
|
||
em {
|
||
font-style: normal;
|
||
color: @primary-strong;
|
||
}
|
||
}
|
||
|
||
&__submit {
|
||
width: 100%;
|
||
height: 46px;
|
||
margin-top: 17px;
|
||
border: none;
|
||
border-radius: @radius-sm;
|
||
background: @primary-strong;
|
||
color: @white;
|
||
font-size: 15px;
|
||
font-weight: 500;
|
||
cursor: pointer;
|
||
transition: background 0.2s;
|
||
|
||
&:hover {
|
||
background: @primary-hover;
|
||
}
|
||
}
|
||
|
||
&__switch {
|
||
align-self: center;
|
||
margin: 17px 0 0;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
line-height: 16px;
|
||
color: #6b7280;
|
||
}
|
||
}
|
||
</style>
|