Files
novel_frontend_RcKtFezyRAZX/wechat/pages/change-password/change-password.js
mzltMpfqGS e4a087e67e init
2026-04-15 19:45:16 +08:00

89 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/change-password/change-password.js
// 修改密码逻辑处理
const app = getApp()
const api = require('../../services/api')
Page({
data: {
oldPassword: '',
newPassword: '',
confirmPassword: '',
loading: false
},
onLoad() {
this.checkLogin()
},
checkLogin() {
const userInfo = wx.getStorageSync('userInfo')
if (!userInfo) {
wx.redirectTo({ url: '/pages/login/login' })
}
},
onOldPasswordInput(e) {
this.setData({ oldPassword: e.detail.value })
},
onNewPasswordInput(e) {
this.setData({ newPassword: e.detail.value })
},
onConfirmPasswordInput(e) {
this.setData({ confirmPassword: e.detail.value })
},
doChangePassword() {
const { oldPassword, newPassword, confirmPassword } = this.data
if (!oldPassword.trim()) {
wx.showToast({ title: '请输入原密码', icon: 'none' })
return
}
if (!newPassword.trim()) {
wx.showToast({ title: '请输入新密码', icon: 'none' })
return
}
if (newPassword.length < 6) {
wx.showToast({ title: '新密码至少6位', icon: 'none' })
return
}
if (newPassword !== confirmPassword) {
wx.showToast({ title: '两次密码不一致', icon: 'none' })
return
}
this.setData({ loading: true })
api.changePassword({
oldPassword: oldPassword.trim(),
newPassword: newPassword.trim()
}).then(res => {
this.setData({ loading: false })
if (res.code === 200) {
wx.showToast({ title: '密码修改成功', icon: 'success' })
setTimeout(() => {
app.clearUserInfo()
wx.redirectTo({ url: '/pages/login/login' })
}, 1500)
} else {
wx.showToast({ title: res.message || '修改失败', icon: 'none' })
}
}).catch(() => {
this.setData({ loading: false })
wx.showToast({ title: '修改失败', icon: 'none' })
})
}
})
/**
* @联系作者:16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
*/