Files
income_payments_applet/pages/upDateInfo/upDateInfo.js
T

283 lines
7.6 KiB
JavaScript

// pages/meeting/meeting.js
import UserApi from '../../assets/js/http/userApi'
import { encrypt } from '../../assets/js/jsencrypt/rsa'
// var countdown = 60; // 倒计时秒数
Page({
/**
* 页面的初始数据
*/
data: {
oldpassword: '', // 旧密码
password: '', // 新密码
confirmpassword: '', // 确认新密码
rsaPublicKey: '', // 公钥
valsOld: [],
valsNew: [],
valsVerify: [],
showOld: true,
show: true, // 默认显示的是闭眼睛
showVerify: true,
},
showPasswordOld(){
this.setData({
showOld: !this.data.showOld
})
},
showPassword(){
this.setData({
show: !this.data.show
})
},
showPasswordVerify(){
this.setData({
'showVerify': !this.data.showVerify
})
},
clearrepeatvalOld(){
this.data.valsOld = []
this.setData({
oldpassword: ''
})
return
},
clearrepeatval(){
this.data.valsNew = []
this.setData({
password: ''
})
return
},
clearrepeatvalVerify(){
this.data.valsVerify = []
this.setData({
confirmpassword: ''
})
return
},
// 旧密码的输入
handleOldPasswordInput(e) { //禁止输入中复制粘贴
// 获取当前数组
const vals = this.data.valsOld
// 获取当前输入的值
const currentval = e.detail.value.replace(/\s+/g, "")
if(currentval){ // 如果值存在追加到vals中
vals.push(currentval)
}
if(vals.length == 1 ){
const v = vals[vals.length-1].length
if(v > 1){ // 如果第一个的长度就大于1 说明是粘贴过来的
this.clearrepeatvalOld()
}
}
if(vals.length > 1){
// 如果值数组大于1 就获取最后一个值长度和倒数第二个值长度
// 比较值长度差如果大于1 则粘贴的
const lastv = vals[vals.length-1].length // 获取最后一个值的长度
const secondv = vals[vals.length-2].length // 获取倒数第二个值得长度
const dis = lastv - secondv
if(dis>1){
this.clearrepeatvalOld()
}
}
// 最后赋值
this.data['oldpassword'] = currentval
},
// 新密码的输入
handlePasswordInput(e) { //禁止输入中复制粘贴
// 获取当前数组
const vals = this.data.valsNew
// 获取当前输入的值
const currentval = e.detail.value.replace(/\s+/g, "")
if(currentval){ // 如果值存在追加到vals中
vals.push(currentval)
}
if(vals.length == 1 ){
const v = vals[vals.length-1].length
if(v > 1){ // 如果第一个的长度就大于1 说明是粘贴过来的
this.clearrepeatval()
}
}
if(vals.length > 1){
// 如果值数组大于1 就获取最后一个值长度和倒数第二个值长度
// 比较值长度差如果大于1 则粘贴的
const lastv = vals[vals.length-1].length // 获取最后一个值的长度
const secondv = vals[vals.length-2].length // 获取倒数第二个值得长度
const dis = lastv - secondv
if(dis>1){
this.clearrepeatval()
}
}
// 最后赋值
this.data['password'] = currentval
},
// 确认新密码的输入
handleVerifyPasswordInput(e) { //禁止输入中复制粘贴
// 获取当前数组
const vals = this.data.valsVerify
// 获取当前输入的值
const currentval = e.detail.value.replace(/\s+/g, "")
if(currentval){ // 如果值存在追加到vals中
vals.push(currentval)
}
if(vals.length == 1 ){
const v = vals[vals.length-1].length
if(v > 1){ // 如果第一个的长度就大于1 说明是粘贴过来的
this.clearrepeatvalVerify()
}
}
if(vals.length > 1){
// 如果值数组大于1 就获取最后一个值长度和倒数第二个值长度
// 比较值长度差如果大于1 则粘贴的
const lastv = vals[vals.length-1].length // 获取最后一个值的长度
const secondv = vals[vals.length-2].length // 获取倒数第二个值得长度
const dis = lastv - secondv
if(dis>1){
this.clearrepeatvalVerify()
}
}
// 最后赋值
this.data['form.confirmpassword'] = currentval
},
// 提交
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,
icon: 'none',
duration: 2000
})
setTimeout(() => {
wx.navigateBack()
}, 2000);
}else{
wx.showToast({
title: res.message,
icon: 'none',
duration: 2000
})
}
}).catch(err=>{
wx.showToast({
title: err.message,
icon: 'none',
duration: 2000
})
})
}
},
/**
* 生命周期函数--监听页面加载
*/
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的登录页
}
})
}
})