login.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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">登录</ezyActiveVue>
  14. <text class="cxfs-btn" @click="startCountdown"
  15. :class="{ 'cxfs-btn-disabled': loginData.isDisabled}">{{loginData.buttonText}}</text>
  16. <text class="login-text" @click="goIndex">无法收到验证码</text>
  17. <text class="login-text">客服电话:<text>4001750778</text></text>
  18. </view>
  19. </view>
  20. <captcha ref="captcha" :config="config" @captchaSuccess="captchaSuccess" @captchaError="captchaError"
  21. @captchaFail="captchaFail" @captchaReady="captchaReady" @captchaClose="captchaClose"></captcha>
  22. </view>
  23. </template>
  24. <script>
  25. import {
  26. ref,
  27. reactive
  28. } from "vue"
  29. import {
  30. login,
  31. sendCode,
  32. banbenImpinfo
  33. } from "@/api/login.js"
  34. import cacheManager from "@/utils/cacheManager.js";
  35. import captcha from "../../components/captcha4/index.vue";
  36. import {
  37. toast,
  38. getUserIdentity
  39. } from "@/utils/common";
  40. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  41. export default {
  42. data() {
  43. return {
  44. loginData: {
  45. phoneNumber: null,
  46. yzmNumber: null,
  47. clearYzmIcon: false,
  48. yzmStatus: 'login-btn-disabled',
  49. timeLeft: 60, // 初始倒计时时间(秒)
  50. intervalId: null, // 定时器ID
  51. isDisabled: false, // 按钮是否禁用
  52. buttonText: '', // 按钮文本
  53. },
  54. sliderData: {},
  55. sliderDialogRef: null,
  56. config: {
  57. captchaId: "9d5837b0807b8de44da0de310a0b2813",
  58. },
  59. banbenId: '',
  60. chanpinId: '',
  61. danyuanId:'',
  62. dengjiId:''
  63. }
  64. },
  65. components: {
  66. captcha,ezyActiveVue
  67. },
  68. onLoad(options) {
  69. this.loginInit(options);
  70. },
  71. onReady() {},
  72. methods: {
  73. captchaSuccess(result) { // app端的回调
  74. console.log(result)
  75. this.startCountdown();
  76. this.sliderData = result;
  77. this.getYzmBtn();
  78. },
  79. captchaError(e) {
  80. // app端的回调、
  81. console.log('error', JSON.stringify(e));
  82. toast(JSON.stringify(e))
  83. },
  84. captchaReady() {
  85. // app端的回调
  86. },
  87. captchaFail() {
  88. // app端的回调
  89. toast('验证失败!')
  90. },
  91. captchaClose() {
  92. uni.redirectTo({
  93. url: `/pages/login/index`
  94. })
  95. },
  96. loginInit(options) {
  97. this.loginData.phoneNumber = options.telNum;
  98. },
  99. getYzmBtn() {
  100. let req = {
  101. phone: this.loginData.phoneNumber,
  102. captchaOutput: this.sliderData.captcha_output,
  103. genTime: this.sliderData.gen_time,
  104. lotNumber: this.sliderData.lot_number,
  105. passToken: this.sliderData.pass_token,
  106. }
  107. console.log('req', req);
  108. sendCode(req).then(res => {
  109. })
  110. },
  111. loginBtn() {
  112. let req = {
  113. tel: this.loginData.phoneNumber,
  114. code: this.loginData.yzmNumber,
  115. }
  116. login(req).then(res => {
  117. if (res.code == 0) {
  118. cacheManager.set('auth', res.data)
  119. setTimeout(() => {
  120. banbenImpinfo({}).then(res => {
  121. if (res.code == 0) {
  122. console.log('banbenImpinfores',res);
  123. this.banbenId = res.data.banbenId
  124. this.chanpinId = res.data.chanpinId
  125. this.danyuanId = res.data.danyuanId
  126. this.dengjiId = res.data.dengjiId
  127. cacheManager.updateObject("auth",{
  128. banbenId:res.data.banbenId,
  129. chanpinId:res.data.chanpinId,
  130. danyuanId:res.data.danyuanId,
  131. dengjiId:res.data.dengjiId,
  132. })
  133. if(this.chanpinId ==0){
  134. // 没学过
  135. uni.switchTab({
  136. url: `/pages/chanpinXuanze/index`
  137. })
  138. }else{
  139. if (cacheManager.get('xuexi-shuxue')) {
  140. cacheManager.remove("xuexi-shuxue")
  141. }
  142. // 学过直接到学习页面
  143. uni.switchTab({
  144. url: `/pages/chanpinneirong/index`,
  145. })
  146. }
  147. }
  148. }).catch(() => {
  149. toast('banbenImpinfo出错')
  150. return false
  151. })
  152. })
  153. }
  154. })
  155. },
  156. clearYzmInput(event) {
  157. if (event.detail.value.length > 0) {
  158. this.loginData.clearYzmIcon = true;
  159. this.loginData.yzmStatus = 'login-btn-normal';
  160. } else {
  161. this.loginData.clearYzmIcon = false;
  162. this.loginData.yzmStatus = 'login-btn-disabled';
  163. }
  164. },
  165. clearYzm() {
  166. this.loginData.yzmNumber = '';
  167. this.loginData.yzmStatus = 'login-btn-disabled';
  168. this.loginData.clearYzmIcon = false;
  169. },
  170. startCountdown() {
  171. if (this.loginData.buttonText === '重新发送') {
  172. this.$refs.captcha.showCaptcha();
  173. }
  174. this.loginData.isDisabled = true;
  175. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  176. // 清除之前的定时器(如果有)
  177. if (this.loginData.intervalId) {
  178. clearInterval(this.loginData.intervalId);
  179. }
  180. // 设置新的定时器
  181. this.loginData.intervalId = setInterval(() => {
  182. this.loginData.timeLeft--;
  183. if (this.loginData.timeLeft <= 0) {
  184. clearInterval(this.loginData.intervalId);
  185. this.loginData.timeLeft = 60; // 重置倒计时
  186. this.loginData.isDisabled = false;
  187. this.loginData.buttonText = '重新发送';
  188. } else {
  189. this.loginData.buttonText = `重新发送(${this.loginData.timeLeft}S)`;
  190. }
  191. }, 1000);
  192. },
  193. goIndex() {
  194. uni.redirectTo({
  195. url: `/pages/login/index`
  196. })
  197. }
  198. },
  199. mounted() {
  200. this.$refs.captcha.showCaptcha();
  201. },
  202. }
  203. </script>