login.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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="请输入验证码" maxlength="6"
  9. @input="clearYzmInput" />
  10. <view class="close-btn" v-if="loginData.clearYzmIcon" @click="clearYzm"></view>
  11. </view>
  12. <view class="login-btn login-btn-disabled" @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"></sliderDialog>
  20. </view>
  21. </template>
  22. <script setup>
  23. import {ref,reactive} from "vue"
  24. import {onLoad,onReady} from '@dcloudio/uni-app';
  25. import request from "@/utils/request.js"
  26. import {login,sendCode} from "@/api/login.js"
  27. import sliderDialog from './sliderDialog.vue'
  28. const loginData = reactive({
  29. phoneNumber: null,
  30. yzmNumber: null,
  31. clearYzmIcon: false,
  32. yzmStatus: '',
  33. timeLeft: 60, // 初始倒计时时间(秒)
  34. intervalId: null, // 定时器ID
  35. isDisabled: false, // 按钮是否禁用
  36. buttonText: '重新发送', // 按钮文本
  37. })
  38. const sliderData = reactive({})
  39. const sliderDialogRef = ref(null);
  40. onLoad((options) => {
  41. loginInit(options);
  42. startCountdown();
  43. getYzmBtn();
  44. })
  45. onReady((options) => {
  46. console.log(sliderDialogRef.value,'sliderDialogRef.value');
  47. sliderDialogRef.value.sliderShow();
  48. })
  49. const loginInit = (options) => {
  50. loginData.phoneNumber = options.telNum;
  51. }
  52. const getYzmBtn = () => {
  53. let req = {
  54. appkey: "FFFF0N00000000007EC0",
  55. phone: "18640920672",
  56. scene: "nc_message_h5',",
  57. sessionid: sliderData.sessionId,
  58. sig: sliderData.sig,
  59. token: sliderData.token,
  60. }
  61. sendCode(req).then(res => {
  62. })
  63. }
  64. const loginBtn = () => {
  65. let req = {
  66. tel: "1",
  67. code: '1'
  68. }
  69. login(req).then(res => {
  70. if (res.code == 0) {
  71. let obj = JSON.stringify(res.data)
  72. console.log(obj)
  73. uni.setStorage({
  74. key: 'Mta-Auth',
  75. data: obj // 假设 this.userInputValue 是用户输入的数据
  76. });
  77. uni.navigateTo({
  78. url: `/pages/study/index?gradeId=${obj.orgId}&termId=${obj.userId}&text='测试111'`
  79. })
  80. }
  81. })
  82. // uni.navigateTo({
  83. // url: `/pages/study/index?gradeId=${options.grade}&termId=${options.term}&text=${text1}${text2}`
  84. // })
  85. }
  86. const clearYzmInput = (event) => {
  87. if (event.detail.value.length > 0) {
  88. loginData.clearYzmIcon = true;
  89. } else {
  90. loginData.clearYzmIcon = false;
  91. }
  92. }
  93. const clearYzm = () => {
  94. loginData.yzmNumber = '';
  95. loginData.clearYzmIcon = false;
  96. }
  97. const startCountdown = () => {
  98. loginData.isDisabled = true;
  99. loginData.buttonText = `重新发送(${loginData.timeLeft}S)`;
  100. // 清除之前的定时器(如果有)
  101. if (loginData.intervalId) {
  102. clearInterval(loginData.intervalId);
  103. }
  104. // 设置新的定时器
  105. loginData.intervalId = setInterval(() => {
  106. loginData.timeLeft--;
  107. if (loginData.timeLeft <= 0) {
  108. clearInterval(loginData.intervalId);
  109. loginData.timeLeft = 60; // 重置倒计时
  110. loginData.isDisabled = false;
  111. loginData.buttonText = '重新发送';
  112. } else {
  113. loginData.buttonText = `重新发送(${loginData.timeLeft}S)`;
  114. }
  115. }, 1000);
  116. }
  117. const goIndex = () => {
  118. uni.navigateTo({
  119. url: `/pages/login/index?data=`+JSON.stringify(sliderData)
  120. })
  121. }
  122. </script>