login.vue 4.4 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 {
  33. getAuth
  34. } from '@/utils/auth.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. 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. let obj = JSON.stringify(res.data)
  91. uni.setStorage({
  92. key: 'Mta-Auth',
  93. data: obj // 假设 this.userInputValue 是用户输入的数据
  94. });
  95. if (res.data.nianji == 0 && res.data.xueqi == 0 ) {
  96. uni.redirectTo({
  97. url: `/pages/selectGradesTerms/index`
  98. })
  99. } else {
  100. uni.redirectTo({
  101. url: `/pages/study/index?nianji=${res.data.nianji}&xueqi=${res.data.xueqi}&zhangId=${JSON.parse(getAuth()).userId}`
  102. })
  103. }
  104. }
  105. })
  106. },
  107. clearYzmInput(event) {
  108. if (event.detail.value.length > 0) {
  109. this.loginData.clearYzmIcon = true;
  110. this.loginData.yzmStatus = 'login-btn-normal';
  111. } else {
  112. this.loginData.clearYzmIcon = false;
  113. this.loginData.yzmStatus = 'login-btn-disabled';
  114. }
  115. },
  116. clearYzm() {
  117. this.loginData.yzmNumber = '';
  118. this.loginData.yzmStatus = 'login-btn-disabled';
  119. this.loginData.clearYzmIcon = false;
  120. },
  121. startCountdown() {
  122. if(this.loginData.buttonText === '重新发送'){
  123. this.sliderFlag = true;
  124. }
  125. this.loginData.isDisabled = true;
  126. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  127. // 清除之前的定时器(如果有)
  128. if (this.loginData.intervalId) {
  129. clearInterval(this.loginData.intervalId);
  130. }
  131. // 设置新的定时器
  132. this.loginData.intervalId = setInterval(() => {
  133. this.loginData.timeLeft--;
  134. if (this.loginData.timeLeft <= 0) {
  135. clearInterval(this.loginData.intervalId);
  136. this.loginData.timeLeft = 60; // 重置倒计时
  137. this.loginData.isDisabled = false;
  138. this.loginData.buttonText = '重新发送';
  139. } else {
  140. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  141. }
  142. }, 1000);
  143. },
  144. goIndex() {
  145. uni.navigateTo({
  146. url: `/pages/login/index`
  147. })
  148. }
  149. },
  150. mounted() {
  151. },
  152. }
  153. </script>