194 lines
4.6 KiB
JavaScript
194 lines
4.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: {
|
|
form: {
|
|
oldpassword: '', // 旧密码
|
|
password: '', // 新密码
|
|
confirmpassword: '', // 确认新密码
|
|
rsaPublicKey: '', // 公钥
|
|
},
|
|
showOld: true,
|
|
typeOld: 'password',
|
|
show: true, // 默认显示的是闭眼睛
|
|
showVerify: true,
|
|
type: 'password',
|
|
typeVerify: 'password'
|
|
},
|
|
showPasswordOld(){
|
|
if(this.data.showOld){ // 显示睁开眼睛的时候 type="text"
|
|
this.setData({
|
|
typeOld: 'text',
|
|
showOld: false
|
|
})
|
|
}else{
|
|
this.setData({
|
|
typeOld: 'password',
|
|
showOld: true
|
|
})
|
|
}
|
|
},
|
|
showPassword(){
|
|
if(this.data.show){ // 显示睁开眼睛的时候 type="text"
|
|
this.setData({
|
|
type: 'text',
|
|
show: false
|
|
})
|
|
}else{
|
|
this.setData({
|
|
type: 'password',
|
|
show: true
|
|
})
|
|
}
|
|
},
|
|
showPasswordVerify(){
|
|
if(this.data.showVerify){ // 显示睁开眼睛的时候 type="text"
|
|
this.setData({
|
|
typeVerify: 'text',
|
|
showVerify: false
|
|
})
|
|
}else{
|
|
this.setData({
|
|
typeVerify: 'password',
|
|
showVerify: true
|
|
})
|
|
}
|
|
},
|
|
// 提交
|
|
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);
|
|
}
|
|
}).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的登录页
|
|
}
|
|
})
|
|
}
|
|
})
|