You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

forget-pwd-step2.vue 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!-- 注册第2步 -->
  2. <template>
  3. <view class="register-main">
  4. <view class="title">请输入验证码</view>
  5. <view class="hint">验证码已发送至:{{ phone }}</view>
  6. <view class="input-code">
  7. <verification-code-input v-model="code"></verification-code-input>
  8. </view>
  9. <view class="hint2">
  10. <view class="green">{{ codeDuration === 0 ? "" : codeDuration }}</view>
  11. <view class="grey" @click="sendRegisterCode">{{
  12. codeDuration === 0 ? "重新发送验证码" : "秒后可重新发送验证码"
  13. }}</view>
  14. </view>
  15. </view>
  16. <view class="btn">
  17. <submit-button title="下一步" @submit="nextStep"></submit-button>
  18. </view>
  19. </template>
  20. <script setup lang="ts">
  21. import { msg, navTo } from "@/utils/utils";
  22. import { onLoad } from "@dcloudio/uni-app";
  23. import { ref } from "vue";
  24. import { request } from "@/utils/network/request";
  25. import { sendCode } from "@/utils/network/api.js";
  26. //上个界面传递的电话号码
  27. const phone = ref("");
  28. const code = ref(null);
  29. //倒计时时常
  30. const codeDuration = ref(0);
  31. let interval = null;
  32. onLoad((options) => {
  33. phone.value = options.phone;
  34. codeInterval();
  35. });
  36. /* 验证码倒计时 */
  37. const codeInterval = () => {
  38. codeDuration.value = 60;
  39. interval = setInterval(() => {
  40. codeDuration.value--;
  41. if (codeDuration.value === 0) {
  42. if (interval) {
  43. clearInterval(interval);
  44. interval = null;
  45. }
  46. }
  47. }, 1000);
  48. };
  49. /* 发送验证码 */
  50. const sendRegisterCode = () => {
  51. if (codeDuration.value !== 0) {
  52. return;
  53. }
  54. const options = {
  55. type: 2,
  56. data: { mobile: phone.value },
  57. method: "POST",
  58. showLoading: true,
  59. };
  60. request(sendCode, options).then((res) => {
  61. msg("验证码发送成功!");
  62. codeInterval();
  63. });
  64. };
  65. /* 下一步 */
  66. const nextStep = () => {
  67. if (!code.value) {
  68. msg("请先输入验证码!");
  69. return;
  70. }
  71. navTo(`/login/forget-pwd-step3?phone=${phone.value}&code=${code.value}`);
  72. };
  73. </script>
  74. <style lang="scss" scoped>
  75. .register-main {
  76. border-top: 1rpx solid #dcdcdc;
  77. padding: 78rpx 30rpx 50rpx;
  78. .title {
  79. font-size: 32rpx;
  80. color: #333333;
  81. font-weight: 600;
  82. }
  83. .hint {
  84. font-size: 24rpx;
  85. color: #999999;
  86. margin-top: 20rpx;
  87. }
  88. }
  89. .input-code {
  90. margin: 100rpx -10rpx 0px;
  91. }
  92. .hint2 {
  93. margin-top: 40rpx;
  94. display: flex;
  95. .green {
  96. font-size: 28rpx;
  97. color: #00b38b;
  98. }
  99. .grey {
  100. font-size: 24rpx;
  101. color: #999999;
  102. margin-left: 16rpx;
  103. }
  104. }
  105. .btn {
  106. margin: 200rpx 40rpx 0px;
  107. }
  108. </style>