index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. form: {}
  13. },
  14. initValidate() {
  15. const rules = { password: { required: true, } }
  16. // 验证字段的提示信息,若不传则调用默认的信息
  17. const messages = { password: { required: '请输入新密码', } };
  18. this.WxValidate = new WxValidate(rules, messages)
  19. },
  20. back: function () {
  21. wx.navigateBack({ url: '/pages/home/index' })
  22. },
  23. // 取消修改
  24. onReset: function () {
  25. this.back()
  26. },
  27. // 提交修改
  28. onSubmit: function (e) {
  29. const params = e.detail.value;
  30. if (!this.WxValidate.checkForm(params)) {
  31. const error = this.WxValidate.errorList[0];
  32. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  33. return false
  34. } else {
  35. console.log(params);
  36. // wx.getStorage({
  37. // key: 'user',
  38. // success: res => {
  39. // if (res.data) {
  40. // wx.request({
  41. // url: app.globalData.publicUrl + `/api/hc/user/password`,
  42. // method: "post",
  43. // data: { ...params, id: res.data.id },
  44. // header: {},
  45. // success: (res) => {
  46. // if (res.data.errcode == '0') {
  47. // wx.showToast({ title: `修改密码成功`, icon: 'success', duration: 2000 });
  48. // wx.clearStorage({
  49. // key: 'toekn',
  50. // success: res => { wx.redirectTo({ url: '/pages/login/index', }) }
  51. // })
  52. // } else {
  53. // wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  54. // }
  55. // },
  56. // })
  57. // }
  58. // }
  59. // })
  60. }
  61. },
  62. /**
  63. * 生命周期函数--监听页面加载
  64. */
  65. onLoad: function (options) {
  66. //验证规则函数
  67. this.initValidate();
  68. // 监听用户是否登录
  69. this.watchLogin();
  70. // 计算高度
  71. this.searchHeight()
  72. },
  73. // 监听用户是否登录
  74. watchLogin: function () {
  75. // wx.getStorage({
  76. // key: 'user',
  77. // success: res => {
  78. // if (res.data) {
  79. // // 查询菜单
  80. // if (res.data) this.searchRouter(res.data);
  81. // res.data.type = type.find((i) => i.value == res.data.type).label;
  82. // if (res.data) this.setData({ userInfo: res.data });
  83. // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
  84. // } else {
  85. // wx.redirectTo({ url: '/pages/login/index', })
  86. // }
  87. // }
  88. // })
  89. },
  90. // 计算高度
  91. searchHeight: function () {
  92. let frameStyle = this.data.frameStyle;
  93. let client = app.globalData.client;
  94. let infoHeight = client.windowHeight;
  95. // 是否去掉状态栏
  96. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  97. // 是否减去底部菜单
  98. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  99. if (infoHeight) this.setData({ infoHeight: infoHeight })
  100. },
  101. /**
  102. * 生命周期函数--监听页面初次渲染完成
  103. */
  104. onReady: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面显示
  108. */
  109. onShow: function () {
  110. },
  111. /**
  112. * 生命周期函数--监听页面隐藏
  113. */
  114. onHide: function () {
  115. },
  116. /**
  117. * 生命周期函数--监听页面卸载
  118. */
  119. onUnload: function () {
  120. },
  121. /**
  122. * 页面相关事件处理函数--监听用户下拉动作
  123. */
  124. onPullDownRefresh: function () {
  125. },
  126. /**
  127. * 页面上拉触底事件的处理函数
  128. */
  129. onReachBottom: function () {
  130. },
  131. /**
  132. * 用户点击右上角分享
  133. */
  134. onShareAppMessage: function () {
  135. }
  136. })