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.

change-phone-code.vue 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 {
  22. msg,
  23. } from "@/utils/utils";
  24. import {
  25. onLoad
  26. } from "@dcloudio/uni-app";
  27. import {
  28. ref
  29. } from "vue";
  30. import {
  31. request,requestNew
  32. } from "@/utils/network/request";
  33. import {
  34. sendMessage,
  35. changePhone
  36. } from "@/utils/network/api.js";
  37. import {
  38. useUserStore
  39. } from '@/stores/user';
  40. const userStore = useUserStore();
  41. const {
  42. loginOutNoConfirm
  43. } = userStore;
  44. //上个界面传递的电话号码
  45. const phone = ref("");
  46. const code = ref(null);
  47. //倒计时时常
  48. const codeDuration = ref(0);
  49. let interval = null;
  50. onLoad((options) => {
  51. phone.value = options.phone;
  52. codeInterval();
  53. });
  54. /* 验证码倒计时 */
  55. const codeInterval = () => {
  56. codeDuration.value = 60;
  57. interval = setInterval(() => {
  58. codeDuration.value--;
  59. if (codeDuration.value === 0) {
  60. if (interval) {
  61. clearInterval(interval);
  62. interval = null;
  63. }
  64. }
  65. }, 1000);
  66. };
  67. /* 发送验证码 */
  68. const sendRegisterCode = () => {
  69. if (codeDuration.value !== 0) {
  70. return;
  71. }
  72. const options = {
  73. type: 2,
  74. data: {
  75. mobile: phone.value
  76. },
  77. method: "POST",
  78. showLoading: true,
  79. };
  80. requestNew(sendMessage, options).then((res) => {
  81. msg("验证码发送成功!");
  82. codeInterval();
  83. });
  84. };
  85. /* 下一步 */
  86. const nextStep = () => {
  87. if (!code.value) {
  88. msg("请先输入验证码!");
  89. return;
  90. }
  91. const options = {
  92. type: 2,
  93. data: {
  94. mobile: phone.value,
  95. verificationCode: code.value
  96. },
  97. method: "POST",
  98. showLoading: true,
  99. };
  100. requestNew(changePhone, options).then((res) => {
  101. msg("更改手机号成功");
  102. codeInterval();
  103. var pages = getCurrentPages().length;
  104. uni.navigateBack({
  105. delta: pages,
  106. });
  107. loginOutNoConfirm()
  108. });
  109. };
  110. </script>
  111. <style lang="scss" scoped>
  112. .register-main {
  113. border-top: 1rpx solid #dcdcdc;
  114. padding: 78rpx 30rpx 50rpx;
  115. .title {
  116. font-size: 32rpx;
  117. color: #333333;
  118. font-weight: 600;
  119. }
  120. .hint {
  121. font-size: 24rpx;
  122. color: #999999;
  123. margin-top: 20rpx;
  124. }
  125. }
  126. .input-code {
  127. margin: 100rpx -10rpx 0px;
  128. }
  129. .hint2 {
  130. margin-top: 40rpx;
  131. display: flex;
  132. .green {
  133. font-size: 28rpx;
  134. color: #00b38b;
  135. }
  136. .grey {
  137. font-size: 24rpx;
  138. color: #999999;
  139. margin-left: 16rpx;
  140. }
  141. }
  142. .btn {
  143. margin: 200rpx 40rpx 0px;
  144. }
  145. </style>