index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view class="ezy-login-page">
  3. <view class="ezy-login-wrap" >
  4. <!-- 手机号 -->
  5. <view class="login-body-box">
  6. <view class="index-title-img"></view>
  7. <view class="phone-input-box">
  8. <view class="phone-prefix">+86</view>
  9. <input class="phone-input" type="text" v-model="data.phoneNumber" placeholder="请输入手机号"
  10. maxlength="11" @input="clearTelInput" />
  11. <view class="close-btn" v-if="data.clearTelIcon" @click="clearTel"></view>
  12. </view>
  13. <view id="yzm-slider"></view>
  14. <!-- 协议勾选框和按钮 -->
  15. <view class="agreement-checkbox-box">
  16. <checkbox class="agreement-checkbox-input" color="#FFFFFF" :checked="data.isAgreed" @change="handleAgreementChange"/>
  17. <view class="agreement-text-box">
  18. 我已阅读并同意<view class="agreement-text">《用户协议》</view>和<view class="agreement-text">《隐私政策》</view>
  19. </view>
  20. </view>
  21. <view class="login-btn yzm-btn-disabled" @click="getYzmBtn" :class="data.telStatus"></view>
  22. </view>
  23. <view class="wx-btn-img"></view>
  24. </view>
  25. </view>
  26. </template>
  27. <script setup>
  28. import {
  29. ref,
  30. reactive
  31. } from "vue"
  32. import { onLoad,onReady } from '@dcloudio/uni-app';
  33. const data = reactive({
  34. phoneNumber: null,
  35. clearTelIcon: false,
  36. telStatus:'',
  37. isAgreed: false,
  38. })
  39. onLoad((options) => {
  40. getAWSC();
  41. })
  42. const getAWSC = () => {
  43. AWSC.use("nc", function (state, module) {
  44. // 初始化
  45. window.nc = module.init({
  46. // 应用类型标识。它和使用场景标识(scene字段)一起决定了滑动验证的业务场景与后端对应使用的策略模型。您可以在阿里云验证码控制台的配置管理页签找到对应的appkey字段值,请务必正确填写。
  47. appkey: "FFFF0N00000000007EC0",
  48. //使用场景标识。它和应用类型标识(appkey字段)一起决定了滑动验证的业务场景与后端对应使用的策略模型。您可以在阿里云验证码控制台的配置管理页签找到对应的scene值,请务必正确填写。
  49. scene: "nc_message_h5",
  50. // 声明滑动验证需要渲染的目标ID。
  51. renderTo: "yzm-slider",
  52. //前端滑动验证通过时会触发该回调参数。您可以在该回调参数中将会话ID(sessionId)、签名串(sig)、请求唯一标识(token)字段记录下来,随业务请求一同发送至您的服务端调用验签。
  53. success: function (data) {
  54. window.console && console.log(data.sessionId)
  55. window.console && console.log(data.sig)
  56. window.console && console.log(data.token)
  57. },
  58. // 滑动验证失败时触发该回调参数。
  59. fail: function (failCode) {
  60. window.console && console.log('失败:'+failCode)
  61. },
  62. // 验证码加载出现异常时触发该回调参数。
  63. error: function (errorCode) {
  64. window.console && console.log('异常:'+ errorCode)
  65. }
  66. });
  67. })
  68. }
  69. const getYzmBtn = () => {
  70. uni.navigateTo({
  71. url: `/pages/login/login?telNum=${data.phoneNumber}`
  72. })
  73. }
  74. // 手机号校验规则
  75. const validatePhoneNumber = (value) => {
  76. const phoneRegex = /^1[3-9]\d{9}$/;
  77. if (phoneRegex.test(value)) {
  78. console.log('手机号格式正确');
  79. data.telStatus = 'yzm-btn-normal';
  80. } else {
  81. console.log('手机号格式不正确');
  82. }
  83. }
  84. const clearTelInput = (event) => {
  85. if (event.detail.value.length > 0) {
  86. data.clearTelIcon = true;
  87. validatePhoneNumber(event.detail.value);
  88. } else {
  89. data.clearTelIcon = false;
  90. }
  91. }
  92. const clearTel = () => {
  93. data.phoneNumber = '';
  94. data.telStatus = 'yzm-btn-disabled';
  95. data.clearTelIcon = false;
  96. }
  97. const handleAgreementChange= () => {
  98. console.log(data.isAgreed,'data.isAgreed');
  99. if(data.isAgreed){
  100. data.isAgreed = !data.isAgreed;
  101. }
  102. }
  103. </script>