change-password.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!-- 修改密码 -->
  2. <template>
  3. <view class="wrap">
  4. <view class="module">
  5. <view class="row-between">
  6. <input type="text" v-model="params.phone" class="input" placeholder="请输入手机号" placeholder-class="placeholder" />
  7. </view>
  8. <view class="row-between">
  9. <input type="text" v-model="params.code" class="input" placeholder="请输入验证码" placeholder-class="placeholder" />
  10. <button v-if="countDown <= 0" @tap="sendSms()" type="default" class="send-code">发送验证码</button>
  11. <button v-else type="default" class="send-code">{{countDown}}秒后重发</button>
  12. <!-- 60s后重新发送 -->
  13. </view>
  14. <view class="row-between">
  15. <input type="password" v-model="params.password" class="input" placeholder="新密码" placeholder-class="placeholder" />
  16. </view>
  17. </view>
  18. <view class="btn-box">
  19. <button type="default" class="active" @tap="modifyPassword">修改</button>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import { generalSendSms, userCenterModifyPassword } from '../../../common/service.js';
  25. import { validatorFun } from '../../../common/utils/util.js';
  26. export default {
  27. data() {
  28. return {
  29. params: {
  30. phone: '',
  31. code: '',
  32. password: '',
  33. },
  34. countDown: 0,
  35. }
  36. },
  37. methods: {
  38. modifyPassword() {
  39. const params = this.params;
  40. const errList = validatorFun(params, [
  41. ['phone', ['notNull', '请输入手机号'], ['isMobile', '请输入正确手机号']],
  42. ['code', ['notNull', '请输入验证码']],
  43. ['password', ['notNull', '请输入新密码']],
  44. ]);
  45. if (errList.length > 0) {
  46. return uni.showToast({
  47. icon: 'none',
  48. title: errList[0].errMsg,
  49. });
  50. }
  51. userCenterModifyPassword({
  52. data: params,
  53. success: ({code, msg, data}) => {
  54. if (code == 1) {
  55. this.info.phone = params.phone;
  56. uni.setStorageSync('USER_INFO', info);
  57. this.params = {
  58. phone: '',
  59. code: '',
  60. password: '',
  61. };
  62. uni.showModal({
  63. title: '提示',
  64. content: '修改成功,请重新登录',
  65. showCancel: false,
  66. success: (res) => {
  67. if (res.confirm) {
  68. uni.removeStorageSync('session_key');
  69. uni.removeStorageSync('USER_INFO');
  70. uni.reLaunch({
  71. url: '/pages/index/index',
  72. });
  73. }
  74. }
  75. });
  76. } else {
  77. uni.showToast({
  78. icon: 'none',
  79. title: msg,
  80. });
  81. }
  82. },
  83. });
  84. },
  85. sendSms() {
  86. const params = this.params;
  87. const errList = validatorFun(params, [
  88. ['phone', ['notNull', '请输入手机号'], ['isMobile', '请输入正确手机号']],
  89. ]);
  90. if (errList.length > 0) {
  91. return uni.showToast({
  92. icon: 'none',
  93. title: errList[0].errMsg,
  94. });
  95. }
  96. generalSendSms({
  97. data: {
  98. phone: params.phone,
  99. },
  100. success: ({code, msg, data}) => {
  101. if (code == 1) {
  102. this.countDownFn();
  103. }
  104. uni.showToast({
  105. icon: 'none',
  106. title: msg,
  107. });
  108. },
  109. });
  110. },
  111. countDownFn() {
  112. let num = 60;
  113. const fn = () => {
  114. if (num == 0) return;
  115. this.countDown = --num;
  116. setTimeout(() => fn(), 1000);
  117. };
  118. fn();
  119. },
  120. }
  121. }
  122. </script>
  123. <style scoped lang="scss">
  124. @import "./change-password.css";
  125. </style>