login.vue 4.4 KB

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