Files
mzltMpfqGS e4a087e67e init
2026-04-15 19:45:16 +08:00

104 lines
2.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/bind-phone/bind-phone.js
// 绑定手机号逻辑处理
const api = require('../../services/api')
Page({
data: {
phone: '',
verifyCode: '',
openid: '',
countdown: 0,
sendBtnText: '获取验证码',
loading: false
},
onLoad(options) {
if (options.openid) {
this.setData({ openid: options.openid })
}
},
onPhoneInput(e) {
this.setData({ phone: e.detail.value })
},
onVerifyCodeInput(e) {
this.setData({ verifyCode: e.detail.value })
},
onSendVerifyCode() {
const phone = this.data.phone.trim()
if (!phone) {
wx.showToast({ title: '请输入手机号', icon: 'none' })
return
}
api.sendSmsCode({ phone }).then(res => {
if (res.code === 200) {
wx.showToast({ title: '验证码已发送', icon: 'success' })
this.startCountdown()
} else {
wx.showToast({ title: res.message || '发送失败', icon: 'none' })
}
})
},
startCountdown() {
let seconds = 60
this.setData({ countdown: seconds, sendBtnText: `${seconds}s` })
const timer = setInterval(() => {
seconds--
if (seconds <= 0) {
clearInterval(timer)
this.setData({ countdown: 0, sendBtnText: '获取验证码' })
} else {
this.setData({ sendBtnText: `${seconds}s` })
}
}, 1000)
},
doBind() {
const { phone, verifyCode, openid } = this.data
if (!phone.trim()) {
wx.showToast({ title: '请输入手机号', icon: 'none' })
return
}
if (!verifyCode.trim()) {
wx.showToast({ title: '请输入验证码', icon: 'none' })
return
}
this.setData({ loading: true })
api.bindPhone({
phone: phone.trim(),
verifyCode: verifyCode.trim(),
openid: openid
}).then(res => {
this.setData({ loading: false })
if (res.code === 200) {
wx.showToast({ title: '绑定成功', icon: 'success' })
setTimeout(() => {
wx.navigateBack()
}, 1500)
} else {
wx.showToast({ title: res.message || '绑定失败', icon: 'none' })
}
}).catch(() => {
this.setData({ loading: false })
wx.showToast({ title: '绑定失败', icon: 'none' })
})
}
})
/**
* @联系作者16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415查看完整运行演示。
*/