// pages/meeting/meeting.js import UserApi from '../../assets/js/http/userApi' import { encrypt } from '../../assets/js/jsencrypt/rsa' // var countdown = 60; // 倒计时秒数 Page({ /** * 页面的初始数据 */ data: { form: { oldpassword: '', // 旧密码 password: '', // 新密码 confirmpassword: '', // 确认新密码 // count: 60, // 倒计时秒 rsaPublicKey: '', // 公钥 }, // showGetCaptcha: true }, // // 获取验证码 // getVerCode() { // if (/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(this.data.form.phone)) { // UserApi.sendCode({ // phone: this.data.form.phone // }).then(res => { // // 获取成功,倒计时 start // if (res.success) { // this.countDown() // } else { // wx.showToast({ // title: '获取验证码失败', // icon: 'error', // duration: 2000 // }) // } // }) // } else { // wx.showToast({ // title: '请输入正确的手机号', // icon: 'none', // duration: 2000 // }) // } // }, // 倒计时 // countDown() { // if (countdown === 0) { // this.setData({ // showGetCaptcha: true // }) // countdown = 60; // return; // } else { // this.setData({ // showGetCaptcha: false // }) // countdown--; // this.setData({ // count: countdown // }) // } // setTimeout(() => { // this.countDown() // }, 1000) // // 倒计时 end // }, // 提交 formSubmit(e) { if(!e.detail.value.oldpassword){ this.data.flag = false wx.showToast({ title: '请输入旧密码', icon: 'none' }) return } else { let pattern = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{8,}$/ if(!pattern.test(e.detail.value.oldpassword)){ wx.showToast({ title: '旧密码由8位数字、大小写字母和特殊符号组成!!', icon: 'none' }) this.data.flag = false return } else { this.data.flag = true } } if(!e.detail.value.password){ this.data.flag = false wx.showToast({ title: '请输入新密码', icon: 'none' }) return } else { let pattern = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{8,}$/ if(!pattern.test(e.detail.value.password)){ wx.showToast({ title: '新密码由8位数字、大小写字母和特殊符号组成!!', icon: 'none' }) this.data.flag = false return } else { this.data.flag = true } } if(!e.detail.value.confirmpassword){ this.data.flag = false wx.showToast({ title: '请输入确认新密码', icon: 'none' }) return } else { let pattern = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{8,}$/ if(!pattern.test(e.detail.value.confirmpassword)){ wx.showToast({ title: '密码由8位数字、大小写字母和特殊符号组成!!', icon: 'none' }) this.data.flag = false return } else { this.data.flag = true } } if(e.detail.value.password === e.detail.value.confirmpassword) { this.data.flag = true } else { this.data.flag = false wx.showToast({ title: '密码不一致', icon: 'none' }) return } console.log('form发生了submit事件,携带数据为:', e.detail.value) let params = { password: encrypt(this.data.rsaPublicKey, e.detail.value.oldpassword), newPassword: encrypt(this.data.rsaPublicKey, e.detail.value.password), verifyPassword: encrypt(this.data.rsaPublicKey, e.detail.value.confirmpassword), rsaPublicKey: this.data.rsaPublicKey, } console.log(params) if(this.data.flag){ UserApi.updatePassword(params).then(res => { console.log(res) if(res.success){ wx.showToast({ title: res.result, }) wx.navigateBack() } }).catch(err => { wx.hideToast() }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { const that = this wx.getStorage({ key: 'rsaPublicKey', success (res) { that.setData({ rsaPublicKey: res.data }) }, fail: function(){ // 缓存中没有登录过默认app.json的登录页 } }) } })