218 lines
4.7 KiB
JavaScript
218 lines
4.7 KiB
JavaScript
import {
|
||
removeToken
|
||
} from '../../utils/auth'
|
||
import {
|
||
codeUpdatePwd,
|
||
sendPhoneMessage
|
||
} from '../../api/login'
|
||
const app = getApp();
|
||
const timer = null;
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
isSend: false,
|
||
count: 120,
|
||
timer: null,
|
||
butText: "发送验证码",
|
||
username: "",
|
||
password: "",
|
||
pw: "",
|
||
code: "",
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
this.resetCountdown();
|
||
},
|
||
|
||
returnToPage: function () {
|
||
wx.redirectTo({
|
||
url: '../login/index',
|
||
})
|
||
},
|
||
|
||
//获取填写的账号信息
|
||
name: function (even) {
|
||
this.setData({
|
||
username: even.detail.value
|
||
})
|
||
},
|
||
|
||
//获取填写的密码信息
|
||
pass: function (even) {
|
||
this.setData({
|
||
password: even.detail.value
|
||
})
|
||
},
|
||
|
||
//获取填写的密码信息
|
||
rpass: function (even) {
|
||
this.setData({
|
||
pw: even.detail.value
|
||
})
|
||
},
|
||
|
||
//获取填写的密码信息
|
||
code: function (even) {
|
||
this.setData({
|
||
code: even.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 发送验证码
|
||
*/
|
||
sendCode() {
|
||
if (!this.data.isSend) {
|
||
if (this.data.username && this.data.username.length == 11) {
|
||
sendPhoneMessage(this.data.username).then(res => {
|
||
if (res.code == 200 && res.data) {
|
||
app.toast("已发送验证码,请注意查收。5分钟内有效!", 1200);
|
||
this.startCountdown();
|
||
} else {
|
||
app.toast("请稍后再试!", 1200);
|
||
}
|
||
});
|
||
} else {
|
||
app.toast("请输入正确的手机号码!");
|
||
}
|
||
}
|
||
},
|
||
|
||
startCountdown() {
|
||
this.setData({
|
||
isSend: true,
|
||
butText: this.data.count + "秒后发送",
|
||
})
|
||
this.timer = setInterval(() => {
|
||
let can = this.data.count - 1;
|
||
if (can <= 0) {
|
||
console.log(can, "xxxxxxxxxxxxxxx");
|
||
clearInterval(this.timer);
|
||
this.resetCountdown();
|
||
} else {
|
||
this.setData({
|
||
isSend: true,
|
||
count: can,
|
||
butText: can + "秒后发送",
|
||
})
|
||
}
|
||
}, 1000);
|
||
},
|
||
|
||
resetCountdown() {
|
||
this.setData({
|
||
isSend: false,
|
||
count: 20,
|
||
butText: "发送验证码",
|
||
})
|
||
if (this.timer) {
|
||
clearInterval(this.timer);
|
||
}
|
||
},
|
||
|
||
//修改密码
|
||
alertPass: function () {
|
||
let {
|
||
username,
|
||
password,
|
||
pw,
|
||
code
|
||
} = this.data;
|
||
var that = this;
|
||
if (username == "") {
|
||
app.toast("手机账号不能为空");
|
||
return;
|
||
}
|
||
if (code == "") {
|
||
app.toast("验证码不能为空");
|
||
return;
|
||
}
|
||
if (password == "") {
|
||
app.toast("登录密码不能为空");
|
||
return;
|
||
}
|
||
if (pw == "") {
|
||
app.toast("确认密码不能为空");
|
||
return;
|
||
}
|
||
if (pw != password) {
|
||
app.toast("登录密码和确认密码不一致");
|
||
return;
|
||
}
|
||
let data = {
|
||
loginName: username,
|
||
password: password,
|
||
confPass: pw,
|
||
code: code,
|
||
source: "r",
|
||
};
|
||
codeUpdatePwd(data).then(res => {
|
||
if (res.code == 200) {
|
||
app.toast("密码修改成功!",800);
|
||
removeToken();
|
||
wx.clearStorageSync();
|
||
wx.setStorageSync('isReload', "1");
|
||
setTimeout(()=>{
|
||
wx.redirectTo({
|
||
url: '../login/index',
|
||
});
|
||
},500)
|
||
}
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
|
||
}
|
||
}) |