// pages/updatePass/index.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { showModal: false, //用于接口报错时的提醒框 id: wx.getStorageSync('id') ? wx.getStorageSync('id') : '', isSubmitting: false, error: {}, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ id: wx.getStorageSync('id') }) }, //表单校验 validate(data) { var reg = /^[0-9a-zA-Z]{5,16}$/; let error = {} if (!data.password) error.password = '请输入原密码' if (!data.newPassword) error.newPassword = '请输入新密码' if (data.newPassword && !reg.test(data.newPassword)) error.newPassword = '请输入长度为5-16位的密码,允许数字、字母!' if (data.newPassword !== data.reNewPassword) error.reNewPassword = '请重复输入一样的新密码' this.setData({ error }) return !Object.keys(error).length }, //表单提交 handleSubmit({ detail: { value } }) { if (!this.validate(value)) return wx.showLoading({ mask: true }) //delete value.reNewPassword app.request.POST({ url: app.API.updatePwd, params: value, page: this, isLoadingTxt: '修改中...', isSubmitting: true, successFun: true }).then(res => { wx.showToast({ title: '修改成功', icon: 'success', duration: 2000, mask:true, complete: function () { setTimeout(function () { wx.clearStorageSync() // wx.removeStorageSync('loginStatus'); // wx.removeStorageSync('Authorization'); wx.redirectTo({ url: '/pages/login/index', }) }, 2000) //延迟时间 } }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { } })