login.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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="请输入验证码" maxlength="6"
  9. @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 {
  27. onLoad,
  28. onReady
  29. } from '@dcloudio/uni-app';
  30. import request from "@/utils/request.js"
  31. import {
  32. login,
  33. sendCode
  34. } from "@/api/login.js"
  35. const data = reactive({
  36. phoneNumber: null,
  37. yzmNumber: null,
  38. clearYzmIcon: false,
  39. yzmStatus: '',
  40. timeLeft: 60, // 初始倒计时时间(秒)
  41. intervalId: null, // 定时器ID
  42. isDisabled: false, // 按钮是否禁用
  43. buttonText: '重新发送', // 按钮文本
  44. sliderObj: {},
  45. })
  46. const pageData = reactive({
  47. })
  48. onLoad((options) => {
  49. Object.assign(pageData, JSON.parse(options.data))
  50. console.log(pageData)
  51. startCountdown();
  52. getYzmBtn();
  53. })
  54. const getYzmBtn = () => {
  55. let req = {
  56. appkey: "FFFF0N00000000007EC0",
  57. phone: "18640920672",
  58. scene: "nc_message_h5',",
  59. sessionid:pageData.sessionId,
  60. sig: pageData.sig,
  61. token: pageData.token,
  62. }
  63. sendCode(req).then(res => {
  64. })
  65. }
  66. const loginBtn = () => {
  67. let req = {
  68. tel: "1",
  69. code:'1'
  70. }
  71. login(req).then(res => {
  72. })
  73. // uni.navigateTo({
  74. // url: `/pages/study/index?gradeId=${options.grade}&termId=${options.term}&text=${text1}${text2}`
  75. // })
  76. }
  77. const clearYzmInput = (event) => {
  78. if (event.detail.value.length > 0) {
  79. data.clearYzmIcon = true;
  80. } else {
  81. data.clearYzmIcon = false;
  82. }
  83. }
  84. const clearYzm = () => {
  85. data.yzmNumber = '';
  86. data.clearYzmIcon = false;
  87. }
  88. const startCountdown = () => {
  89. data.isDisabled = true;
  90. data.buttonText = `重新发送(${data.timeLeft}S)`;
  91. // 清除之前的定时器(如果有)
  92. if (data.intervalId) {
  93. clearInterval(data.intervalId);
  94. }
  95. // 设置新的定时器
  96. data.intervalId = setInterval(() => {
  97. data.timeLeft--;
  98. if (data.timeLeft <= 0) {
  99. clearInterval(data.intervalId);
  100. data.timeLeft = 60; // 重置倒计时
  101. data.isDisabled = false;
  102. data.buttonText = '重新发送';
  103. } else {
  104. data.buttonText = `重新发送(${data.timeLeft}S)`;
  105. }
  106. }, 1000);
  107. }
  108. </script>