主题
验证码
获取验证码
js
//获取短信验证码
async getMsgCode(){
if(this.isSendCode){
if(this.cellphone.trim()==''){
uni.showToast({
title: '请输入手机号',
icon: 'none',
duration:2000
})
return;
}
if(!this.cellphone.match(/^1[0-9][0-9]\d{8}$/)){
uni.showToast({
title: '您输入的手机号格式不正确',
icon: 'none',
duration:2000
})
return;
}
let existCellphone=await this.existCellphone({cellphone:this.cellphone});
if(existCellphone.data.exist=='1'){//手机号已存在
uni.showToast({
title: '手机号存在,请更换',
icon: 'none',
duration:2000
});
return;
}
let smsCode=await this.sendCode({cellphone:this.cellphone});
if(smsCode.code==200){
uni.showToast({
title: ""+smsCode.data.sms_code+"",
icon: 'none',
duration:3000
});
this.isSendCode=false;
let time=10;
this.msgText="重新获取("+time+"s)";
this.timer=setInterval(()=>{
if(time<=0){
clearInterval(this.timer);
this.isSendCode=true;
this.msgText="获取验证码";
}else{
time--;
this.msgText="重新获取("+time+"s)";
}
},1000);
}
}
}