import '../style/style'; import '../style/login'; import $ from 'jquery'; import { fail } from 'assert'; let code = ''; let num = 10; let flag = true; $('.jurisdiction').hide(); if(window.localStorage.getItem('uid')) { $('.login').hide(); $('.jurisdiction').show(); } $('#sendCode').click(function () { const phoneNum = $('#phoneNum').val().replace(/\s/ig,''); if(proving(phoneNum) && flag) { // 调用获取验证码接口 $.get(`${process.env.BASE_API}sharedWhiteBoard/wx/user/sendMag`, { phoneNum }, function (res) { if(res.code == 200) { code = res.data; time(); } }); } }) $('#login').click(function () { const mobile = $('#phoneNum').val().replace(/\s/ig,''); const sign = $('#phoneCode').val().replace(/\s/ig,''); // if(sign == code) { if(proving(mobile)) { $.ajax({ url:`${process.env.BASE_API}sharedWhiteBoard/wx/user/loginByPhone`, type: 'POST', data: JSON.stringify({ mobile, sign }), contentType: "application/json", dataType: "json", success: function (res) { console.log(res) if(res.code == 200) { console.log(res.data.id) window.localStorage.setItem('uid', res.data.id); $('.login').hide(); $('.jurisdiction').show(); }else if (res.code == 600) { console.log(res.message); alert(res.message) } } }); } // }else { // alert('验证码错误') // } }) //创建远程观看 $('#ok').click(function () { const title = $('#title').val().replace(/\s/ig,''); const code = $('.auth-code').val().replace(/\s/ig,''); const uid = window.localStorage.getItem('uid'); if(!title) { alert('请输入分会场名称') return; } if(!code) { alert('请输入授权码') return; } $.ajax({ url:`${process.env.BASE_API}sharedWhiteBoard/shareJoin`, type: 'POST', data: JSON.stringify({ uid, title, code }), contentType: "application/json", dataType: "json", success: function (res) { if(res.code == 200) { const shareTask = JSON.stringify(res.data); window.sessionStorage.setItem('dataList', shareTask); window.location.href="./index.html" }else if (res.code == 600) { console.log(res.message) alert(res.message) } } }); }) // 倒计时 const time = function () { setTimeout(function () { flag = false; $('#sendCode').html(`${num}秒后重新发送`).addClass('color'); num--; if(num > 0) { time(); }else { num = 10; flag = true; $('#sendCode').html('发送验证码').removeClass('color') } },1000) } // 验证手机号码 const proving = (phone) => { // 手机号正则 const telStr = /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/; if (!(telStr.test(phone))) { alert('手机号码输入不规范'); return false; } return true; }