完善手机号校验和验证码发送限制
This commit is contained in:
@@ -18,7 +18,8 @@ Page({
|
||||
loading: false,
|
||||
codeLoading: false,
|
||||
countdown: 0,
|
||||
countdownTimer: null
|
||||
countdownTimer: null,
|
||||
agreementAccepted: false
|
||||
},
|
||||
|
||||
async onLoad(options) {
|
||||
@@ -39,11 +40,20 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) },
|
||||
onInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
const value = field === 'phone'
|
||||
? String(event.detail.value || '').replace(/\D/g, '').slice(0, 11)
|
||||
: event.detail.value
|
||||
this.setData({ [`form.${field}`]: value })
|
||||
},
|
||||
|
||||
togglePasswordMode() { this.setData({ passwordMode: !this.data.passwordMode }) },
|
||||
|
||||
toggleAgreement() { this.setData({ agreementAccepted: !this.data.agreementAccepted }) },
|
||||
|
||||
async sendCode() {
|
||||
if (!this.data.agreementAccepted) { wx.showToast({ title: '请先同意用户协议和隐私政策', icon: 'none' }); return }
|
||||
const phone = String(this.data.form.phone || '').trim()
|
||||
if (!PHONE_REGEX.test(phone)) { wx.showToast({ title: '请输入正确手机号', icon: 'none' }); return }
|
||||
if (this.data.codeLoading || this.data.countdown > 0) return
|
||||
|
||||
Reference in New Issue
Block a user