210 lines
5.4 KiB
Vue
210 lines
5.4 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from 'vue'
|
|
import { resetPassword } from '@/api/auth'
|
|
import PasswordStrength from '@/pages/Login/user-register/components/PasswordStrength.vue'
|
|
import { getPasswordStrength } from '@/utils/password-strength'
|
|
import { navigateBackWithFallback } from '@/utils/navigate-back'
|
|
import { navigateToResultPage } from '@/utils/navigate-result'
|
|
import { navigateToSecurityPage } from '@/utils/navigate-security-page'
|
|
import { validatePhone } from '@/utils/sms-code'
|
|
import CodeInput from './components/CodeInput.vue'
|
|
import ForgotInput from './components/ForgotInput.vue'
|
|
import PasswordField from './components/PasswordField.vue'
|
|
|
|
const phone = ref('')
|
|
const code = ref('')
|
|
const newPassword = ref('')
|
|
const confirmPassword = ref('')
|
|
const agreed = ref(false)
|
|
const submitting = ref(false)
|
|
|
|
function toggleAgreed() {
|
|
uni.showModal({
|
|
title: '服务协议及隐私保护',
|
|
content: '为了更好地保障您的合法权益,请您阅读并同意《用户协议》《隐私政策》以及《定制条款》',
|
|
confirmText: '同意',
|
|
cancelText: '不同意',
|
|
confirmColor: '#2563EB',
|
|
success: (res) => {
|
|
agreed.value = !!res.confirm
|
|
},
|
|
})
|
|
}
|
|
|
|
async function handleSubmit() {
|
|
if (submitting.value)
|
|
return
|
|
|
|
if (!agreed.value) {
|
|
uni.showToast({ title: '请先同意用户协议', icon: 'none' })
|
|
return
|
|
}
|
|
if (!phone.value || !code.value || !newPassword.value || !confirmPassword.value) {
|
|
uni.showToast({ title: '请填写完整信息', icon: 'none' })
|
|
return
|
|
}
|
|
if (!validatePhone(phone.value))
|
|
return
|
|
if (newPassword.value !== confirmPassword.value) {
|
|
uni.showToast({ title: '两次密码输入不一致', icon: 'none' })
|
|
return
|
|
}
|
|
if (getPasswordStrength(newPassword.value).isTooWeak) {
|
|
uni.showToast({ title: '密码等级过低,请重新输入', icon: 'none' })
|
|
return
|
|
}
|
|
|
|
submitting.value = true
|
|
uni.showLoading({ title: '提交中...', mask: true })
|
|
|
|
try {
|
|
await resetPassword({
|
|
phoneNumber: phone.value.trim(),
|
|
smsCode: code.value.trim(),
|
|
newPassword: newPassword.value,
|
|
confirmPassword: confirmPassword.value,
|
|
})
|
|
navigateToResultPage('resetPassword')
|
|
}
|
|
catch {
|
|
// 错误提示由 request 统一处理
|
|
}
|
|
finally {
|
|
submitting.value = false
|
|
uni.hideLoading()
|
|
}
|
|
}
|
|
|
|
function handleLogin() {
|
|
navigateBackWithFallback('/pages/Login/user-login/index')
|
|
}
|
|
|
|
function handleUserAgreement() {
|
|
navigateToSecurityPage('userAgreement')
|
|
}
|
|
|
|
function handlePrivacyPolicy() {
|
|
navigateToSecurityPage('privacyPolicy')
|
|
}
|
|
|
|
function handleCustomTerms() {
|
|
navigateToSecurityPage('customTerms')
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<view class="forgot-page">
|
|
<view class="forgot-page__header">
|
|
<text class="forgot-page__title">
|
|
找回密码
|
|
</text>
|
|
<text class="forgot-page__subtitle">
|
|
使用手机号重新设置您的密码
|
|
</text>
|
|
</view>
|
|
|
|
<view class="forgot-page__form">
|
|
<view class="forgot-page__field">
|
|
<ForgotInput
|
|
v-model="phone"
|
|
placeholder="请输入手机号"
|
|
input-type="number"
|
|
/>
|
|
</view>
|
|
|
|
<view class="forgot-page__field">
|
|
<CodeInput
|
|
v-model="code"
|
|
:phone="phone"
|
|
scene="resetPwd"
|
|
/>
|
|
</view>
|
|
|
|
<view class="forgot-page__field">
|
|
<PasswordField
|
|
v-model="newPassword"
|
|
placeholder="请输入新密码"
|
|
/>
|
|
<PasswordStrength :password="newPassword" />
|
|
</view>
|
|
|
|
<view class="forgot-page__field">
|
|
<PasswordField
|
|
v-model="confirmPassword"
|
|
placeholder="请再次输入新密码"
|
|
/>
|
|
</view>
|
|
|
|
<view
|
|
class="forgot-page__agreement"
|
|
@tap="toggleAgreed"
|
|
>
|
|
<view
|
|
class="forgot-page__checkbox"
|
|
:class="{ 'forgot-page__checkbox--checked': agreed }"
|
|
>
|
|
<text
|
|
v-if="agreed"
|
|
class="forgot-page__checkmark"
|
|
>
|
|
✓
|
|
</text>
|
|
</view>
|
|
<view class="forgot-page__agreement-text">
|
|
<text class="forgot-page__agreement-normal">
|
|
我已阅读并同意
|
|
</text>
|
|
<text
|
|
class="forgot-page__agreement-link"
|
|
@tap.stop="handleUserAgreement"
|
|
>
|
|
用户协议
|
|
</text>
|
|
<text class="forgot-page__agreement-normal">
|
|
和
|
|
</text>
|
|
<text
|
|
class="forgot-page__agreement-link"
|
|
@tap.stop="handlePrivacyPolicy"
|
|
>
|
|
隐私政策
|
|
</text>
|
|
<text class="forgot-page__agreement-normal">
|
|
以及
|
|
</text>
|
|
<text
|
|
class="forgot-page__agreement-link"
|
|
@tap.stop="handleCustomTerms"
|
|
>
|
|
定制条款
|
|
</text>
|
|
</view>
|
|
</view>
|
|
|
|
<button
|
|
class="forgot-page__submit"
|
|
:disabled="submitting"
|
|
@tap="handleSubmit"
|
|
>
|
|
{{ submitting ? '提交中...' : '确认修改' }}
|
|
</button>
|
|
</view>
|
|
|
|
<view class="forgot-page__footer">
|
|
<text class="forgot-page__footer-normal">
|
|
已有账号?
|
|
</text>
|
|
<text
|
|
class="forgot-page__footer-link"
|
|
@tap="handleLogin"
|
|
>
|
|
立即登录
|
|
</text>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<style scoped lang="scss">
|
|
@import './index.scss';
|
|
</style>
|