|
|
@@ -98,7 +98,7 @@
|
|
|
<script setup>
|
|
|
import { ref, reactive } from 'vue'
|
|
|
import storage from "@/utils/storage.js"
|
|
|
-// import { resetPassword, sendVerificationCode } from '@/api/services/auth.js'
|
|
|
+import { resetPassword, forgetPassword, sendPhoneVcodeNoUnique } from '@/api/services/connect.js'
|
|
|
|
|
|
// 响应式数据
|
|
|
const formData = reactive({
|
|
|
@@ -149,7 +149,7 @@ const startCountdown = () => {
|
|
|
}, 1000)
|
|
|
}
|
|
|
|
|
|
-const getVerificationCode = () => {
|
|
|
+const getVerificationCode = async () => {
|
|
|
if (codeBtnDisabled.value) return
|
|
|
|
|
|
if (!formData.phone) {
|
|
|
@@ -168,42 +168,51 @@ const getVerificationCode = () => {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 发送验证码请求
|
|
|
- uni.showLoading({ title: '发送中...' })
|
|
|
+ uni.showLoading({ title: '验证中...' })
|
|
|
|
|
|
- // 调用发送验证码接口
|
|
|
- uni.request({
|
|
|
- url: 'API_URL/user/sendCode', // 替换为实际接口地址
|
|
|
- method: 'POST',
|
|
|
- data: {
|
|
|
- phone: formData.phone,
|
|
|
- type: 'reset'
|
|
|
- },
|
|
|
- success: (res) => {
|
|
|
- if (res.data.code === 200) {
|
|
|
- uni.showToast({
|
|
|
- title: '验证码已发送',
|
|
|
- icon: 'success'
|
|
|
- })
|
|
|
- startCountdown()
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: res.data.msg || '发送失败,请稍后重试',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
+ try {
|
|
|
+ // 第一步:校验用户信息
|
|
|
+ // const verifyRes = await forgetPassword({
|
|
|
+ // phonenumber: formData.phone
|
|
|
+ // })
|
|
|
+ // console.log("verifyRes",verifyRes);
|
|
|
+
|
|
|
+ // if (verifyRes.data.code !== 200) {
|
|
|
+ // uni.showToast({
|
|
|
+ // title: verifyRes.data.msg || '用户信息校验失败',
|
|
|
+ // icon: 'none'
|
|
|
+ // })
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 第二步:发送验证码
|
|
|
+ uni.showLoading({ title: '发送中...' })
|
|
|
+ const codeRes = await sendPhoneVcodeNoUnique({
|
|
|
+ terminal: formData.phone,
|
|
|
+ scene: 'FORGET_PWD'
|
|
|
+ })
|
|
|
+ console.log("codeRes",codeRes);
|
|
|
+ if (codeRes.data.code === 200) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '验证码已发送',
|
|
|
+ icon: 'success'
|
|
|
+ })
|
|
|
+ startCountdown()
|
|
|
+ } else {
|
|
|
uni.showToast({
|
|
|
- title: '网络异常,请稍后重试',
|
|
|
+ title: codeRes.data.msg || '发送失败,请稍后重试',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
- console.error(err)
|
|
|
- },
|
|
|
- complete: () => {
|
|
|
- uni.hideLoading()
|
|
|
}
|
|
|
- })
|
|
|
+ } catch (err) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '网络异常,请稍后重试',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ console.error(err)
|
|
|
+ } finally {
|
|
|
+ uni.hideLoading()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const validateForm = () => {
|
|
|
@@ -258,53 +267,45 @@ const validateForm = () => {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-const handleResetPassword = () => {
|
|
|
+const handleResetPassword = async () => {
|
|
|
if (!validateForm()) return
|
|
|
|
|
|
isSubmitting.value = true
|
|
|
-
|
|
|
- // 调用重置密码接口
|
|
|
uni.showLoading({ title: '提交中...' })
|
|
|
|
|
|
- // 调用重置密码接口
|
|
|
- uni.request({
|
|
|
- url: 'API_URL/user/resetPassword', // 替换为实际接口地址
|
|
|
- method: 'POST',
|
|
|
- data: {
|
|
|
- phone: formData.phone,
|
|
|
- code: formData.code,
|
|
|
+ try {
|
|
|
+ const res = await resetPassword({
|
|
|
+ phonenumber: formData.phone,
|
|
|
+ vcode: formData.code,
|
|
|
password: formData.password
|
|
|
- },
|
|
|
- success: (res) => {
|
|
|
- if (res.data.code === 200) {
|
|
|
- uni.showToast({
|
|
|
- title: '密码重置成功',
|
|
|
- icon: 'success'
|
|
|
- })
|
|
|
-
|
|
|
- // 延迟跳转到登录页
|
|
|
- setTimeout(() => {
|
|
|
- uni.navigateBack()
|
|
|
- }, 1500)
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: res.data.msg || '重置失败,请稍后重试',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
+ })
|
|
|
+
|
|
|
+ if (res.data.code === 200) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '密码重置成功',
|
|
|
+ icon: 'success'
|
|
|
+ })
|
|
|
+
|
|
|
+ // 延迟跳转到登录页
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.navigateBack()
|
|
|
+ }, 1500)
|
|
|
+ } else {
|
|
|
uni.showToast({
|
|
|
- title: '网络异常,请稍后重试',
|
|
|
+ title: res.data.msg || '重置失败,请稍后重试',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
- console.error(err)
|
|
|
- },
|
|
|
- complete: () => {
|
|
|
- uni.hideLoading()
|
|
|
- isSubmitting.value = false
|
|
|
}
|
|
|
- })
|
|
|
+ } catch (err) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '网络异常,请稍后重试',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ console.error(err)
|
|
|
+ } finally {
|
|
|
+ uni.hideLoading()
|
|
|
+ isSubmitting.value = false
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
|