index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '修改密码', leftArrow: true, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. },
  13. initValidate() {
  14. const rules = { oldPassword: { required: true, }, newPassword: { required: true, }, }
  15. // 验证字段的提示信息,若不传则调用默认的信息
  16. const messages = { oldPassword: { required: '请输入旧密码', }, newPassword: { required: '请输入新密码', } };
  17. this.WxValidate = new WxValidate(rules, messages)
  18. },
  19. back: function () {
  20. wx.navigateBack({ url: '/pages/home/index' })
  21. },
  22. // 取消修改
  23. onReset: function () {
  24. this.back()
  25. },
  26. // 提交修改
  27. onSubmit: function (e) {
  28. const params = e.detail.value;
  29. if (!this.WxValidate.checkForm(params)) {
  30. const error = this.WxValidate.errorList[0];
  31. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  32. return false
  33. } else {
  34. console.log(params);
  35. wx.showToast({ title: `修改密码成功`, icon: 'success', duration: 2000 })
  36. }
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. //验证规则函数
  43. this.initValidate()
  44. // 计算高度
  45. this.searchHeight()
  46. },
  47. // 计算高度
  48. searchHeight: function () {
  49. let frameStyle = this.data.frameStyle;
  50. let client = app.globalData.client;
  51. // 减去状态栏
  52. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  53. // 是否减去底部菜单
  54. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  55. if (infoHeight) this.setData({ infoHeight: infoHeight })
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面隐藏
  69. */
  70. onHide: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面卸载
  74. */
  75. onUnload: function () {
  76. },
  77. /**
  78. * 页面相关事件处理函数--监听用户下拉动作
  79. */
  80. onPullDownRefresh: function () {
  81. },
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom: function () {
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage: function () {
  91. }
  92. })