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

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