checkCode.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <!--验证验证码-->
  3. <view class="retrieve-pwd">
  4. <u--form
  5. labelPosition="left"
  6. :model="formData"
  7. :rules="rules"
  8. ref="uForm"
  9. labelWidth="70"
  10. >
  11. <u-form-item borderBottom label="手机号">
  12. <view class="phone-num">
  13. <text>
  14. {{ formData.phoneNum }}
  15. </text>
  16. </view>
  17. </u-form-item>
  18. <u-form-item label="验证码">
  19. <c-input
  20. class="login-input"
  21. v-model="formData.code"
  22. placeholder="请输入验证码"
  23. type="number"
  24. border="none"
  25. >
  26. <view slot="suffix">
  27. <u-code
  28. keepRunning
  29. uniqueKey="retrieve-pwd-code"
  30. ref="uCode"
  31. @change="codeChange"
  32. ></u-code>
  33. <u--text
  34. size="14"
  35. @click="getCode"
  36. type="primary"
  37. :text="tips"
  38. >
  39. </u--text>
  40. </view>
  41. </c-input>
  42. </u-form-item>
  43. </u--form>
  44. <view class="footer" style="margin-top: 130rpx">
  45. <c-button
  46. @click="nextStep"
  47. :key="isPassed"
  48. type="primary"
  49. :disabled="!isPassed"
  50. >
  51. 下一步
  52. </c-button>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import { getAuthCode } from '@/api/com';
  58. import { byPassword } from '@/api/user/login/retrievePwd'; // 找回密码手机验证码验证
  59. export default {
  60. name: 'retrievePwd',
  61. data() {
  62. return {
  63. tips: '',
  64. formData: {
  65. phoneNum: '',
  66. code: '',
  67. },
  68. rules: {
  69. code: [
  70. {
  71. type: 'string',
  72. required: true,
  73. message: '请输入验证码',
  74. trigger: ['change'],
  75. },
  76. ],
  77. },
  78. };
  79. },
  80. computed: {
  81. isPassed() {
  82. const code = this.formData.code;
  83. return code;
  84. },
  85. },
  86. onLoad(params) {
  87. this.formData.phoneNum = params.phoneNum;
  88. },
  89. methods: {
  90. async nextStep() {
  91. try {
  92. const params = {
  93. userName: this.formData.phoneNum,
  94. code: this.formData.code,
  95. };
  96. this.$c.loading();
  97. const { data } = await byPassword(params);
  98. uni.hideLoading();
  99. uni.$u.route({
  100. type: 'redirectTo',
  101. url: '/pages/user/retrievePwd/setNewPwd',
  102. params: {
  103. uuid: data,
  104. phone: this.formData.phoneNum,
  105. },
  106. });
  107. } catch (e) {
  108. uni.hideLoading();
  109. console.error(e);
  110. }
  111. },
  112. async getCode() {
  113. //注意:用户可能在倒计时的过程中点击获取验证码的按钮,组件内部提供了通过ref获取的canGetCode变量,在倒计时 过程中,该值为false
  114. if (!this.$refs.uCode.canGetCode) return;
  115. if (!this.formData.phoneNum) {
  116. // 手机号为空
  117. this.$c.toast('手机号不能为空');
  118. return;
  119. }
  120. uni.$c.loading('正在获取验证码');
  121. await getAuthCode({
  122. phone: this.formData.phoneNum,
  123. code: 'putPassword',
  124. });
  125. uni.hideLoading();
  126. uni.$c.toast('验证码已发送');
  127. // 通知验证码组件内部开始倒计时
  128. this.$refs.uCode.start();
  129. },
  130. codeChange(text) {
  131. this.tips = text;
  132. },
  133. },
  134. };
  135. </script>
  136. <style scoped lang="scss">
  137. .retrieve-pwd {
  138. padding: 28rpx;
  139. background-color: #f8f8f8;
  140. height: 100%;
  141. .u-form {
  142. padding: 8rpx 20rpx;
  143. background-color: #fff;
  144. border-radius: 6px;
  145. }
  146. .phone-num {
  147. display: flex;
  148. justify-content: flex-end;
  149. width: 100%;
  150. font-size: 13px;
  151. color: $u-tips-color;
  152. }
  153. }
  154. </style>