index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // pages/updatePass/index.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. showModal: false, //用于接口报错时的提醒框
  9. id: wx.getStorageSync('id') ? wx.getStorageSync('id') : '',
  10. isSubmitting: false,
  11. error: {},
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. this.setData({
  18. id: wx.getStorageSync('id')
  19. })
  20. },
  21. //表单校验
  22. validate(data) {
  23. var reg = /^[0-9a-zA-Z]{5,16}$/;
  24. let error = {}
  25. if (!data.password) error.password = '请输入原密码'
  26. if (!data.newPassword) error.newPassword = '请输入新密码'
  27. if (data.newPassword && !reg.test(data.newPassword)) error.newPassword = '请输入长度为5-16位的密码,允许数字、字母!'
  28. if (data.newPassword !== data.reNewPassword) error.reNewPassword = '请重复输入一样的新密码'
  29. this.setData({
  30. error
  31. })
  32. return !Object.keys(error).length
  33. },
  34. //表单提交
  35. handleSubmit({ detail: { value } }) {
  36. if (!this.validate(value)) return
  37. wx.showLoading({
  38. mask: true
  39. })
  40. //delete value.reNewPassword
  41. app.request.POST({
  42. url: app.API.updatePwd,
  43. params: value,
  44. page: this,
  45. isLoadingTxt: '修改中...',
  46. isSubmitting: true,
  47. successFun: true
  48. }).then(res => {
  49. wx.showToast({
  50. title: '修改成功',
  51. icon: 'success',
  52. duration: 2000,
  53. mask:true,
  54. complete: function () {
  55. setTimeout(function () {
  56. wx.clearStorageSync()
  57. // wx.removeStorageSync('loginStatus');
  58. // wx.removeStorageSync('Authorization');
  59. wx.redirectTo({
  60. url: '/pages/login/index',
  61. })
  62. }, 2000) //延迟时间
  63. }
  64. })
  65. })
  66. },
  67. /**
  68. * 生命周期函数--监听页面初次渲染完成
  69. */
  70. onReady: function () {
  71. }
  72. })