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

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