From 874a5a8f1353666c10a2aa0b6963873cecff5bab Mon Sep 17 00:00:00 2001 From: TM <923727421@qq.com> Date: Tue, 15 Dec 2020 17:08:28 +0800 Subject: [PATCH] 修改头像 --- pages/changePassword/changePassword.js | 104 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 75 insertions(+), 29 deletions(-) diff --git a/pages/changePassword/changePassword.js b/pages/changePassword/changePassword.js index dfd94ab..0ceeacc 100644 --- a/pages/changePassword/changePassword.js +++ b/pages/changePassword/changePassword.js @@ -1,58 +1,104 @@ let $api = require('../../utils/ajaxFn.js') let md5 = require('../../utils/md5.js') +let validator = require('../../utils/validator.js') const app = getApp() Page({ data: { - userStyle:{}, - newTwo:"", - info:{ - newPwd: "", - oldPwd: "" - } + userStyle: {}, + newTwo: "", + info: { + newPwd: "", + oldPwd: "" + }, + userInfo: {} }, onLoad() { this.setData({ - userStyle:app.userStyle + userStyle: app.userStyle, + userInfo: app.userInfo }) }, - getOld(e){ + getOld(e) { this.setData({ - 'info.oldPwd':md5.hex_md5(e.detail.value) + 'info.oldPwd': e.detail.value }) }, - getNem(e){ + getNem(e) { this.setData({ - 'info.newPwd':md5.hex_md5(e.detail.value) + 'info.newPwd': e.detail.value }) }, - getNemTwo(e){ - console.log(3) + getNemTwo(e) { this.setData({ - newTwo: md5.hex_md5(e.detail.value) + newTwo: e.detail.value }) }, - save(){ - console.log(this.data.newTwo,this.data.info) - if(this.data.newTwo != this.data.info.newPwd){ + save() { + let self = this + console.log(this.data.userInfo.mblNo, this.data.newTwo, this.data.info) + if (validator.checkValEmpty(this.data.info.oldPwd)) { + my.showToast({ + content: '请输入原密码', + duration: 2000, + }); + return + } + if (validator.checkValEmpty(this.data.info.newPwd)) { + my.showToast({ + content: '请输入新密码', + duration: 2000, + }); + return + } + if (this.data.newTwo != this.data.info.newPwd) { my.showToast({ content: '两次新密码不一致,请确认', duration: 2000, }); return } - $api.ajax( - '/sib/user/updatePwd', - 'POST', - (res)=>{ + let p = new Promise(function (re, rej) { + $api.ajax( + '/sib/user/updatePwd', + 'POST', + (res) => { + my.showToast({ + content:'修改成功', + duration:3000, + success:()=>{ + re() + } + }) + }, + (err) => { - }, - (err)=>{ + }, + true, + { + newPwd: md5.hex_md5(self.data.userInfo.mblNo + self.data.info.newPwd), + oldPwd: md5.hex_md5(self.data.userInfo.mblNo + self.data.info.oldPwd) + } + ) - }, - true, - { - ...this.data.info - } - ) + }) + p.then(() => { + $api.ajax( + '/sib/xcx/login/logout', + 'POST', + res => { + my.removeStorageSync({ + key: 'sessionId', + }); + my.navigateTo({ + url: '/pages/index/index' + }); + }, + err => { + + }, + true + ) + }) + } }); -- Gitblit v1.8.0