login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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="请输入验证码"
  9. maxlength="6" @input="clearYzmInput" />
  10. <view class="close-btn" v-if="loginData.clearYzmIcon" @click="clearYzm"></view>
  11. </view>
  12. <view class="login-btn yzm-btn" @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. <sliderDialog ref="sliderDialogRef" @emitFun="emitFun" @sliderClose="sliderClose" v-if="sliderFlag"></sliderDialog>
  20. </view>
  21. </template>
  22. <script>
  23. import {
  24. ref,
  25. reactive
  26. } from "vue"
  27. import {
  28. login,
  29. sendCode
  30. } from "@/api/login.js"
  31. import sliderDialog from './sliderDialog.vue'
  32. import cacheManager from "@/utils/cacheManager.js";
  33. export default {
  34. data() {
  35. return {
  36. loginData: {
  37. phoneNumber: null,
  38. yzmNumber: null,
  39. clearYzmIcon: false,
  40. yzmStatus: 'login-btn-disabled',
  41. timeLeft: 60, // 初始倒计时时间(秒)
  42. intervalId: null, // 定时器ID
  43. isDisabled: false, // 按钮是否禁用
  44. buttonText: '', // 按钮文本
  45. },
  46. sliderData: {},
  47. sliderDialogRef: null,
  48. sliderFlag: false,
  49. }
  50. },
  51. components: {
  52. sliderDialog
  53. },
  54. onLoad(options) {
  55. this.loginInit(options);
  56. },
  57. onReady() {},
  58. methods: {
  59. emitFun(data){
  60. this.sliderFlag =false;
  61. this.startCountdown();
  62. this.sliderData =data;
  63. this.getYzmBtn();
  64. },
  65. sliderClose(){
  66. this.sliderFlag =false;
  67. },
  68. loginInit(options) {
  69. this.loginData.phoneNumber = options.telNum;
  70. this.sliderFlag = true;
  71. },
  72. getYzmBtn() {
  73. let req = {
  74. appkey: "FFFF0N00000000007EC0",
  75. phone: this.loginData.phoneNumber,
  76. scene: "nc_message_h5',",
  77. sessionid: this.sliderData.sessionId,
  78. sig: this.sliderData.sig,
  79. token: this.sliderData.token,
  80. }
  81. sendCode(req).then(res => {
  82. })
  83. },
  84. loginBtn() {
  85. let req = {
  86. tel: this.loginData.phoneNumber,
  87. code: this.loginData.yzmNumber,
  88. }
  89. login(req).then(res => {
  90. if (res.code == 0) {
  91. cacheManager.set('auth',res.data)
  92. if (res.data.cardId == 0 ) {
  93. uni.redirectTo({
  94. url: `/pages/selectGradesTerms/index`
  95. })
  96. } else {
  97. uni.redirectTo({
  98. url: `/pages/study/index`
  99. })
  100. }
  101. }
  102. })
  103. },
  104. clearYzmInput(event) {
  105. if (event.detail.value.length > 0) {
  106. this.loginData.clearYzmIcon = true;
  107. this.loginData.yzmStatus = 'login-btn-normal';
  108. } else {
  109. this.loginData.clearYzmIcon = false;
  110. this.loginData.yzmStatus = 'login-btn-disabled';
  111. }
  112. },
  113. clearYzm() {
  114. this.loginData.yzmNumber = '';
  115. this.loginData.yzmStatus = 'login-btn-disabled';
  116. this.loginData.clearYzmIcon = false;
  117. },
  118. startCountdown() {
  119. if(this.loginData.buttonText === '重新发送'){
  120. this.sliderFlag = true;
  121. }
  122. this.loginData.isDisabled = true;
  123. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  124. // 清除之前的定时器(如果有)
  125. if (this.loginData.intervalId) {
  126. clearInterval(this.loginData.intervalId);
  127. }
  128. // 设置新的定时器
  129. this.loginData.intervalId = setInterval(() => {
  130. this.loginData.timeLeft--;
  131. if (this.loginData.timeLeft <= 0) {
  132. clearInterval(this.loginData.intervalId);
  133. this.loginData.timeLeft = 60; // 重置倒计时
  134. this.loginData.isDisabled = false;
  135. this.loginData.buttonText = '重新发送';
  136. } else {
  137. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  138. }
  139. }, 1000);
  140. },
  141. goIndex() {
  142. uni.navigateTo({
  143. url: `/pages/login/index`
  144. })
  145. }
  146. },
  147. mounted() {
  148. },
  149. }
  150. </script>