173 lines
3.6 KiB
JavaScript
173 lines
3.6 KiB
JavaScript
import { baseUrl } from "../../../request";
|
|
import { formatPassword } from "../../../utils/util"
|
|
|
|
// pages/personCenter/resetPwd/resetPwd.js
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
phone: '', // 手机号
|
|
sending: false, // 是否发送验证码
|
|
count: 60,
|
|
password: '', // 第一次输入的密码
|
|
currentPwd: '', // 再次确认密码
|
|
verificationCode: '' // 验证码
|
|
},
|
|
|
|
resetPwd() {
|
|
const { phone, verificationCode, password, currentPwd } = this.data;
|
|
formatPassword(password,currentPwd);
|
|
wx.request({
|
|
url: baseUrl + '/userInfo/mini/in/reset/pwd',
|
|
method: 'POST',
|
|
header: {
|
|
Authorization: wx.getStorageSync('token')
|
|
},
|
|
data: {
|
|
phoneNumber: phone,
|
|
verificationCode: verificationCode,
|
|
userPassword: password,
|
|
userConfirmPassword: currentPwd
|
|
},
|
|
success: res => {
|
|
console.log('修改密码--->',res);
|
|
if (res.data.code === 1) {
|
|
wx.showToast({
|
|
title: '更改密码成功',
|
|
icon: 'success'
|
|
})
|
|
wx.reLaunch({
|
|
url: '/pages/loginModule/pwdLogin/pwdLogin',
|
|
})
|
|
} else {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: res.data.message
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
// 获取验证码
|
|
getVerificationCode() {
|
|
const { phone } = this.data;
|
|
wx.request({
|
|
url: baseUrl + '/userInfo/code/pwd',
|
|
method: 'POST',
|
|
header: {
|
|
Authorization: wx.getStorageSync('token')
|
|
},
|
|
data: {
|
|
templateString: phone
|
|
},
|
|
success: res => {
|
|
if (res.data.code === 1) {
|
|
wx.showToast({ title: '验证码已发送' });
|
|
this.startCountdown();
|
|
} else {
|
|
wx.showToast({
|
|
title: '发送失败',
|
|
icon: 'error'
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
// 验证码开始
|
|
startCountdown() {
|
|
this.setData({ sending: true, count: 60 });
|
|
const timer = setInterval(() => {
|
|
let { count } = this.data;
|
|
if (count <= 1) {
|
|
clearInterval(timer);
|
|
this.setData({ sending: false });
|
|
} else {
|
|
this.setData({ count: count - 1 });
|
|
}
|
|
}, 1000);
|
|
},
|
|
|
|
// 通用输入事件处理函数
|
|
onInput(e) {
|
|
const field = e.currentTarget.dataset.field; // 获取字段名
|
|
console.log(field);
|
|
const value = e.detail.value; // 获取输入容
|
|
this.setData({
|
|
[field]: value // 动态更新应字段
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
// 获取用户信息 —— 用于渲染手机号
|
|
wx.request({
|
|
url: baseUrl + '/userInfo/get/jwt',
|
|
method: 'GET',
|
|
header: {
|
|
Authorization: wx.getStorageSync('token')
|
|
},
|
|
success: res => {
|
|
if (res.data.code === 1) {
|
|
this.setData({
|
|
phone: res.data.data.phoneNumber
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |