login.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. import {useXuekeNianji} from "@/utils/cacheManager.js"
  34. const { updateXueke, getXueke} = useXuekeNianji();
  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. loginInit(options) {
  68. this.loginData.phoneNumber = options.telNum;
  69. this.sliderFlag = true;
  70. },
  71. getYzmBtn() {
  72. let req = {
  73. appkey: "FFFF0N00000000007EC0",
  74. phone: this.loginData.phoneNumber,
  75. scene: "nc_message_h5',",
  76. sessionid: this.sliderData.sessionId,
  77. sig: this.sliderData.sig,
  78. token: this.sliderData.token,
  79. }
  80. sendCode(req).then(res => {
  81. })
  82. },
  83. loginBtn() {
  84. let req = {
  85. tel: this.loginData.phoneNumber,
  86. code: this.loginData.yzmNumber,
  87. }
  88. login(req).then(res => {
  89. if (res.code == 0) {
  90. // 暂时写死
  91. res.data.cardId = 1
  92. cacheManager.set('auth',res.data)
  93. if (res.data.cardId == 0 ) {
  94. uni.redirectTo({
  95. url: `/pages/selectGradesTerms/index`
  96. })
  97. } else {
  98. updateXueke(res.data.nianji,res.data.cardId)
  99. uni.redirectTo({
  100. url: `/pages/study/index?nianji=${res.data.nianji}&cardId=${res.data.cardId}&zhangId=${cacheManager.get('auth').zhangId}`
  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.navigateTo({
  145. url: `/pages/login/index`
  146. })
  147. }
  148. },
  149. mounted() {
  150. },
  151. }
  152. </script>