小程序修改密码
This commit is contained in:
105
weixin-miniprogram/pages/person/updpwd.js
Normal file
105
weixin-miniprogram/pages/person/updpwd.js
Normal file
@@ -0,0 +1,105 @@
|
||||
// pages/person/updpwd.js
|
||||
// 获取应用实例
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
waiting: false,
|
||||
|
||||
oldpwd: '', // 旧密码
|
||||
newpwd: '', // 新密码
|
||||
newpwd2: '' // 确认新密码
|
||||
},
|
||||
// 表单提交事件
|
||||
submitForm(e) {
|
||||
// 获取表单数据
|
||||
let { oldpwd, newpwd, newpwd2 } = e.detail.value
|
||||
// 验证表单数据
|
||||
if (!newpwd || !newpwd2) {
|
||||
// 新密码不能为空
|
||||
wx.showToast({
|
||||
title: '新密码不能为空',
|
||||
icon: 'none'
|
||||
})
|
||||
} else if (newpwd !== newpwd2) {
|
||||
// 两次密码不一致
|
||||
wx.showToast({
|
||||
title: '两次密码不一致',
|
||||
icon: 'none'
|
||||
})
|
||||
} else {
|
||||
let userInfo = wx.getStorageSync("userInfo")
|
||||
if (!userInfo || !userInfo.id) {
|
||||
console.log("userInfo", userInfo)
|
||||
wx.showModal({
|
||||
title: '登陆失效',
|
||||
content: '请重新登录',
|
||||
showCancel: false,
|
||||
complete: (res) => {
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
}
|
||||
// 调用后台接口修改密码
|
||||
this.setData({
|
||||
waiting: true,
|
||||
})
|
||||
wx.showNavigationBarLoading()
|
||||
var that = this
|
||||
wx.request({
|
||||
url: app.globalData.baseUrl + '/user/updatePwd', // 后台接口地址
|
||||
method: 'POST',
|
||||
data: {
|
||||
userId: userInfo.id,
|
||||
oldpwd, // 旧密码
|
||||
newpwd // 新密码
|
||||
},
|
||||
header: {
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
success(res) {
|
||||
wx.hideNavigationBarLoading()
|
||||
that.setData({
|
||||
waiting: false,
|
||||
})
|
||||
console.log("res.data.success", res.data.success)
|
||||
// 请求成功
|
||||
if (res.data.success) {
|
||||
// 修改成功
|
||||
wx.showModal({
|
||||
title: '修改成功',
|
||||
content: '密码修改成功',
|
||||
showCancel: false,
|
||||
complete: (res) => {
|
||||
// 返回上一页
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// 修改失败
|
||||
// wx.showToast({
|
||||
// title: res.data.msg,
|
||||
// icon: 'none'
|
||||
// })
|
||||
wx.showModal({
|
||||
title: '修改失败',
|
||||
content: res.data.msg,
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
wx.hideNavigationBarLoading()
|
||||
that.setData({
|
||||
waiting: false,
|
||||
})
|
||||
// 请求失败
|
||||
wx.showToast({
|
||||
title: '网络异常,请稍后重试',
|
||||
icon: 'none'
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user