login.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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">验证码已发送至:{{loginData.phoneNumber}}</view>
  7. <view class="phone-input-box">
  8. <input class="phone-input" type="text" v-model="loginData.yzmNumber" placeholder="请输入验证码" maxlength="6"
  9. @input="clearYzmInput" />
  10. <view class="close-btn" v-if="loginData.clearYzmIcon" @click="clearYzm"></view>
  11. </view>
  12. <view class="login-btn login-btn-disabled" @click="loginBtn" :class="loginData.yzmStatus"></view>
  13. <text class="cxfs-btn" @click="startCountdown"
  14. :class="{ 'cxfs-btn-disabled': loginData.isDisabled}">{{loginData.buttonText}}</text>
  15. <text class="login-text" @click="goIndex">无法收到验证码</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 loginData = 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. })
  45. const pageData = reactive({
  46. })
  47. onLoad((options) => {
  48. loginInit(options);
  49. startCountdown();
  50. getYzmBtn();
  51. })
  52. const loginInit = (options) => {
  53. loginData.phoneNumber = options.telNum;
  54. Object.assign(pageData, JSON.parse(options.data))
  55. }
  56. const getYzmBtn = () => {
  57. let req = {
  58. appkey: "FFFF0N00000000007EC0",
  59. phone: "18640920672",
  60. scene: "nc_message_h5',",
  61. sessionid: pageData.sessionId,
  62. sig: pageData.sig,
  63. token: pageData.token,
  64. }
  65. sendCode(req).then(res => {
  66. })
  67. }
  68. const loginBtn = () => {
  69. let req = {
  70. tel: "1",
  71. code: '1'
  72. }
  73. login(req).then(res => {
  74. if (res.code == 0) {
  75. let obj = JSON.stringify(res.data)
  76. console.log(obj)
  77. uni.setStorage({
  78. key: 'Mta-Auth',
  79. data: obj // 假设 this.userInputValue 是用户输入的数据
  80. });
  81. }
  82. uni.switchTab({
  83. url: `/pages/study/index`
  84. })
  85. })
  86. // uni.navigateTo({
  87. // url: `/pages/study/index?gradeId=${options.grade}&termId=${options.term}&text=${text1}${text2}`
  88. // })
  89. }
  90. const clearYzmInput = (event) => {
  91. if (event.detail.value.length > 0) {
  92. loginData.clearYzmIcon = true;
  93. } else {
  94. loginData.clearYzmIcon = false;
  95. }
  96. }
  97. const clearYzm = () => {
  98. loginData.yzmNumber = '';
  99. loginData.clearYzmIcon = false;
  100. }
  101. const startCountdown = () => {
  102. loginData.isDisabled = true;
  103. loginData.buttonText = `重新发送(${loginData.timeLeft}S)`;
  104. // 清除之前的定时器(如果有)
  105. if (loginData.intervalId) {
  106. clearInterval(loginData.intervalId);
  107. }
  108. // 设置新的定时器
  109. loginData.intervalId = setInterval(() => {
  110. loginData.timeLeft--;
  111. if (loginData.timeLeft <= 0) {
  112. clearInterval(loginData.intervalId);
  113. loginData.timeLeft = 60; // 重置倒计时
  114. loginData.isDisabled = false;
  115. loginData.buttonText = '重新发送';
  116. } else {
  117. loginData.buttonText = `重新发送(${loginData.timeLeft}S)`;
  118. }
  119. }, 1000);
  120. }
  121. const goIndex = () => {
  122. uni.navigateTo({
  123. url: `/pages/login/index?data=`+JSON.stringify(pageData)
  124. })
  125. }
  126. </script>