index.js 3.5 KB

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