login.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view class="ezy-login-page">
  3. <view class="ezy-login-wrap" >
  4. <view class="login-body-box">
  5. <view class="login-title-img"></view>
  6. <view class="yzm-show">验证码已发送至:{{data.phoneNumber}}</view>
  7. <view class="phone-input-box">
  8. <input class="phone-input" type="text" v-model="data.yzmNumber" placeholder="请输入验证码"
  9. maxlength="6" @input="clearYzmInput" />
  10. <view class="close-btn" v-if="data.clearYzmIcon" @click="clearYzm"></view>
  11. </view>
  12. <view class="login-btn login-btn-disabled" @click="loginBtn" :class="data.yzmStatus"></view>
  13. <text class="cxfs-btn" @click="startCountdown"
  14. :class="{ 'cxfs-btn-disabled': data.isDisabled}">{{data.buttonText}}</text>
  15. <text class="login-text">无法收到验证码</text>
  16. <text class="login-text">客服电话:400-052-2130</text>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script setup>
  22. import {
  23. ref,
  24. reactive
  25. } from "vue"
  26. import { onLoad,onReady } from '@dcloudio/uni-app';
  27. import request from "@/utils/request.js"
  28. const data = reactive({
  29. phoneNumber: null,
  30. yzmNumber: null,
  31. clearYzmIcon: false,
  32. yzmStatus:'',
  33. timeLeft: 60, // 初始倒计时时间(秒)
  34. intervalId: null, // 定时器ID
  35. isDisabled: false, // 按钮是否禁用
  36. buttonText: '重新发送' // 按钮文本
  37. })
  38. onLoad((options) => {
  39. startCountdown();
  40. // getYzmBtn();
  41. })
  42. /********* 验证码 *********/
  43. const getYzmBtn = () => {
  44. return request({
  45. url: "/common/app/send/code",
  46. method: "POST",
  47. data: {
  48. phone: 18842603074,
  49. sign: ''
  50. }
  51. })
  52. }
  53. const loginBtn = () => {
  54. uni.switchTab({
  55. url: '/pages/study/index'
  56. });
  57. uni.navigateTo({
  58. url: `/pages/study/index?gradeId=${options.grade}&termId=${options.term}&text=${text1}${text2}`
  59. })
  60. }
  61. const clearYzmInput = (event) => {
  62. if (event.detail.value.length > 0) {
  63. data.clearYzmIcon = true;
  64. } else {
  65. data.clearYzmIcon = false;
  66. }
  67. }
  68. const clearYzm = () => {
  69. data.yzmNumber = '';
  70. data.clearYzmIcon = false;
  71. }
  72. const startCountdown= () => {
  73. data.isDisabled = true;
  74. data.buttonText = `重新发送(${data.timeLeft}S)`;
  75. // 清除之前的定时器(如果有)
  76. if (data.intervalId) {
  77. clearInterval(data.intervalId);
  78. }
  79. // 设置新的定时器
  80. data.intervalId = setInterval(() => {
  81. data.timeLeft--;
  82. if (data.timeLeft <= 0) {
  83. clearInterval(data.intervalId);
  84. data.timeLeft = 60; // 重置倒计时
  85. data.isDisabled = false;
  86. data.buttonText = '重新发送';
  87. } else {
  88. data.buttonText = `重新发送(${data.timeLeft}S)`;
  89. }
  90. }, 1000);
  91. }
  92. </script>