index.js 2.3 KB

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