Browse Source

增加回车登录

limengbo 4 years ago
parent
commit
e3fa1c94c4
1 changed files with 85 additions and 0 deletions
  1. 85 0
      src/js/login.js

+ 85 - 0
src/js/login.js

@@ -10,6 +10,21 @@ if(localStorage.getItem('uid')) {
   $('.login').hide();
   $('.jurisdiction').show();
 }
+$('#phoneNum').keydown((event) => {
+  const phoneNum = $('#phoneNum').val().replace(/\s/ig,'');
+  if (event.keyCode === 13 && proving(phoneNum) && flag) {
+    // 调用获取验证码接口
+    $.get(`${process.env.BASE_API}sharedWhiteBoard/wx/user/sendMag`, {
+      phoneNum
+    }, function (res) {
+      if(res.code == 200) {
+        code = res.data;
+        $('#phoneCode').focus()
+        time();
+      }
+    });
+  }
+})
 $('#sendCode').click(function () {
   const phoneNum = $('#phoneNum').val().replace(/\s/ig,'');
   if(proving(phoneNum) && flag) {
@@ -24,6 +39,34 @@ $('#sendCode').click(function () {
     });
   }
 })
+$('#phoneCode').keydown((event) => {
+  const mobile = $('#phoneNum').val().replace(/\s/ig,'');
+  const sign = $('#phoneCode').val().replace(/\s/ig,'');
+  if (event.keyCode === 13 && 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)
+          localStorage.setItem('uid', res.data.id);
+          $('.login').hide();
+          $('.jurisdiction').show();
+        }else if (res.code == 600) {
+          console.log(res.message);
+          alert(res.message)
+        }
+      }
+    });
+  }
+})
 $('#login').click(function () {
   const mobile = $('#phoneNum').val().replace(/\s/ig,'');
   const sign = $('#phoneCode').val().replace(/\s/ig,'');
@@ -56,6 +99,48 @@ $('#login').click(function () {
   //   alert('验证码错误')
   // }
 })
+$('#title').keydown((event) => {
+  const title = $('#title').val().replace(/\s/ig,'');
+  if (event.keyCode === 13 && title) {
+    $('.auth-code').focus();
+  }
+})
+$('.auth-code').keydown((event) => {
+  const title = $('#title').val().replace(/\s/ig,'');
+  const code = $('.auth-code').val().replace(/\s/ig,'');
+  const uid = window.localStorage.getItem('uid');
+  if (event.keyCode === 13) {
+    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)
+        }
+      }
+    });
+  }
+})
 //创建远程观看
 $('#ok').click(function () {
   const title = $('#title').val().replace(/\s/ig,'');