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-ali.vue 2.7KB

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