184 lines
3.9 KiB
JavaScript
184 lines
3.9 KiB
JavaScript
import {url} from '../../request'
|
|
Page({
|
|
data: {
|
|
|
|
},
|
|
phone(e){
|
|
this.setData({
|
|
phone:e.detail.value
|
|
})
|
|
console.log(e.detail.value);
|
|
},
|
|
yanzhengma(e){
|
|
this.setData({
|
|
yanzhengma:e.detail.value
|
|
})
|
|
console.log(e.detail.value);
|
|
},
|
|
password(e){
|
|
this.setData({
|
|
password:e.detail.value
|
|
})
|
|
console.log(e.detail.value);
|
|
},
|
|
passwordagain(e){
|
|
this.setData({
|
|
passwordagain:e.detail.value
|
|
})
|
|
console.log(e.detail.value);
|
|
},
|
|
subimt(){
|
|
const phone = this.data.phone
|
|
const yanzhengma = this.data.yanzhengma
|
|
const password = this.data.password
|
|
const passwordagain = this.data.passwordagain
|
|
console.log(phone,'aslkjyhdkjashdjkashkj');
|
|
if (!/^\d{11}$/.test(phone)) {
|
|
wx.showToast({
|
|
title: '请输入11位的手机号',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
if (!/^\d{6}$/.test(yanzhengma)) {
|
|
wx.showToast({
|
|
title: '请输入6位的验证码',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
if (!/^[a-zA-Z0-9]{6,10}$/.test(password)) {
|
|
wx.showToast({
|
|
title: '请输入6~10位的密码',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
if (!/^[a-zA-Z0-9]{6,10}$/.test(passwordagain)) {
|
|
wx.showToast({
|
|
title: '请再次输入密码',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
if(password !== passwordagain){
|
|
wx.showToast({
|
|
title: '两次输入的密码不一致,请重新输入',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
wx.request({
|
|
url: url + '/userInfo/mini/out/reset/pwd',
|
|
method: 'POST',
|
|
data: {
|
|
phoneNumber: this.data.phone,
|
|
verificationCode: this.data.yanzhengma,
|
|
userPassword: this.data.password,
|
|
userConfirmPassword: this.data.passwordagain
|
|
},
|
|
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
|
|
});
|
|
}
|
|
},
|
|
fail(err) {
|
|
console.error('请求失败', err);
|
|
}
|
|
});
|
|
},
|
|
// 获取验证码
|
|
getcode(){
|
|
const phone = this.data.phone;
|
|
console.log(phone,'askjhdsakjhdjkashjk');
|
|
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);
|
|
}
|
|
});
|
|
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);
|
|
}
|
|
},
|
|
back(){
|
|
wx.navigateTo({
|
|
url: '/pages/logain/logain',
|
|
})
|
|
}
|
|
|
|
}) |