mobile.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. {extend name="public/base"/}
  2. {block name="css"}
  3. <style>
  4. .other-login {width:60%;margin:50px auto 0 auto;}
  5. .other-login .other-login-icon{display:flex;align-items:center;justify-content:space-around;}
  6. .service {display: flex;justify-content: center;text-align:center;margin-top:50px;font-size:14px;}
  7. .service a {color:#0081ff;}
  8. .lw-title {font-size:18px;text-align:center;font-weight:bold;padding-top:10px;}
  9. .content {width:100%;padding-top:10px;}
  10. .content p {padding:0;margin:0;text-indent:2em;}
  11. </style>
  12. {/block}
  13. {block name="body"}
  14. <van-nav-bar
  15. class="nav-theme"
  16. :fixed="true"
  17. :placeholder="true"
  18. >
  19. <template #title>
  20. <span class="text-white">登录</span>
  21. </template>
  22. </van-nav-bar>
  23. <van-form @submit="onSubmit">
  24. <van-cell-group>
  25. <van-field
  26. v-model="mobile"
  27. required
  28. label="电话"
  29. placeholder="请输入电话"
  30. :rules="[
  31. { required: true, message: '请填写电话' },
  32. { validator, message: '请输入正确的手机号'}
  33. ]"
  34. ></van-field>
  35. <van-field
  36. v-model="verify"
  37. required
  38. center
  39. clearable
  40. label="短信验证码"
  41. placeholder="请输入短信验证码"
  42. :rules="[{ required: true, message: '请填写短信验证码' }]"
  43. >
  44. <template #button>
  45. <van-button size="small" :disabled="second != 60" type="primary" @click="sendSms">{{second_text}}</van-button>
  46. </template>
  47. </van-field>
  48. </van-cell-group>
  49. <div style="margin: 16px;">
  50. <van-button block type="primary" native-type="submit">确定</van-button>
  51. </div>
  52. </van-form>
  53. {/block}
  54. {block name="script"}
  55. <script>
  56. function v_setup() {
  57. let base = {};
  58. base.mobile = Vue.ref('');
  59. base.verify = Vue.ref('');
  60. //短信验证码
  61. base.is_send = false;
  62. base.second = Vue.ref(60);
  63. base.set = null;
  64. base.sendSms = () => {
  65. if (base.is_send) {
  66. return false;
  67. }
  68. if (base.mobile.value === '') {
  69. vant.showToast('请输入电话');
  70. return false;
  71. }
  72. base.is_send = true;
  73. postJson("{:url('login/sendSms')}", {mobile:base.mobile.value},({msg})=>{
  74. vant.showToast(msg);
  75. base.is_send = false;
  76. }).then(() => {
  77. base.set = setInterval(function(){
  78. base.second.value--;
  79. if (base.second.value === 0) {
  80. base.second.value = 60;
  81. base.is_send = false;
  82. clearInterval(base.set);
  83. }
  84. },1000);
  85. });
  86. };
  87. base.second_text = Vue.computed(()=>{
  88. if (base.second.value === 60) {
  89. return '发送验证码';
  90. } else {
  91. return `${base.second.value}秒`;
  92. }
  93. });
  94. //登录
  95. base.onSubmit = () => {
  96. const param = {mobile:base.mobile.value,verify:base.verify.value};
  97. postJson("{:url('login/mobilePost')}", param).then(({data}) => {
  98. location.href = data.url;
  99. });
  100. };
  101. //手机号验证
  102. base.validator = (val) => {
  103. return /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/.test(val);
  104. };
  105. return base;
  106. }
  107. </script>
  108. {/block}