index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. wx.showToast({ title: `修改密码成功`, icon: 'success', duration: 2000 });
  35. wx.clearStorage({
  36. key: 'toekn',
  37. success: res => { wx.redirectTo({ url: '/pages/login/index', }) }
  38. })
  39. }
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. //验证规则函数
  46. this.initValidate()
  47. // 计算高度
  48. this.searchHeight()
  49. },
  50. // 计算高度
  51. searchHeight: function () {
  52. let frameStyle = this.data.frameStyle;
  53. let client = app.globalData.client;
  54. // 减去状态栏
  55. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  56. // 是否减去底部菜单
  57. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  58. if (infoHeight) this.setData({ infoHeight: infoHeight })
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面显示
  67. */
  68. onShow: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面隐藏
  72. */
  73. onHide: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面卸载
  77. */
  78. onUnload: function () {
  79. },
  80. /**
  81. * 页面相关事件处理函数--监听用户下拉动作
  82. */
  83. onPullDownRefresh: function () {
  84. },
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. onReachBottom: function () {
  89. },
  90. /**
  91. * 用户点击右上角分享
  92. */
  93. onShareAppMessage: function () {
  94. }
  95. })