feat:登录的功能完成
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
<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 { validatePhone } from '@/utils/sms-code'
|
||||
import CodeInput from './components/CodeInput.vue'
|
||||
import ForgotInput from './components/ForgotInput.vue'
|
||||
import PasswordField from './components/PasswordField.vue'
|
||||
@@ -10,12 +15,16 @@ const code = ref('')
|
||||
const newPassword = ref('')
|
||||
const confirmPassword = ref('')
|
||||
const agreed = ref(false)
|
||||
const submitting = ref(false)
|
||||
|
||||
function toggleAgreed() {
|
||||
agreed.value = !agreed.value
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
async function handleSubmit() {
|
||||
if (submitting.value)
|
||||
return
|
||||
|
||||
if (!agreed.value) {
|
||||
uni.showToast({ title: '请先同意用户协议', icon: 'none' })
|
||||
return
|
||||
@@ -24,15 +33,40 @@ function handleSubmit() {
|
||||
uni.showToast({ title: '请填写完整信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!validatePhone(phone.value))
|
||||
return
|
||||
if (newPassword.value !== confirmPassword.value) {
|
||||
uni.showToast({ title: '两次密码输入不一致', icon: 'none' })
|
||||
return
|
||||
}
|
||||
navigateToResultPage('resetPassword')
|
||||
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() {
|
||||
uni.navigateBack()
|
||||
navigateBackWithFallback('/pages/Login/user-login/index')
|
||||
}
|
||||
|
||||
function handleUserAgreement() {
|
||||
@@ -75,6 +109,7 @@ function handleUserAgreement() {
|
||||
v-model="newPassword"
|
||||
placeholder="请输入新密码"
|
||||
/>
|
||||
<PasswordStrength :password="newPassword" />
|
||||
</view>
|
||||
|
||||
<view class="forgot-page__field">
|
||||
@@ -126,9 +161,10 @@ function handleUserAgreement() {
|
||||
|
||||
<button
|
||||
class="forgot-page__submit"
|
||||
:disabled="submitting"
|
||||
@tap="handleSubmit"
|
||||
>
|
||||
确认修改
|
||||
{{ submitting ? '提交中...' : '确认修改' }}
|
||||
</button>
|
||||
</view>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user