login.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view class="ezy-login-page">
  3. <view @click="goIndex" class="ezy-nav-bar-icon"></view>
  4. <view class="ezy-login-wrap">
  5. <icon class="login-e-img"></icon>
  6. <view class="login-body-box">
  7. <view class="login-title-img"></view>
  8. <view class="yzm-show">验证码已发送至:{{loginData.phoneNumber}}</view>
  9. <view class="phone-input-box">
  10. <input class="phone-input" type="text" v-model="loginData.yzmNumber" placeholder="请输入验证码"
  11. maxlength="6" @input="clearYzmInput" />
  12. <view class="close-btn" v-if="loginData.clearYzmIcon" @click="clearYzm"></view>
  13. </view>
  14. <view class="login-btn yzm-btn" @click="loginBtn" :class="loginData.yzmStatus"></view>
  15. <text class="cxfs-btn" @click="startCountdown"
  16. :class="{ 'cxfs-btn-disabled': loginData.isDisabled}">{{loginData.buttonText}}</text>
  17. <text class="login-text" @click="goIndex">无法收到验证码</text>
  18. <text class="login-text">客服电话:17304117625</text>
  19. </view>
  20. </view>
  21. <captcha ref="captcha" :config="config" @captchaSuccess="captchaSuccess" @captchaError="captchaError"
  22. @captchaFail="captchaFail" @captchaReady="captchaReady" @captchaClose="captchaClose"></captcha>
  23. </view>
  24. </template>
  25. <script>
  26. import {
  27. ref,
  28. reactive
  29. } from "vue"
  30. import {
  31. login,
  32. sendCode
  33. } from "@/api/login.js"
  34. import cacheManager from "@/utils/cacheManager.js";
  35. import captcha from "../../components/captcha4/index.vue";
  36. import {
  37. toast
  38. } from "../../utils/common";
  39. export default {
  40. data() {
  41. return {
  42. loginData: {
  43. phoneNumber: null,
  44. yzmNumber: null,
  45. clearYzmIcon: false,
  46. yzmStatus: 'login-btn-disabled',
  47. timeLeft: 60, // 初始倒计时时间(秒)
  48. intervalId: null, // 定时器ID
  49. isDisabled: false, // 按钮是否禁用
  50. buttonText: '', // 按钮文本
  51. },
  52. sliderData: {},
  53. sliderDialogRef: null,
  54. config: {
  55. captchaId: "9d5837b0807b8de44da0de310a0b2813",
  56. },
  57. }
  58. },
  59. components: {
  60. captcha
  61. },
  62. onLoad(options) {
  63. this.loginInit(options);
  64. },
  65. onReady() {},
  66. methods: {
  67. captchaSuccess(result) { // app端的回调
  68. console.log(result)
  69. this.startCountdown();
  70. this.sliderData = result;
  71. this.getYzmBtn();
  72. },
  73. captchaError(e) {
  74. // app端的回调、
  75. console.log('error',JSON.stringify(e));
  76. toast(JSON.stringify(e))
  77. },
  78. captchaReady() {
  79. // app端的回调
  80. },
  81. captchaFail() {
  82. // app端的回调
  83. toast('验证失败!')
  84. },
  85. captchaClose() {
  86. uni.redirectTo({
  87. url: `/pages/login/index`
  88. })
  89. },
  90. loginInit(options) {
  91. this.loginData.phoneNumber = options.telNum;
  92. },
  93. getYzmBtn() {
  94. let req = {
  95. phone: this.loginData.phoneNumber,
  96. captchaOutput: this.sliderData.captcha_output,
  97. genTime: this.sliderData.gen_time,
  98. lotNumber: this.sliderData.lot_number,
  99. passToken: this.sliderData.pass_token,
  100. }
  101. console.log('req', req);
  102. sendCode(req).then(res => {
  103. })
  104. },
  105. loginBtn() {
  106. let req = {
  107. tel: this.loginData.phoneNumber,
  108. code: this.loginData.yzmNumber,
  109. }
  110. login(req).then(res => {
  111. if (res.code == 0) {
  112. cacheManager.set('auth', res.data)
  113. if (res.data.subjectId ==0 &&res.data.levelId == 0) {
  114. uni.redirectTo({
  115. url: `/pages/selectGradesTerms/index`
  116. })
  117. } else {
  118. uni.redirectTo({
  119. url: `/pages/study/index`
  120. })
  121. }
  122. }
  123. })
  124. },
  125. clearYzmInput(event) {
  126. if (event.detail.value.length > 0) {
  127. this.loginData.clearYzmIcon = true;
  128. this.loginData.yzmStatus = 'login-btn-normal';
  129. } else {
  130. this.loginData.clearYzmIcon = false;
  131. this.loginData.yzmStatus = 'login-btn-disabled';
  132. }
  133. },
  134. clearYzm() {
  135. this.loginData.yzmNumber = '';
  136. this.loginData.yzmStatus = 'login-btn-disabled';
  137. this.loginData.clearYzmIcon = false;
  138. },
  139. startCountdown() {
  140. if (this.loginData.buttonText === '重新发送') {
  141. this.$refs.captcha.showCaptcha();
  142. }
  143. this.loginData.isDisabled = true;
  144. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  145. // 清除之前的定时器(如果有)
  146. if (this.loginData.intervalId) {
  147. clearInterval(this.loginData.intervalId);
  148. }
  149. // 设置新的定时器
  150. this.loginData.intervalId = setInterval(() => {
  151. this.loginData.timeLeft--;
  152. if (this.loginData.timeLeft <= 0) {
  153. clearInterval(this.loginData.intervalId);
  154. this.loginData.timeLeft = 60; // 重置倒计时
  155. this.loginData.isDisabled = false;
  156. this.loginData.buttonText = '重新发送';
  157. } else {
  158. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  159. }
  160. }, 1000);
  161. },
  162. goIndex() {
  163. uni.redirectTo({
  164. url: `/pages/login/index`
  165. })
  166. }
  167. },
  168. mounted() {
  169. this.$refs.captcha.showCaptcha();
  170. },
  171. }
  172. </script>