editPwd.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //index.js
  2. import WxValidate from '../../utils/wxValidate';
  3. //获取应用实例
  4. const app = getApp();
  5. Page({
  6. data: {
  7. form: {}
  8. },
  9. initValidate() {
  10. const rules = {
  11. phone: {
  12. required: true,
  13. },
  14. oldPwd: {
  15. required: true,
  16. },
  17. newPwd: {
  18. required: true,
  19. },
  20. isnewPwd: {
  21. required: false,
  22. },
  23. }
  24. // 验证字段的提示信息,若不传则调用默认的信息
  25. const messages = {
  26. phone: {
  27. required: '请输入手机号',
  28. },
  29. oldPwd: {
  30. required: '请输入原密码',
  31. },
  32. newPwd: {
  33. required: '请输入新密码',
  34. },
  35. isnewPwd: {
  36. required: '请输入确认密码'
  37. }
  38. };
  39. this.WxValidate = new WxValidate(rules, messages)
  40. },
  41. //事件处理函数
  42. formSubmit: function (e) {
  43. const params = e.detail.value;
  44. if (!this.WxValidate.checkForm(params)) {
  45. const error = this.WxValidate.errorList[0];
  46. wx.showToast({
  47. title: error.msg,
  48. icon: 'none',
  49. duration: 2000
  50. })
  51. return false
  52. } else {
  53. // 判断新密码,确认新密码是否一致
  54. if (params.newPwd === params.isnewPwd) {
  55. console.log(params);
  56. } else {
  57. wx.showToast({
  58. title: '新密码与确认密码不一致,请重新输入',
  59. icon: 'none',
  60. duration: 2000
  61. })
  62. }
  63. }
  64. },
  65. onLoad: function (options) {
  66. this.initValidate()//验证规则函数
  67. },
  68. })