feat:登录注册完成

This commit is contained in:
李伊帆
2026-10-09 14:29:58 +08:00
parent da83a58948
commit ee3ecc00eb
106 changed files with 4937 additions and 59 deletions

View File

@@ -0,0 +1,47 @@
import { ref } from 'vue'
import { useSmsCode } from '@/hooks/use-sms-code'
import { getErrorMessage } from '@/utils/api-error'
import { isValidPhone, isValidSmsCode } from '@/utils/validate'
import { SMS_CODE_SCENE } from '@/types/api'
import { verifyForgetPasswordCode } from './forgot-password.api'
export function useForgotPassword() {
const phone = ref('')
const code = ref('')
const loading = ref(false)
const { counting, seconds, sendCode } = useSmsCode(SMS_CODE_SCENE.reset)
function onSendCode() {
sendCode(phone.value)
}
async function nextStep() {
if (!isValidPhone(phone.value)) {
uni.showToast({ title: '请输入正确手机号', icon: 'none' })
return
}
if (!isValidSmsCode(code.value)) {
uni.showToast({ title: '请输入验证码', icon: 'none' })
return
}
if (loading.value) return
loading.value = true
try {
const res = await verifyForgetPasswordCode({ phone: phone.value, code: code.value })
if (!res.resetToken) {
uni.showToast({ title: '验证失败,未获取重置令牌', icon: 'none' })
return
}
uni.navigateTo({
url: `/pages/change-password/index?resetToken=${encodeURIComponent(res.resetToken)}`,
})
} catch (err) {
uni.showToast({ title: getErrorMessage(err, '验证失败,请重试'), icon: 'none' })
} finally {
loading.value = false
}
}
return { phone, code, counting, seconds, onSendCode, nextStep }
}