mirror of
https://gitee.com/qingqing-coconut-tea/RcKtFezyRAZX
synced 2026-07-21 10:32:32 +08:00
init
This commit is contained in:
103
wechat/pages/bind-phone/bind-phone.js
Normal file
103
wechat/pages/bind-phone/bind-phone.js
Normal file
@@ -0,0 +1,103 @@
|
||||
// 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,查看完整运行演示。
|
||||
*/
|
||||
Reference in New Issue
Block a user