修改验证短信

This commit is contained in:
zhouyanli
2026-09-04 18:01:17 +08:00
parent c3004c76a8
commit 1efccef465
6 changed files with 53 additions and 41 deletions

View File

@@ -16,30 +16,27 @@
</view>
<input class="input-content verify-input native-input" :type="inputType" v-model="verifyCode"
placeholder="请输入验证码" maxlength="6" placeholder-style="font-size:24rpx"/>
<button
class="get-verify-btn"
:disabled="!canGetVerify || countDown > 0"
@click="getVerifyCode"
>
<button class="get-verify-btn" :disabled="!canGetVerify || countDown > 0"
@click="getVerifyCode">
{{ countDown > 0 ? `${countDown}s后重新获取` : '获取验证码' }}
</button>
</view>
<!-- 下一步 -->
<button
class="forget-btn"
:disabled="!canRegister"
<button
class="forget-btn"
:disabled="!canRegister || submitting"
@click="handleNext"
>
下一步
{{ submitting ? '校验中...' : '下一步' }}
</button>
</view>
</template>
<script setup>
import { ref, computed, onUnmounted } from 'vue';
import {getSendCode} from '../api/api.js'
import {getSendCode,verifySmsCode} from '../api/api.js'
// 输入框类型:统一用 text,避免 number 在真机上把 -/. 过滤掉导致手机号被误判合法;非法手机号由 canGetVerify 禁用获取验证码按钮
// 输入框类型:统一用 text
const inputType = 'text'
// ====响应式数据======
@@ -47,6 +44,7 @@ const phoneNumber = ref('')
const verifyCode = ref('')
const countDown = ref(0)
const submitting = ref(false)
let timer = null;
const placeholderStyle = ref('font-size:24rpx')
@@ -105,18 +103,34 @@ const canRegister = computed(() => {
});
// 下一步
const handleNext = () =>{
// 把参数存到本地缓存
uni.setStorageSync('tempChangePwdParams', {
phoneNumber:phoneNumber.value,
verifyCode: verifyCode.value
});
if(!canRegister.value){
uni.showToast({ title: '请输入',icon: 'error'});
return
}
uni.navigateTo({
url: '/pageSubPack/loginSub/change-pwd'
});
if(!canRegister.value){
uni.showToast({ title: '请输入正确的手机号和验证码', icon: 'none'});
return
}
if(submitting.value) return
submitting.value = true
// 后端验证短信
verifySmsCode({
phone: phoneNumber.value,
smsCode: verifyCode.value,
scene: 'reset'
}).then(res =>{
// 把参数存到本地缓存
uni.setStorageSync('tempChangePwdParams', {
phoneNumber:phoneNumber.value,
verifyCode: verifyCode.value
});
uni.navigateTo({
url: '/pageSubPack/loginSub/change-pwd'
});
}).catch(err =>{
uni.showToast({
title: err.msg || '验证码错误',
icon: 'none'
});
}).finally(() =>{
submitting.value = false
})
}
// 返回上一页
const goBack = () => {