login.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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" 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. loginInit(options) {
  66. this.loginData.phoneNumber = options.telNum;
  67. this.sliderFlag = true;
  68. },
  69. getYzmBtn() {
  70. let req = {
  71. appkey: "FFFF0N00000000007EC0",
  72. phone: this.loginData.phoneNumber,
  73. scene: "nc_message_h5',",
  74. sessionid: this.sliderData.sessionId,
  75. sig: this.sliderData.sig,
  76. token: this.sliderData.token,
  77. }
  78. sendCode(req).then(res => {
  79. })
  80. },
  81. loginBtn() {
  82. let req = {
  83. tel: this.loginData.phoneNumber,
  84. code: this.loginData.yzmNumber,
  85. }
  86. login(req).then(res => {
  87. if (res.code == 0) {
  88. // 暂时写死
  89. res.data.cardId = 1
  90. cacheManager.set('auth',res.data)
  91. if (res.data.nianji == 0 && res.data.cardId == 0 ) {
  92. uni.redirectTo({
  93. url: `/pages/selectGradesTerms/index`
  94. })
  95. } else {
  96. uni.redirectTo({
  97. url: `/pages/study/index?nianji=${res.data.nianji}&cardId=${res.data.cardId}&zhangId=${cacheManager.get('auth').zhangId}`
  98. })
  99. }
  100. }
  101. })
  102. },
  103. clearYzmInput(event) {
  104. if (event.detail.value.length > 0) {
  105. this.loginData.clearYzmIcon = true;
  106. this.loginData.yzmStatus = 'login-btn-normal';
  107. } else {
  108. this.loginData.clearYzmIcon = false;
  109. this.loginData.yzmStatus = 'login-btn-disabled';
  110. }
  111. },
  112. clearYzm() {
  113. this.loginData.yzmNumber = '';
  114. this.loginData.yzmStatus = 'login-btn-disabled';
  115. this.loginData.clearYzmIcon = false;
  116. },
  117. startCountdown() {
  118. if(this.loginData.buttonText === '重新发送'){
  119. this.sliderFlag = true;
  120. }
  121. this.loginData.isDisabled = true;
  122. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  123. // 清除之前的定时器(如果有)
  124. if (this.loginData.intervalId) {
  125. clearInterval(this.loginData.intervalId);
  126. }
  127. // 设置新的定时器
  128. this.loginData.intervalId = setInterval(() => {
  129. this.loginData.timeLeft--;
  130. if (this.loginData.timeLeft <= 0) {
  131. clearInterval(this.loginData.intervalId);
  132. this.loginData.timeLeft = 60; // 重置倒计时
  133. this.loginData.isDisabled = false;
  134. this.loginData.buttonText = '重新发送';
  135. } else {
  136. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  137. }
  138. }, 1000);
  139. },
  140. goIndex() {
  141. uni.navigateTo({
  142. url: `/pages/login/index`
  143. })
  144. }
  145. },
  146. mounted() {
  147. },
  148. }
  149. </script>