login.vue 4.4 KB

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