浏览代码

验证码图片显示

1178232204@qq.com 3 年之前
父节点
当前提交
914c4b9dad
共有 1 个文件被更改,包括 100 次插入101 次删除
  1. 100 101
      src/js/login.js

+ 100 - 101
src/js/login.js

@@ -22,106 +22,105 @@ $(function () {
       sureLogin()
     }
   });
-  
-  
+
+
 });
 
 //获取验证码
 function getSecurityCode() {
-    $.ajax({
-        url:api.getCaptcha,
-        method:'get',
-        responseType:'blob',
-        success:function(res){
-            console.log('success');
-            const img = document.createElement("img");
-            const qrUrl = window.URL.createObjectURL(new Blob([res],{type:'image/png'}));
-            img.src = qrUrl;
-            //释放对象
-            img.onload=function(){
-                console.log('释放')
-                window.URL.revokeObjectURL(qrUrl)
-            }
-            const imgDiv = document.getElementById("codeImg");
-            $(imgDiv).html(img);
-        },
-        error:function(error){
-            console.log('error:',error)
-        }
-    })
+  var windowUrl = window.URL || window.webkitURL;//处理浏览器兼容性
+  var xhr = new XMLHttpRequest();
+  var url = api.getCaptcha;//验证码请求地址
+  xhr.open("GET", url, true);
+  xhr.responseType = "blob";
+  xhr.onload = function () {
+    if (this.status == 200) {
+      var blob = this.response;
+      const img = document.createElement("img");
+      const qrUrl = window.URL.createObjectURL(blob);
+      img.src = qrUrl;
+      //释放对象
+      img.onload = function () {
+        console.log('释放')
+        window.URL.revokeObjectURL(qrUrl)
+      }
+      const imgDiv = document.getElementById("codeImg");
+      $(imgDiv).html(img);
+    }
+  }
+  xhr.send();
 }
-
 function getHospitalMark() {
   localStorage.removeItem('accessToken')
   //post(api.getHospitalMark).then((res) => {
-    const data = {code:0,data:0}//res.data;
-    if (data.code == 0) {
-      type = parseInt(data.data)
-      if (parseInt(data.data) == 1) {   //湘雅三院登录样式
-        str = '<div class="bg2">'
-        str += '<div class="login-info">'
-        str += '<div class="info-perPub">'
-        str += ' <p> 用户名:</p>'
-        str += '<div class="info-iptWrap">'
-        str += '<input type="text" placeholder="请输入用户名" id="username" value="" autocomplete="off">'
-        str += '</div></div>'
-        str += '<div class="info-perPub">'
-        str += ' <p> 密码:</p>'
-        str += '<div class="info-iptWrap">'
-        str += '<input type="text" placeholder="请输入密码" id="password" value="" autocomplete="off">'
-        str += '</div></div>'
-        str += '<p class="waring"></p><div class="sureLogin">登录</div></div>'
+  const data = { code: 0, data: 0 }//res.data;
+  if (data.code == 0) {
+    type = parseInt(data.data)
+    if (parseInt(data.data) == 1) {   //湘雅三院登录样式
+      str = '<div class="bg2">'
+      str += '<div class="login-info">'
+      str += '<div class="info-perPub">'
+      str += ' <p> 用户名:</p>'
+      str += '<div class="info-iptWrap">'
+      str += '<input type="text" placeholder="请输入用户名" id="username" value="" autocomplete="off">'
+      str += '</div></div>'
+      str += '<div class="info-perPub">'
+      str += ' <p> 密码:</p>'
+      str += '<div class="info-iptWrap">'
+      str += '<input type="text" placeholder="请输入密码" id="password" value="" autocomplete="off">'
+      str += '</div></div>'
+      str += '<p class="waring"></p><div class="sureLogin">登录</div></div>'
+      $('.login').html(str)
+    } else {    //通用版样式
+      str = '<div class="bg fl"><p class="title">AI病案质控平台</p></div>'
+      str += '<div class="message fr"><div class="inner"><p class="welcome">欢迎使用!</p>'
+      str += '<div class="perPub">'
+      str += ' <p> 用户名:</p>'
+      str += '<div class="iptWrap">'
+      str += '<input type="text" placeholder="请输入用户名" id="username" value="" autocomplete="off">'
+      str += '</div></div><br>'
+      str += '<div class="perPub">'
+      str += ' <p> 密码:</p>'
+      str += '<div class="iptWrap">'
+      str += '<input type="text" placeholder="请输入密码" id="password" value="" autocomplete="off">'
+      str += '</div></div><br>'
+      str += '<div class="perPub">'
+      str += ' <p> 验证码:</p>'
+      str += '<div class="iptWrap security-code">'
+      str += '<input type="text" placeholder="请输入验证码" id="code" value="" autocomplete="off">'
+      str += '<div id="codeImg" class="code-img"></div>'
+      str += '<a id="changeCode" >换一张</a>'
+      str += '</div></div>'
+      str += '<p class="waring"></p><div class="sureLogin">登录</div></div><div class="copy-right">由杭州朗通信息技术有限公司提供技术支持</div></div>',
         $('.login').html(str)
-      } else {    //通用版样式
-        str = '<div class="bg fl"><p class="title">AI病案质控平台</p></div>'
-        str += '<div class="message fr"><div class="inner"><p class="welcome">欢迎使用!</p>'
-        str += '<div class="perPub">'
-        str += ' <p> 用户名:</p>'
-        str += '<div class="iptWrap">'
-        str += '<input type="text" placeholder="请输入用户名" id="username" value="" autocomplete="off">'
-        str += '</div></div><br>'
-        str += '<div class="perPub">'
-        str += ' <p> 密码:</p>'
-        str += '<div class="iptWrap">'
-        str += '<input type="text" placeholder="请输入密码" id="password" value="" autocomplete="off">'
-        str += '</div></div><br>'
-        str += '<div class="perPub">'
-        str += ' <p> 验证码:</p>'
-        str += '<div class="iptWrap security-code">'
-        str += '<input type="text" placeholder="请输入验证码" id="code" value="" autocomplete="off">'
-        str += '<div id="codeImg" class="code-img"></div>'
-        str += '<a id="changeCode" >换一张</a>'
-        str += '</div></div>'
-        str += '<p class="waring"></p><div class="sureLogin">登录</div></div><div class="copy-right">由杭州朗通信息技术有限公司提供技术支持</div></div>',
-        $('.login').html(str)
-      }
-      getSecurityCode();
-      $(".sureLogin").click(() => {
-        sureLogin()
-      })
-        //点击换一张事件
-        $("#codeImg,#changeCode").click(function(){
-            getSecurityCode();
-        })
-      $("#password").focus(function () {
-        $(this).attr("type", "password")
-      })
-      $(".iptWrap:not(.security-code) input").focus(function () {
-        $(this).parent().addClass('inputFocus')
-      })
-      $(".security-code input").focus(function () {
-          $(this).addClass('inputFocus')
-      })
-      $(".iptWrap input").blur(function () {
-        $(this).parent().removeClass('inputFocus')
-        $(this).removeClass('inputFocus')
-      })
-      $("body").on('input', '#username,#password', function () {
-        if ($(this).val().trim() != '') {
-          $(".login .waring").html('')
-        }
-      })
     }
+    getSecurityCode();
+    $(".sureLogin").click(() => {
+      sureLogin()
+    })
+    //点击换一张事件
+    $("#codeImg,#changeCode").click(function () {
+      getSecurityCode();
+    })
+    $("#password").focus(function () {
+      $(this).attr("type", "password")
+    })
+    $(".iptWrap:not(.security-code) input").focus(function () {
+      $(this).parent().addClass('inputFocus')
+    })
+    $(".security-code input").focus(function () {
+      $(this).addClass('inputFocus')
+    })
+    $(".iptWrap input").blur(function () {
+      $(this).parent().removeClass('inputFocus')
+      $(this).removeClass('inputFocus')
+    })
+    $("body").on('input', '#username,#password', function () {
+      if ($(this).val().trim() != '') {
+        $(".login .waring").html('')
+      }
+    })
+  }
   /*}).catch(() => {
 
   })*/
@@ -132,10 +131,10 @@ function sureLogin() {
   let username = $("#username").val().trim();
   let password = $("#password").val().trim();
   const captcha = $("#code").val().trim();
-  if (!username) { 
-    if(type == 1){
+  if (!username) {
+    if (type == 1) {
       toast("请输入用户名!");
-    }else{
+    } else {
       $(".login .waring").css('visibility', 'visible').html('请输入用户名')
     }
     return
@@ -147,18 +146,18 @@ function sureLogin() {
     }
     return
   } else if (!captcha) {
-      if (type == 1) {
-          toast("请输入验证码!");
-      } else {
-          $(".login .waring").css('visibility', 'visible').html('请输入验证码')
-      }
-      return
+    if (type == 1) {
+      toast("请输入验证码!");
+    } else {
+      $(".login .waring").css('visibility', 'visible').html('请输入验证码')
+    }
+    return
   }
   $.alerModal({ type: "loading" });
   post(api.getJwt, {
     username: username,
     password: password,
-    captcha:captcha
+    captcha: captcha
   }).then((res) => {
     const data = res.data;
     if (data.code == 0) {
@@ -182,7 +181,7 @@ function sureLogin() {
       } else {
         $(".login .waring").css('visibility', 'visible').html(data.msg)
       }
-      
+
     }
   }).catch(() => {
     $(".divModal").remove()