Files
cz-web/src/views/login/reset.vue
2026-10-01 10:53:13 +08:00

279 lines
6.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<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 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"
>
<!-- 设计稿:密码框下 15 高密码强度条 + 15 高提示行 -->
<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>
// 设计稿(找回密码):表单列起点 x1040(--auth-form-x 1023 + 17)、垂直顶 261
.reset {
--auth-form-x: 1023px;
--auth-form-y: 261px;
&__form {
.flex(column, flex-start, stretch);
// 副标题底 335 → 首个标签 361 = 26(副标题行盒 17 + 外边距 12 → 实际需补 38)
margin: 38px 0 0 17px;
width: 680px;
}
&__field {
.flex(column, flex-start, stretch);
gap: 8px;
width: 680px;
}
// 设计稿:手机号框底 425 → 验证码标签 443 = 18
&__field + &__field {
margin-top: 18px;
}
&__label {
font-size: 13px; // 设计稿 13/500 #1F2937
font-weight: 500;
line-height: 17px;
color: #1f2937;
}
&__input {
width: 100%;
height: 39px;
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;
}
}
// 设计稿:协议行 @(1040,741)
&__agree {
.flex(row, flex-start, center);
gap: 8px;
margin-top: 22px;
font-size: 12px;
font-weight: 400;
line-height: 16px;
color: #6b7280;
cursor: pointer;
input {
flex-shrink: 0;
width: 16px;
height: 16px;
margin: 0;
accent-color: @primary-strong;
}
em {
font-style: normal;
color: @primary-strong;
}
}
// 设计稿:确认修改按钮 680×46 @y775、#024FFF 实底、文字 15/500
&__submit {
width: 100%;
height: 46px;
margin-top: 18px;
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;
}
}
// 设计稿:按钮底 821 → 切换行 838 = 17
&__switch {
align-self: center;
margin: 17px 0 0;
font-size: 12px;
font-weight: 400;
line-height: 16px;
color: #6b7280;
}
&__subtitle {
margin: 12px 0 0;
font-size: 13px; // 设计稿 13/400 #6B7280
font-weight: 400;
line-height: 17px;
color: #6b7280;
}
}
</style>