index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // pages/mine/personage/index.js
  2. const _my = require("../../../__antmove/api/index.js")(my);
  3. const wx = _my; // pages/home/home.js
  4. import {
  5. updateUserPassword
  6. } from '../../../utils/api/api.js'
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. password: '',
  13. open: false, //默认不显示密码
  14. userInfo: null,
  15. },
  16. getVal(e) {
  17. let type = e.target.dataset.type
  18. this.setData({
  19. [type]: e.detail.value
  20. });
  21. },
  22. switch() {
  23. this.setData({
  24. open: !this.data.open
  25. })
  26. },
  27. submit() {
  28. if (!this.data.password) {
  29. wx.showToast({
  30. title: '请填写密码',
  31. icon: 'none'
  32. })
  33. return
  34. }
  35. if (!/^(((?=.*\d)(?=.*[a-z])(?=.*[A-Z]))|((?=.*\d)(?=.*[a-z])(?=.*[~!@#$%^&*]))|((?=.*\d)(?=.*[A-Z])(?=.*[~!@#$%^&*]))|((?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^&*]))|((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^&*]))).{10,32}$/.test(
  36. this.data.password
  37. )) {
  38. wx.showToast({
  39. title: '密码格式有误',
  40. icon: 'none'
  41. })
  42. return
  43. }
  44. const params = {
  45. newPassword: this.data.password
  46. }
  47. updateUserPassword(params).then(res => {
  48. wx.showToast({
  49. title: '修改成功,即将重新登录',
  50. icon: 'none',
  51. duration: 2000,
  52. mask: true,
  53. success: function () {
  54. setTimeout(function () {
  55. wx.removeStorageSync('userInfo')
  56. wx.navigateTo({
  57. url: '/pages/login/index',
  58. })
  59. }, 800)
  60. }
  61. })
  62. })
  63. },
  64. /**
  65. * 生命周期函数--监听页面加载
  66. */
  67. onLoad(options) { },
  68. /**
  69. * 生命周期函数--监听页面初次渲染完成
  70. */
  71. onReady() { },
  72. /**
  73. * 生命周期函数--监听页面显示
  74. */
  75. onShow() {
  76. const userInfo = wx.getStorageSync('userInfo')
  77. this.setData({
  78. userInfo
  79. })
  80. },
  81. /**
  82. * 生命周期函数--监听页面隐藏
  83. */
  84. onHide() { },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload() { },
  89. /**
  90. * 页面相关事件处理函数--监听用户下拉动作
  91. */
  92. onPullDownRefresh() { },
  93. /**
  94. * 页面上拉触底事件的处理函数
  95. */
  96. onReachBottom() { },
  97. /**
  98. * 用户点击右上角分享
  99. */
  100. onShareAppMessage() { },
  101. antmoveAction: function () {
  102. //执行时动态赋值,请勿删除
  103. }
  104. });