changePwd.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var businessT = require('../../../../../tool/business-tool.js')
  2. var sysT = require('../../../../../tool/sys-tool.js')
  3. var key = require('../../../../../constant/key.js')
  4. var url = require('../../../../../constant/url.js')
  5. var M = require('../../../../../tool/md5.js')
  6. import Net from '../../../../../tool/net.js'
  7. var net = new Net()
  8. var app = getApp()
  9. Page({
  10. data: {
  11. ui: [{ t: '原密码', p: '请输入原密码' }, { t: '新密码', p: '请设置新密码' }, { t: '确认密码', p: '请确认新密码' }]
  12. },
  13. inputAction(e) {
  14. if (e.currentTarget.dataset.index == 0) {
  15. this.setData({
  16. oldPwd: e.detail.value
  17. })
  18. } else if (e.currentTarget.dataset.index == 1) {
  19. this.setData({
  20. newPwd: e.detail.value
  21. })
  22. } else {
  23. this.setData({
  24. surePwd: e.detail.value
  25. })
  26. }
  27. if (this.data.oldPwd && this.data.newPwd && this.data.surePwd) {
  28. this.setData({
  29. canSave: true
  30. })
  31. } else {
  32. this.setData({
  33. canSave: false
  34. })
  35. }
  36. },
  37. btnAction() {
  38. var prePassword = M.md5(this.data.oldPwd)
  39. var password = M.md5(this.data.newPwd)
  40. if (swan.getStorageSync(key.StorageKey.userCode) != prePassword) {
  41. swan.showToast({
  42. title: '原密码不正确',
  43. icon: 'none',
  44. mask: true
  45. });
  46. return
  47. }
  48. if (this.data.newPwd != this.data.surePwd) {
  49. swan.showToast({
  50. title: '新密码和确认密码不一致',
  51. icon: 'none',
  52. mask: true
  53. });
  54. return
  55. }
  56. if (this.data.newPwd.length <6|| this.data.surePwd.length <6) {
  57. swan.showToast({
  58. title: '请输入6位以上的新密码',
  59. icon: 'none',
  60. mask: true
  61. });
  62. return
  63. }
  64. swan.showLoading({
  65. title: '请稍后...',
  66. mask: true,
  67. });
  68. net.connectNeedLogin({
  69. url: url.app_host + url.changePwd,
  70. data: { prePassword, password },
  71. success: (err, res) => {
  72. swan.setStorageSync(key.StorageKey.userCode,password)
  73. swan.hideLoading();
  74. swan.showToast({
  75. title: '修改成功',
  76. icon: 'none',
  77. mask: true
  78. });
  79. swan.navigateBack();
  80. },
  81. fail: (err, res) => {
  82. swan.hideLoading();
  83. console.log(err)
  84. businessT.showFailTips(err)
  85. }
  86. }, false)
  87. },
  88. onLoad: function () {
  89. // 监听页面加载的生命周期函数
  90. },
  91. onReady: function () {
  92. // 监听页面初次渲染完成的生命周期函数
  93. },
  94. onShow: function () {
  95. // 监听页面显示的生命周期函数
  96. },
  97. onHide: function () {
  98. // 监听页面隐藏的生命周期函数
  99. },
  100. onUnload: function () {
  101. // 监听页面卸载的生命周期函数
  102. },
  103. onPullDownRefresh: function () {
  104. // 监听用户下拉动作
  105. },
  106. onReachBottom: function () {
  107. // 页面上拉触底事件的处理函数
  108. },
  109. onShareAppMessage: function () {
  110. // 用户点击右上角转发
  111. }
  112. });