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" 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. export default {
  33. data() {
  34. return {
  35. loginData: {
  36. phoneNumber: null,
  37. yzmNumber: null,
  38. clearYzmIcon: false,
  39. yzmStatus: 'login-btn-disabled',
  40. timeLeft: 60, // 初始倒计时时间(秒)
  41. intervalId: null, // 定时器ID
  42. isDisabled: false, // 按钮是否禁用
  43. buttonText: '', // 按钮文本
  44. },
  45. sliderData: {},
  46. sliderDialogRef: null,
  47. sliderFlag: false,
  48. }
  49. },
  50. components: {
  51. sliderDialog
  52. },
  53. onLoad(options) {
  54. this.loginInit(options);
  55. },
  56. onReady() {},
  57. methods: {
  58. emitFun(data){
  59. this.sliderFlag =false;
  60. this.startCountdown();
  61. this.sliderData =data;
  62. this.getYzmBtn();
  63. },
  64. loginInit(options) {
  65. this.loginData.phoneNumber = options.telNum;
  66. this.sliderFlag = true;
  67. },
  68. getYzmBtn() {
  69. let req = {
  70. appkey: "FFFF0N00000000007EC0",
  71. phone: this.loginData.phoneNumber,
  72. scene: "nc_message_h5',",
  73. sessionid: this.sliderData.sessionId,
  74. sig: this.sliderData.sig,
  75. token: this.sliderData.token,
  76. }
  77. sendCode(req).then(res => {
  78. })
  79. },
  80. loginBtn() {
  81. let req = {
  82. tel: 1,
  83. code: this.loginData.yzmNumber,
  84. }
  85. login(req).then(res => {
  86. if (res.code == 0) {
  87. let obj = JSON.stringify(res.data)
  88. uni.setStorage({
  89. key: 'Mta-Auth',
  90. data: obj // 假设 this.userInputValue 是用户输入的数据
  91. });
  92. if (res.data.nianji == 0 && res.data.xueqi == 0 ) {
  93. uni.navigateTo({
  94. url: `/pages/selectGradesTerms/index`
  95. })
  96. } else {
  97. uni.navigateTo({
  98. url: `/pages/study/index?nianji=${res.data.nianji}&xueqi=${res.data.xueqi}`
  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>