qingcheng-xiaochengxu/pages/zucepage/zucepage.js

209 lines
4.4 KiB
JavaScript
Raw Normal View History

2025-05-11 07:12:01 +00:00
import {url} from '../../request'
2025-04-28 07:59:21 +00:00
Page({
/**
* 页面的初始数据
*/
data: {
2025-05-15 13:01:14 +00:00
countdown: 60, // 设置倒计时时长(秒)
timer: null, // 存储计时器
2025-04-28 07:59:21 +00:00
},
2025-05-11 07:12:01 +00:00
name(e){
this.setData({
name:e.detail.value
})
console.log(e.detail.value);
2025-04-28 07:59:21 +00:00
},
2025-05-11 07:12:01 +00:00
phone(e){
this.setData({
phone:e.detail.value
})
console.log(e.detail.value);
2025-04-28 07:59:21 +00:00
},
2025-05-11 07:12:01 +00:00
code(e){
this.setData({
code:e.detail.value
})
console.log(e.detail.value);
2025-04-28 07:59:21 +00:00
},
2025-05-11 07:12:01 +00:00
yanzhengma(e){
this.setData({
yanzhengma:e.detail.value
})
console.log(e.detail.value);
2025-04-28 07:59:21 +00:00
},
2025-05-11 07:12:01 +00:00
password(e){
this.setData({
password:e.detail.value
})
console.log(e.detail.value);
2025-04-28 07:59:21 +00:00
},
2025-05-11 07:12:01 +00:00
getcode(){
const phone = this.data.phone;
if (!/^\d{11}$/.test(phone)) {
wx.showToast({
title: '请输入11位的手机号',
icon: 'none'
});
return;
}
wx.request({
url: url + '/userInfo/code',
method: 'POST',
data: {
templateString: this.data.phone
},
header: {
'content-type': 'application/json'
},
success(res) {
console.log('发送成功', res);
if(res.data.code==1){
wx.showToast({
title: '发送成功',
icon: 'success',
duration: 2000
});
}else{
wx.showToast({
title: res.data.message,
icon: 'success',
duration: 2000
});
}
},
fail(err) {
console.error('请求失败', err);
}
});
2025-05-15 13:01:14 +00:00
this.startCountdown();
},
startCountdown() {
this.setData({
isCountingDown: true,
countdown: 60
});
this.data.timer = setInterval(() => {
let count = this.data.countdown;
if (count <= 1) {
clearInterval(this.data.timer);
this.setData({
isCountingDown: false,
countdown: 60
});
} else {
this.setData({
countdown: count - 1
});
}
}, 1000);
},
onUnload() {
// 页面卸载时清除定时器
if (this.data.timer) {
clearInterval(this.data.timer);
}
2025-04-28 07:59:21 +00:00
},
2025-05-11 07:12:01 +00:00
// 注册
submit(){
const yanzhengma = this.data.yanzhengma
const phone = this.data.phone
const password = this.data.password
const code = this.data.code
const name = this.data.name
if (!name) {
wx.showToast({
title: '请输入昵称',
icon: 'none'
});
return;
}
if (!/^\d{6}$/.test(yanzhengma)) {
wx.showToast({
title: '请输入6位验证码',
icon: 'none'
});
return;
}
if (!/^\d{6,11}$/.test(phone)) {
wx.showToast({
title: '请输入6到11位的账号',
icon: 'none'
});
return;
}
// 密码验证6~10位字符
if (!/^.{6,10}$/.test(password)) {
wx.showToast({
title: '请输入6到10位的密码',
icon: 'none'
});
return;
}
if (!/^\d{6}$/.test(code)) {
wx.showToast({
title: '请输入6位的邀请码',
icon: 'none'
});
return;
}
if (this.data.isAgree!=true) {
wx.showToast({
title: '请先勾选协议',
icon: 'none'
});
return;
}
console.log("sakldhasjdhja");
wx.request({
url: url + '/userInfo/register',
method: 'POST',
data: {
nickName: this.data.name,
phoneNumber: this.data.phone,
verificationCode: this.data.yanzhengma,
invitationCode: this.data.code,
userPassword: this.data.password
},
header: {
'content-type': 'application/json'
},
success(res) {
console.log('注册成功', res);
if(res.data.code==1){
wx.showToast({
title: '注册成功',
icon: 'success',
duration: 2000
});
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 2000);
}else{
wx.showToast({
title: res.data.message,
icon: 'error',
duration: 2000
});
2025-05-15 13:01:14 +00:00
2025-05-11 07:12:01 +00:00
}
},
fail(err) {
console.error('请求失败', err);
}
});
2025-04-28 07:59:21 +00:00
},
2025-05-11 07:12:01 +00:00
// 勾选
onAgreeChange(e) {
this.setData({
isAgree: true
});
console.log("gaibianler",this.data.isAgree);
},
})