jhwxapp/miniprogram/pages/components/user-infos/index.js

216 lines
4.5 KiB
JavaScript
Raw Normal View History

2024-03-19 23:25:38 +08:00
import {
removeToken
} from '../../../utils/auth'
2024-04-08 00:58:58 +08:00
import {
2024-04-21 13:08:16 +08:00
loginOut,
2024-05-03 10:37:27 +08:00
updatePwd,
2024-04-21 13:08:16 +08:00
findOpenUserMsgId
2024-04-08 00:58:58 +08:00
} from '../../../api/login'
2024-04-21 13:08:16 +08:00
2024-03-19 23:25:38 +08:00
const app = getApp()
Component({
/**数据监听 */
observers: {},
/**
* 组件的初始数据
*/
data: {
show: false,
userData: {},
resPas: false,
oldPsw: '',
newPsw: '',
password: '',
showOldPass: true,
showNewPass: true,
showPassWord: true,
2024-04-08 00:58:58 +08:00
binding: false,
2024-04-14 21:28:11 +08:00
msgOpenId: "",
2024-03-19 23:25:38 +08:00
},
created() {
let that = this;
//获取缓存数据
wx.getStorage({
key: 'userinfo',
success: function (res) {
that.setData({
userData: res.data,
loginName: res.data.loginName,
2024-04-14 21:28:11 +08:00
msgOpenId: res.data.msgOpenId || "",
2024-03-19 23:25:38 +08:00
})
}
})
},
/**
* 组件的方法列表
*/
methods: {
2024-04-14 21:28:11 +08:00
loadUserInfo() {
let that = this;
//获取缓存数据
wx.getStorage({
key: 'userinfo',
success: function (res) {
2024-04-21 13:08:16 +08:00
findOpenUserMsgId(res.data.openId).then(vo =>{
if(vo.code==200 && vo.data){
res.data.msgOpenId=vo.data.msgOpenId;
wx.setStorage({
key: 'userinfo',
data: res.data
});
that.setData({
show:true,
userData: res.data,
loginName: res.data.loginName,
msgOpenId: res.data.msgOpenId || "",
})
}
});
2024-04-14 21:28:11 +08:00
}
})
},
2024-04-21 13:08:16 +08:00
2024-03-19 23:25:38 +08:00
showPopup() {
this.setData({
show: true
});
},
/**
* 关闭用户详情
*/
closePopup() {
this.setData({
show: false
});
},
//修改密码
resPassword: function () {
this.setData({
resPas: true
});
},
2024-04-08 00:58:58 +08:00
//绑定公众号
binding: function () {
app.initWxAuth();
},
2024-03-19 23:25:38 +08:00
/**
* 修改密码返回
*/
closeResPas: function () {
this.setData({
resPas: false
});
},
2024-04-08 00:58:58 +08:00
/**
* 修改密码返回
*/
closeBinding: function () {
this.setData({
binding: false
});
},
bindingBuild: function () {
wx.previewImage({
2024-04-14 21:28:11 +08:00
urls: "https://szgcwx.jhncidg.com/staticFiles/qrv1.jpg".split(","),
2024-04-08 00:58:58 +08:00
current: 0
})
},
2024-03-19 23:25:38 +08:00
//退出登录
loginOut: function () {
2024-04-08 00:58:58 +08:00
loginOut({}).then(res => {
removeToken();
});
2024-03-19 23:25:38 +08:00
wx.clearStorageSync();
wx.setStorageSync('isReload', "1")
wx.redirectTo({
url: '../login/index',
})
},
seeTap1() {
let that = this;
that.setData({
// 切换图标
showOldPass: !that.data.showOldPass
})
},
seeTap2() {
let that = this;
that.setData({
// 切换图标
showNewPass: !that.data.showNewPass
})
},
seeTap3() {
let that = this;
that.setData({
// 切换图标
showPassWord: !that.data.showPassWord
})
if (that.data.newPsw != '' && that.data.newPsw != that.data.password) {
app.toast("两次密码输入不一致!");
}
},
/**
* 添加预警信息
*/
submit: function () {
var that = this;
if (that.data.oldPsw == '') {
app.toast("请输入旧密码!");
return;
}
if (that.data.password == '') {
app.toast("请确认新密码!");
return;
}
if (that.data.newPsw != '' && that.data.newPsw != that.data.password) {
app.toast("两次密码输入不一致!");
return;
}
if (that.data.oldPsw.length < 6) {
app.toast("请输入旧密码长度 [6-20]位字符!");
return;
}
if (that.data.newPsw.length < 6) {
app.toast("请输入新密码长度 [6-20]位字符!");
return;
}
if (that.data.password.length < 6) {
app.toast("请输入确认密码长度 [6-20]位字符!");
return;
}
2024-05-03 10:37:27 +08:00
let data = {
loginName: that.data.loginName,
oldPass: that.data.oldPsw,
password: that.data.newPsw,
confPass: that.data.password,
source:"u"
}
updatePwd(data).then(res =>{
if(res.code==200){
app.toast("密码修改成功,请重新登录!",800);
removeToken();
wx.clearStorageSync();
wx.setStorageSync('isReload', "1");
setTimeout(()=>{
2024-03-19 23:25:38 +08:00
wx.redirectTo({
2024-05-03 10:37:27 +08:00
url: '../login/index',
2024-03-19 23:25:38 +08:00
});
2024-05-03 10:37:27 +08:00
},500)
2024-03-19 23:25:38 +08:00
}
2024-05-03 10:37:27 +08:00
});
2024-03-19 23:25:38 +08:00
},
}
})