login.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. left-text="返回"
  19. left-arrow
  20. @click-left="onBack"
  21. >
  22. <template #title>
  23. <span class="text-white">登录</span>
  24. </template>
  25. </van-nav-bar>
  26. <van-tabs v-model:active="active">
  27. <van-tab title="验证码登录">
  28. <van-form @submit="onSubmit('mobile')">
  29. <van-cell-group>
  30. <van-field
  31. v-model="mobile"
  32. required
  33. label="电话"
  34. placeholder="请输入电话"
  35. :rules="[
  36. { required: true, message: '请填写电话' },
  37. { validator, message: '请输入正确的手机号'}
  38. ]"
  39. ></van-field>
  40. <van-field
  41. v-model="verify"
  42. required
  43. center
  44. clearable
  45. label="短信验证码"
  46. placeholder="请输入短信验证码"
  47. :rules="[{ required: true, message: '请填写短信验证码' }]"
  48. >
  49. <template #button>
  50. <van-button size="small" :disabled="second != 60" type="primary" @click="sendSms">{{second_text}}</van-button>
  51. </template>
  52. </van-field>
  53. </van-cell-group>
  54. <div style="margin: 16px;">
  55. <van-button block type="primary" native-type="submit">确定</van-button>
  56. </div>
  57. </van-form>
  58. </van-tab>
  59. <van-tab title="密码登录">
  60. <van-form @submit="onSubmit('account')">
  61. <van-cell-group>
  62. <van-field
  63. v-model="account"
  64. required
  65. label="账号"
  66. placeholder="请输入账号"
  67. :rules="[{ required: true, message: '请填写账号' }]"
  68. ></van-field>
  69. <van-field
  70. v-model="password"
  71. type="password"
  72. required
  73. label="密码"
  74. placeholder="请输入密码"
  75. :rules="[{ required: true, message: '请填写密码' }]"
  76. ></van-field>
  77. </van-cell-group>
  78. <div style="margin: 16px;">
  79. <van-button block type="primary" native-type="submit">确定</van-button>
  80. </div>
  81. </van-form>
  82. </van-tab>
  83. </van-tabs>
  84. <div class="other-login">
  85. <van-divider>其他登录方式</van-divider>
  86. <div class="other-login-icon">
  87. <van-image width="40" height="40" src="__COMMON_IMAGES__/icon_wechat.png" @click="wechatLogin"></van-image>
  88. </div>
  89. </div>
  90. <van-popup
  91. v-model:show="service_show"
  92. position="bottom"
  93. round
  94. :style="{ height: '80%' }"
  95. >
  96. <div class="lw-title">用户协议</div>
  97. <div class="content">
  98. {$service.service}
  99. </div>
  100. </van-popup>
  101. <van-popup
  102. v-model:show="privacy_show"
  103. position="bottom"
  104. round
  105. :style="{ height: '80%' }"
  106. >
  107. <div class="lw-title">隐私政策</div>
  108. <div class="content">
  109. {$service.privacy}
  110. </div>
  111. </van-popup>
  112. <div class="service">
  113. <van-checkbox v-model="service_check" shape="square" icon-size="14px">
  114. 同意
  115. <a href="javascript:void(0);" @click.stop="showService('service_show')">《用户协议》</a>
  116. <a href="javascript:void(0);" @click.stop="showService('privacy_show')">《隐私政策》</a>
  117. <!--<a href="{:url('index/singlePage')}?field=privacy">《隐私政策》</a>-->
  118. </van-checkbox>
  119. </div>
  120. {/block}
  121. {block name="script"}
  122. <script>
  123. function v_setup() {
  124. let base = {};
  125. base.onBack = () => {
  126. location.href = "{:url('/')}";
  127. };
  128. base.active = Vue.ref(0);
  129. base.service_check = Vue.ref(false);
  130. base.service_show = Vue.ref(false);
  131. base.privacy_show = Vue.ref(false);
  132. base.mobile = Vue.ref('');
  133. base.verify = Vue.ref('');
  134. base.account = Vue.ref('');
  135. base.password = Vue.ref('');
  136. //短信验证码
  137. base.is_send = false;
  138. base.second = Vue.ref(60);
  139. base.set = null;
  140. base.sendSms = () => {
  141. if (base.is_send) {
  142. return false;
  143. }
  144. if (base.mobile.value === '') {
  145. vant.showToast('请输入电话');
  146. return false;
  147. }
  148. base.is_send = true;
  149. postJson("{:url('login/sendSms')}", {mobile:base.mobile.value},({msg})=>{
  150. vant.showToast(msg);
  151. base.is_send = false;
  152. }).then(() => {
  153. base.set = setInterval(function(){
  154. base.second.value--;
  155. if (base.second.value === 0) {
  156. base.second.value = 60;
  157. base.is_send = false;
  158. clearInterval(base.set);
  159. }
  160. },1000);
  161. });
  162. };
  163. base.second_text = Vue.computed(()=>{
  164. if (base.second.value === 60) {
  165. return '发送验证码';
  166. } else {
  167. return `${base.second.value}秒`;
  168. }
  169. });
  170. //登录
  171. base.onSubmit = (type) => {
  172. if (!base.service_check.value) {
  173. vant.showToast('请勾选协议');
  174. return false;
  175. }
  176. let param = {};
  177. if (type === 'mobile') {
  178. param = {type:'mobile',mobile:base.mobile.value,verify:base.verify.value};
  179. } else if (type === 'account') {
  180. param = {type:'account',account:base.account.value,password:base.password.value};
  181. }
  182. postJson("{:url('login/loginPost')}", param).then(({data}) => {
  183. location.href = data.url;
  184. });
  185. };
  186. base.wechatLogin = () => {
  187. if (!base.service_check.value) {
  188. vant.showToast('请勾选协议');
  189. return false;
  190. }
  191. location.href = "{:url('login/wechat')}";
  192. };
  193. //协议
  194. base.showService = (value) => {
  195. base[value].value = true;
  196. };
  197. //手机号验证
  198. base.validator = (val) => {
  199. return /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/.test(val);
  200. }
  201. return base;
  202. }
  203. </script>
  204. {/block}