index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // pages/password/index.js
  2. import http from '../../utils/http'
  3. import api from '../../utils/api'
  4. import util from '../../utils/util'
  5. const app = getApp()
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. old: '',
  12. new: '',
  13. new_confirm: ''
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. },
  20. updateInput: function(e) {
  21. app.updateInput(this, e)
  22. },
  23. save: function(e) {
  24. if(!this.data.old) {
  25. util.error('旧密码必填')
  26. return false
  27. }
  28. if(!this.data.new) {
  29. util.error('新密码必填')
  30. return false
  31. }
  32. if(this.data.new.length < 6) {
  33. util.error('密码至少6位')
  34. return false
  35. }
  36. if(!util.checkPass(this.data.new)) {
  37. util.error('密码必须同时包含数字和字母')
  38. return false
  39. }
  40. if(this.data.new != this.data.new_confirm) {
  41. util.error('两次输入的密码不一致')
  42. return false
  43. }
  44. http({
  45. url: 'users/changePassword',
  46. data: this.data,
  47. success: function(res) {
  48. if(res.code == 0) {
  49. util.success('更改成功')
  50. } else {
  51. util.error(res.msg)
  52. }
  53. }
  54. })
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面显示
  63. */
  64. onShow: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面隐藏
  68. */
  69. onHide: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面卸载
  73. */
  74. onUnload: function () {
  75. },
  76. /**
  77. * 页面相关事件处理函数--监听用户下拉动作
  78. */
  79. onPullDownRefresh: function () {
  80. },
  81. /**
  82. * 页面上拉触底事件的处理函数
  83. */
  84. onReachBottom: function () {
  85. },
  86. /**
  87. * 用户点击右上角分享
  88. */
  89. onShareAppMessage: function () {
  90. }
  91. })