(function ($) { $.getUrlParam = function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } })(jQuery); $(function() { document.cookie = "cas_hash=" + encodeURIComponent(window.location.hash) ; document.cookie = "accessUrl" + "=" + $.getUrlParam("service") + "; " ; try{ if(window.localStorage){ //重新登录的时候清除掉localStorage window.localStorage.clear(); } if(window.sessionStorage){ //重新登录的时候清除掉sessionStorage window.sessionStorage.clear(); } }catch(e){} var passwordhtml = document.getElementById("password_template").innerHTML; var qrcodehtml = document.getElementById("qrcode_template").innerHTML; var phonehtml = document.getElementById("phonecode_template").innerHTML; $("#login_content").html(passwordhtml); initPassWordEvent(); //手机端不显示微信登录 var userAgentInfo = navigator.userAgent; if(userAgentInfo.indexOf("Mobile")>-1){ $("#isPc").hide(); $("#isNotPc").show().find(".qq").css("margin-left","calc(50% - 33px)"); }else{ $("#isNotPc").hide(); $("#isPc").show(); } var setting = { imageWidth : 1680, imageHeight : 1050 }; var init = function() { var windowHeight = $(window).height(); var windowWidth = $(window).width(); $(".login_conatiner").css("height",windowHeight); $(".login_conatiner").css("width",windowWidth); $("#container_bg").css("height",windowHeight); $("#container_bg").css("width",windowWidth); $("#login_right_box").css("height",windowHeight); var imgW = setting.imageWidth; var imgH = setting.imageHeight; var ratio = imgH / imgW; // 图片的高宽比 imgW = windowWidth; // 图片的宽度等于窗口宽度 imgH = Math.round(windowWidth * ratio); // 图片高度等于图片宽度 乘以 高宽比 if (imgH < windowHeight) { // 但如果图片高度小于窗口高度的话 imgH = windowHeight; // 让图片高度等于窗口高度 imgW = Math.round(imgH / ratio); // 图片宽度等于图片高度 除以 高宽比 } $(".login_img_01").width(imgW).height(imgH); // 设置图片高度和宽度 }; init(); $(window).resize(function() { init(); }); //点击账号登陆 $("#password_login").click(function(){ // $("#password_login").addClass("active"); // $("#qrcode_login").removeClass("active"); // $("#login_content").html(passwordhtml); $("#password_login").addClass("active"); $("#qrcode_login").removeClass("active"); $("#phoneCode_login").removeClass("active"); $("#login_content").html(passwordhtml); initPassWordEvent(); // var search =location.search; // //跳转url // var service = getParameter(search, "service", ""); // window.location.href = decodeURIComponent(service); }); //点击扫码登陆 $("#qrcode_login").click(function(){ $("#password_login").removeClass("active"); $("#qrcode_login").addClass("active"); $("#phoneCode_login").removeClass("active"); $("#login_content").html(qrcodehtml); mxsock(); //获取token及扫码地址 /*$.ajax({ type : "get", url : "yunschoolsso", dataType : "text", cache: false , data : { "type" : "getToken" }, success : function(result) { var token = result.substring(0,result.indexOf(",")); var content = result.substring(result.indexOf(",")+1); //生成二维码 setQrcode(content); var num = 0; //扫码登录 qrcodeLogin(content, token, num); }, error : function(xhr, status, errMsg) { alert("获取token失败"); } });*/ }); $("#phoneCode_login").click(function(){ $("#password_login").removeClass("active"); $("#qrcode_login").removeClass("active"); $("#phoneCode_login").addClass("active"); $("#login_content").html(phonehtml); initErrormsg(); }); //触发如何使用360极速模式图片 // $("#open_360").mouseover(function(){ // $("#open_360_img").show(); // }).mouseout(function(){ // $("#open_360_img").hide(); // }); //如果有错误信息,则显示 if($("#errormsghide").text()){ $("#errormsg").text($("#errormsghide").text()).show(); $("#help-link").hide(); } }); function initPassWordEvent(){ //放大 //点击放大图片 comm/image/cau_qyh.png $('div[name="cleckBig"]').click(function(){ $("#qrcodBig").show(); }); $(".popup-outside-content").click(function(){ $("#qrcodBig").hide(); }); //点击记住用户名 $("#rememberName").change(function(){ if($(this).is(":checked")){ var $u = $("#un").val() ; if($.trim($u)==''){ $("#errormsg").text("账号不能为空。").show(); $("#help-link").hide(); $(this).removeAttr("checked"); }else{ //不等于空,写cookie setCookie('dlut_cas_un' , $u , 365); document.getElementById('pd').focus() } }else{ //反选之后清空cookie clearCookie('dlut_cas_un'); } }); //登录按钮触发 $("#index_login_btn").click(function(){ login(); }); $("#open_360").click(function(){ $("#open_360_img").show(); }); $("#open_360").click(function(event){ event.stopPropagation(); }); $(document).click(function(){ $("#open_360_img").hide(); }); //用户名文本域keyup事件 $("#un").keyup(function(e){ if(e.which == 13) { login(); } }).keydown(function(e){ $("#errormsg").hide(); var winW =$("body").width(); if(winW < 1024){ $("#help-link").show(); } }).focus(); //密码文本域keyup事件 $("#pd").keyup(function(e){ if(e.which == 13) { login(); } }).keydown(function(e){ $("#errormsg").hide(); var winW =$("body").width(); if(winW < 1024){ $("#help-link").show(); } }); //重新获取验证码 $("#a_changeCode").click(function(){ $("#codeImage").attr("src", "code?"+Math.random()) ; }); //获取cookie值 var cookie = getCookie('dlut_cas_un'); if(cookie){ $("#un").val(cookie); $("#rememberName").attr("checked","checked"); } var ifchecked = function(){ if($("#rememberName").is(":checked")){ document.getElementById('pd').focus() } }; ifchecked(); } function initErrormsg(){ testTTT(); $("#phone").keyup(function(e){ if(e.which == 11){ loginBtn(); } }).keydown(function(e){ $("#errormsg").hide(); }).focus(); $("#phoneCode").keyup(function(e){ if(e.which == 10){ loginBtn(); } }).keydown(function(e){ $("#errormsg").hide(); }); $("#index_login_btn_phone").click(function(){ loginBtn(); }); } function mxsock() { /*$.ajax({ type : "get", url : "yunschoolsso", dataType : "text", cache: false , data : {"cs":"cs", "type":"cs", "code" : "cs" }, success : function(result) { }, error : function(result) { window.open("www.baidu.com"); } });*/ var service = GetQueryString("service"); console.log(service); mxsoc = new mxsocket({ //自定义参数begin debug: true,//是否开启调试模式,开启调试后调试信息将以console.log的形式输出 domain: "wep.cau.edu.cn",//域名 security: true,//是否https。 appid: '200190905170208710',//开发者APPID title: '上网系统扫码登录',//当前操作名称,如XX系统扫码登录 qrcode_id: 'qrcode',//二维码所在div的ID,会自动在该DIV下生成二维码 qrcode_width: 200,//二维码宽度,单位px qrcode_height: 200,//二维码高度,单位px //自定义参数end open: function (data) { //打开websocket连接后会触发该事件 //this.send("WebSocket rocks"); }, close: function () { //websocket连接中断后触发该事件 //this.init();//关闭后重新建立websocket连接,重新生成二维码 }, confirm: function (rs) { //用户扫码后点击确认同意后会触发该事件。 //console.log(rs.find("code")); console.log(rs); console.log(rs.code); $.ajax({ type : "get", url : "yunschoolsso", dataType : "text", cache: false , data : { "type":rs.code, "code" : rs.code }, success : function(result) { //window.location="http://baidu.com" console.log(result); if(result=="login"){ if(Boolean($.cookie("accessUrl"))){ window.location.href = $.cookie("accessUrl"); }else{ window.location.href = service == "" ? "https://one.cau.edu.cn/tp_up" : service; } }else{ //$("#qrcode").hide(); $("#qrcode").html("
"+result+"
") } }, error : function(result) { //window.location.href="http://baidu.com" console.log(result); } }); //这里写自己登陆逻辑处理,返回数据格式为{"code":"879d1a2d490d441cf76e90cbcae13209"} //PS:扫码成功后该二维码立即失效,其他用户再扫则会提示二维码失效,如果是多次人扫码场景即非登录场景,则需自行重新生成二维码(调用this.send('ticket')) }, reject: function (rs) { //用户扫码后点击取消会触发该事件。即用户拒绝该次扫码请求 console.log(rs); //这里写自己取消的逻辑处理。rs为空 }, error: function (rs) { //发生错误后点击取消会触发该事件 console.log(rs); }, /*日志输出方法,调试时可复写 log: function (msg) { var output = document.getElementById("debug"); var pre = document.createElement("p"); pre.style.color = "red"; pre.style.wordWrap = "break-word"; console.log(msg); pre.innerHTML = typeof msg == "string" ? msg : JSON.stringify(msg); output.appendChild(pre); }*/ }); }; function login(){ var $u = $("#un") , $p=$("#pd"); var u = $u.val().trim(); if(u==""){ $u.focus(); $("#errormsg").text("账号不能为空。"); $("#help-link").hide(); return ; } var p = $p.val().trim(); if(p==""){ $p.focus(); $("#errormsg").text("密码不能为空。"); $("#help-link").hide(); return ; } $u.attr("disabled","disabled"); $p.attr("disabled","disabled"); var lt = $("#lt").val(); $("#ul").val(u.length); $("#pl").val(p.length); $("#rsa").val(strEnc(u+p+lt , '1' , '2' , '3')); $("#sl").val(0); $("#loginForm")[0].submit(); } function loginBtn(){ var $phone = $("#phone"); var $code = $("#phoneCode"); var phone = $phone.val().trim(); if(phone == ""){ $phone.focus(); $phone.parent().addClass("login_error_border"); $("#errormsg").html("手机号不能为空!"); $("#errormsg").show(); $("#help-link").hide(); return ; } var code = $code.val().trim(); if(code == ""){ $code.focus(); $code.parent().addClass("login_error_border"); $("#errormsg").html("验证码不能为空!"); $("#errormsg").show(); $("#help-link").hide(); return ; } var mreg = /^0?1\d{10}$/; if(!mreg.test(phone)){ $phone.focus(); $phone.parent().addClass("login_error_border"); $("#errormsg").html("手机号格式不正确"); $("#errormsg").show(); return ; } var djsendtime = $.cookie("djsendtime"); if(djsendtime == null || djsendtime == "null" || djsendtime == undefined || djsendtime == "undefined"){ $phone.focus(); $("#errormsg").html("请先点击获取验证码再登陆"); $("#errormsg").show(); return ; } $phone.attr("disabled","disabled"); $code.attr("disabled","disabled"); var lt = $("#lt").val(); $("#ul").val(phone.length); $("#pl").val(code.length); $("#rsa").val(strEnc(phone+code+lt , '1' , '2' , '3')); $("#sl").val(1); $("#loginForm")[0].submit(); } function setQrcode(content){ $("#qrcode").qrcode({width: 143,height: 143,text: content}); } function qrcodeLogin(content, token, num){ var search =location.search; //跳转url var service = getParameter(search, "service", ""); $.ajax({ type : "get", url : "qrcodesso", dataType : "text", cache: false , data : { "type" : "qrcodeLogin", "service" : service, "token" : token, "content" : content }, success : function(result) { num ++; if(result == "out" && num < 2){ qrcodeLogin(content, token, num); }else{ window.location.href = decodeURIComponent(service); } // window.location.href = decodeURIComponent(service); // if(result == "ok"){ // window.location.href = decodeURIComponent(service); // }else if(result == "out"){ //// alert("扫码超时"); // window.location.href = decodeURIComponent(service); // }else if(result == "error"){ // alert("二维码失效"); // } }, error : function(xhr, status, errMsg) { // alert("扫码失败刷新后重试"); } }); } function getParameter(hash,name,nvl) { if(!nvl){ nvl = ""; } var svalue = hash.match(new RegExp("[\?\&]?" + name + "=([^\&\#]*)(\&?)", "i")); if(svalue == null){ return nvl; }else{ svalue = svalue ? svalue[1] : svalue; svalue = svalue.replace(/