index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. // 主体高度
  10. infoHeight: '',
  11. frameStyle: { useTop: true, name: '修改密码', leftArrow: true, useBar: false },
  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. formSubmit: function (e) {
  26. const value = e.detail.value;
  27. var id = this.data.id;
  28. if (!this.WxValidate.checkForm(value)) {
  29. const error = this.WxValidate.errorList[0];
  30. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  31. return false
  32. } else {
  33. wx.request({
  34. url: `${app.globalData.publicUrl}/courtAdmin/api/user/updatePwd/${id}`,
  35. method: "post",
  36. data: value,
  37. header: {},
  38. success: res => {
  39. wx.showModal({
  40. title: '是否修改密码',
  41. success(res) {
  42. if (res.confirm) {
  43. wx.removeStorage({
  44. key: 'token',
  45. success(res) {
  46. return wx.redirectTo({ url: '/pages/index/index', })
  47. }
  48. })
  49. } else if (res.cancel) {
  50. }
  51. }
  52. })
  53. },
  54. })
  55. }
  56. },
  57. /**
  58. * 生命周期函数--监听页面加载
  59. */
  60. onLoad: function (options) {
  61. // 计算高度
  62. this.searchHeight();
  63. // 监听用户是否登录
  64. this.watchLogin();
  65. //验证规则函数
  66. this.initValidate();
  67. },
  68. // 监听用户是否登录
  69. watchLogin: function () {
  70. const that = this;
  71. wx.getStorage({
  72. key: 'token',
  73. success: res => {
  74. that.setData({ id: res.data.id })
  75. wx.request({
  76. url: `${app.globalData.publicUrl}/courtAdmin/api/user/${res.data.id}`,
  77. method: "get",
  78. data: {},
  79. header: {},
  80. success: res => {
  81. that.setData({ form: res.data.data })
  82. },
  83. error: err => {
  84. }
  85. })
  86. },
  87. fail: res => {
  88. wx.redirectTo({ url: '/pages/login/index', })
  89. }
  90. })
  91. },
  92. // 计算高度
  93. searchHeight: function () {
  94. let frameStyle = this.data.frameStyle;
  95. let client = app.globalData.client;
  96. let infoHeight = client.windowHeight;
  97. // 是否去掉状态栏
  98. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  99. // 是否减去底部菜单
  100. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  101. if (infoHeight) this.setData({ infoHeight: infoHeight })
  102. },
  103. /**
  104. * 生命周期函数--监听页面初次渲染完成
  105. */
  106. onReady: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面显示
  110. */
  111. onShow: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面隐藏
  115. */
  116. onHide: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面卸载
  120. */
  121. onUnload: function () {
  122. },
  123. /**
  124. * 页面相关事件处理函数--监听用户下拉动作
  125. */
  126. onPullDownRefresh: function () {
  127. },
  128. /**
  129. * 页面上拉触底事件的处理函数
  130. */
  131. onReachBottom: function () {
  132. },
  133. /**
  134. * 用户点击右上角分享
  135. */
  136. onShareAppMessage: function () {
  137. }
  138. })