login.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="ezy-login-page">
  3. <view @click="goIndex" class="ezy-nav-bar-icon yzm-nav-bar-icon"></view>
  4. <icon class="login-img"></icon>
  5. <view class="ezy-login-wrap">
  6. <view class="login-body-box">
  7. <view class="yzm-show">验证码已发送至:{{loginData.phoneNumber}}</view>
  8. <view class="phone-input-box">
  9. <input class="phone-input" type="text" v-model="loginData.yzmNumber" placeholder="请输入验证码"
  10. maxlength="4" @input="clearYzmInput" />
  11. <view class="close-btn" v-if="loginData.clearYzmIcon" @click="clearYzm"></view>
  12. </view>
  13. <ezyActiveVue class="ezy-btn-active login-btn yzm-btn" @aclick="loginBtn" :class="loginData.yzmStatus">
  14. 登录</ezyActiveVue>
  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">客服电话:<text>4001750778</text></text>
  19. </view>
  20. </view>
  21. <captcha ref="captcha" :config="config" @captchaSuccess="captchaSuccess" @captchaError="captchaError"
  22. @captchaFail="captchaFail" @captchaReady="captchaReady" @captchaClose="captchaClose"></captcha>
  23. </view>
  24. </template>
  25. <script>
  26. import {
  27. ref,
  28. reactive
  29. } from "vue"
  30. import {
  31. login,
  32. sendCode,
  33. banbenImpinfo
  34. } from "@/api/login.js"
  35. import cacheManager from "@/utils/cacheManager.js";
  36. import captcha from "../../components/captcha4/index.vue";
  37. import {
  38. toast,
  39. getUserIdentity
  40. } from "@/utils/common";
  41. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  42. export default {
  43. data() {
  44. return {
  45. loginData: {
  46. phoneNumber: null,
  47. yzmNumber: null,
  48. clearYzmIcon: false,
  49. yzmStatus: 'login-btn-disabled',
  50. timeLeft: 60, // 初始倒计时时间(秒)
  51. intervalId: null, // 定时器ID
  52. isDisabled: false, // 按钮是否禁用
  53. buttonText: '', // 按钮文本
  54. },
  55. sliderData: {},
  56. sliderDialogRef: null,
  57. config: {
  58. captchaId: "9d5837b0807b8de44da0de310a0b2813",
  59. },
  60. banbenId: '',
  61. chanpinId: '',
  62. danyuanId: '',
  63. dengjiId: ''
  64. }
  65. },
  66. components: {
  67. captcha,
  68. ezyActiveVue
  69. },
  70. onLoad(options) {
  71. this.loginInit(options);
  72. },
  73. onReady() {},
  74. methods: {
  75. captchaSuccess(result) { // app端的回调
  76. console.log(result)
  77. this.startCountdown();
  78. this.sliderData = result;
  79. this.getYzmBtn();
  80. },
  81. captchaError(e) {
  82. // app端的回调、
  83. console.log('error', JSON.stringify(e));
  84. toast(JSON.stringify(e))
  85. },
  86. captchaReady() {
  87. // app端的回调
  88. },
  89. captchaFail() {
  90. // app端的回调
  91. toast('验证失败!')
  92. },
  93. captchaClose() {
  94. uni.redirectTo({
  95. url: `/pages/login/index`
  96. })
  97. },
  98. loginInit(options) {
  99. this.loginData.phoneNumber = options.telNum;
  100. },
  101. getYzmBtn() {
  102. let req = {
  103. phone: this.loginData.phoneNumber,
  104. captchaOutput: this.sliderData.captcha_output,
  105. genTime: this.sliderData.gen_time,
  106. lotNumber: this.sliderData.lot_number,
  107. passToken: this.sliderData.pass_token,
  108. }
  109. console.log('req', req);
  110. sendCode(req).then(res => {
  111. })
  112. },
  113. loginBtn() {
  114. let req = {
  115. tel: this.loginData.phoneNumber,
  116. code: this.loginData.yzmNumber,
  117. }
  118. login(req).then(res => {
  119. if (res.code == 0) {
  120. cacheManager.set('auth', res.data)
  121. uni.switchTab({
  122. url: `/pages/chanpinXuanze/index`
  123. })
  124. }
  125. })
  126. },
  127. clearYzmInput(event) {
  128. if (event.detail.value.length > 0) {
  129. this.loginData.clearYzmIcon = true;
  130. this.loginData.yzmStatus = 'login-btn-normal';
  131. } else {
  132. this.loginData.clearYzmIcon = false;
  133. this.loginData.yzmStatus = 'login-btn-disabled';
  134. }
  135. },
  136. clearYzm() {
  137. this.loginData.yzmNumber = '';
  138. this.loginData.yzmStatus = 'login-btn-disabled';
  139. this.loginData.clearYzmIcon = false;
  140. },
  141. startCountdown() {
  142. if (this.loginData.buttonText === '重新发送') {
  143. this.$refs.captcha.showCaptcha();
  144. }
  145. this.loginData.isDisabled = true;
  146. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  147. // 清除之前的定时器(如果有)
  148. if (this.loginData.intervalId) {
  149. clearInterval(this.loginData.intervalId);
  150. }
  151. // 设置新的定时器
  152. this.loginData.intervalId = setInterval(() => {
  153. this.loginData.timeLeft--;
  154. if (this.loginData.timeLeft <= 0) {
  155. clearInterval(this.loginData.intervalId);
  156. this.loginData.timeLeft = 60; // 重置倒计时
  157. this.loginData.isDisabled = false;
  158. this.loginData.buttonText = '重新发送';
  159. } else {
  160. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  161. }
  162. }, 1000);
  163. },
  164. goIndex() {
  165. uni.redirectTo({
  166. url: `/pages/login/index`
  167. })
  168. }
  169. },
  170. mounted() {
  171. this.$refs.captcha.showCaptcha();
  172. },
  173. }
  174. </script>