// subpages/settings/pages/changePassword/changePassword.js import {encryptedData} from "../../../../utils/index" import api from "../../../../utils/api" Page({ /** * 页面的初始数据 */ data: { pubKey:'', oldPassword:"", newPassword:"", confirmPassword:"" }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getPubKey() }, getPubKey(){ api.getPubKey().then(res=>{ this.setData({ pubKey:res.data }) }).catch(err=>{ }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, changeOldPassword(e){ this.setData({ oldPassword:e.detail.value }) }, changeNewPassword(e){ this.setData({ newPassword:e.detail.value }) }, changeConfirmPassword(e){ this.setData({ confirmPassword:e.detail.value }) }, validateComplexity(pwd) { let regex = new RegExp("(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z]).{8,20}"); if (!regex.test(pwd)) return false; return true; }, handelSubmit(e){ if(!this.data.oldPassword){ wx.showToast({ title: '原密码不能为空', icon:"none" }) return } if(!this.data.newPassword){ wx.showToast({ title: '新密码不能为空', icon:"none" }) return } if(!this.data.confirmPassword){ wx.showToast({ title: '确认密码不能为空', icon:"none" }) return } if(!this.data.confirmPassword === this.data.newPassword){ wx.showToast({ title: '两次密码不一致', icon:"none" }) return } if (!this.validateComplexity(this.data.newPassword)) { wx.showToast({ title: '密码必须8-20个字符,而且同时包含大小写字母和数字', icon:"none", duration:5000 }) return }; let obj={ oldPassword: encryptedData(this.data.pubKey, this.data.oldPassword), newPassword: encryptedData(this.data.pubKey, this.data.newPassword), confirmNewPassword: encryptedData(this.data.pubKey,this.data.confirmPassword), } api.changePassword(obj).then(res=>{ console.log(res); if(res.code == 0){ wx.showToast({ title: '修改成功', duration:3000, success:function(){ setTimeout(()=>{ wx.reLaunch({ url: '/pages/login/login', }) },3000) } }) } }).catch(err=>{ console.log(err); }) } })