import {stationurl} from "../../public/js/url.js"; $().ready(function() { //设置用户名,密码保存的cookie var userName=""; var userPwd=""; var loginCount=3; $(".button").click(function(){ sendLoginResquest(); }) $(document).keyup(function(event){ if(event.keyCode=="13"){//13表示回车键的代码 sendLoginResquest(); } }) $("#pwd").focus(function(){ $(this).attr("type","password"); }); //接受url的值,进行解析 function getParams(key) { var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); } return null; }; var UrlUserName=getParams("username"); var UrlPassWord=getParams("password"); if(UrlUserName!=null||UrlPassWord!=null){ userName=UrlUserName; userPwd=UrlPassWord; var userInfoObj={ "name":userName, "password":hex_md5(userPwd) }; loginReq(userInfoObj) } function loginError(msg){ layer.confirm(msg,{ btn:[ '确定'], title:false, closeBtn:false, // r表示right,b表示bottom offset: 'auto', anim: 2, }) } function sendLoginResquest(){ var username=$(".username").val(); var password=$(".password").val(); userName=username; userPwd=password; if(username==""||password==""){ var msg="用户输入有误,请重试"; $(".error").html(msg); loginError(msg) return; } var num = show_num.join("");//验证码 var verCode = $("#verCode").val().toLowerCase(); if(num!=verCode){ var msg="验证码输入有误,请重试"; $(".error").html(msg); loginError(msg) return; } var userInfoObj={ "name":userName, "password":hex_md5(userPwd) }; loginReq(userInfoObj) } function loginReq(userInfoObj){ var loginurl=stationurl+"/common/client/user/login"; $.ajax({ url:loginurl, type:"post", dataType:"json", headers:{ "Content-Type":"application/json;charset=utf-8", }, data:JSON.stringify(userInfoObj), success:function(data){ loginCallBack(data); } }) } function loginCallBack(data){ var code=data["code"]; if(code==0){ getrememberPwd(); var spanL=$(".login_right>p:nth-child(5)>span:nth-child(1)").children(); var data=data["data"]; var user_session=data["session"]; var user_type=data["usertype"]; var user_phone=data["phone"]; var user_scopelevel=data["scopelevel"]; var user_levelvalue=data["levelvalue"]; var organize=data["organize"]; var user_longitude=data["longitude"]; var user_latitude=data["latitude"]; var hidden=data["hidden"]; if(user_scopelevel==""){ user_scopelevel="master"; user_levelvalue=""; } var theme=data["theme"]; if(theme==null||theme.length==0){ theme=JSON.stringify({ "title":"数字可视化对讲综合管理平台" }) } if(organize==null){ var organize={ "theme":"" } } var unameInfo={ "session":user_session,//用户session "user_type":user_type,//用户类型 "user_scopelevel":user_scopelevel,//用户等级 "user_levelvalue":user_levelvalue,//等级值 "user_name":userName,//用户名称 "user_pwd":userPwd,//用户密码 "user_longitude":user_longitude,//用户位置信息 "user_latitude":user_latitude,//用户位置信息 "user_phone":user_phone,//用户电话,用于做对讲使用 "systemName":"", "systePage":"", "theme":theme, "organize":organize, "hidden":hidden } var unameInfoStr=JSON.stringify(unameInfo); sessionStorage.setItem("unameInfoStr",unameInfoStr); //window.location.href="./furongNav/index.html?pages=login"; //window.location.href="cmdDispatch.html?pages=login"; window.location.href="./pages/newIndex/index.html" }else{ var msg=data["msg"]; loginError(msg) $(".error").html(msg); } } //验证码 var show_num = []; draw(show_num); $("#canvas").on('click',function(){ draw(show_num); }) //生成并渲染出验证码图形 function draw(show_num) { var canvas_width=$('#canvas').width(); var canvas_height=$('#canvas').height(); var canvas = document.getElementById("canvas");//获取到canvas的对象,演员 var context = canvas.getContext("2d");//获取到canvas画图的环境,演员表演的舞台 canvas.width = canvas_width; canvas.height = canvas_height; var sCode = "2,3,4,5,6,8,9"; var aCode = sCode.split(","); var aLength = aCode.length;//获取到数组的长度 for (var i = 0; i < 4; i++) { //这里的for循环可以控制验证码位数(如果想显示6位数,4改成6即可) var j = Math.floor(Math.random() * aLength);//获取到随机的索引值 // var deg = Math.random() * 30 * Math.PI / 180;//产生0~30之间的随机弧度 var deg = Math.random() - 0.5; //产生一个随机弧度 var txt = aCode[j];//得到随机的一个内容 show_num[i] = txt.toLowerCase(); var x = 10 + i * 20;//文字在canvas上的x坐标 var y = 20 + Math.random() * 8;//文字在canvas上的y坐标 context.font = "bold 23px 微软雅黑"; context.translate(x, y); context.rotate(deg); context.fillStyle = randomColor(); context.fillText(txt, 0, 0); context.rotate(-deg); context.translate(-x, -y); } // for (var i = 0; i <= 2; i++) { //验证码上显示线条 // context.strokeStyle = randomColor(); // context.beginPath(); // context.moveTo(Math.random() * canvas_width, Math.random() * canvas_height); // context.lineTo(Math.random() * canvas_width, Math.random() * canvas_height); // context.stroke(); // } // for (var i = 0; i <= 10; i++) { //验证码上显示小点 // context.strokeStyle = randomColor(); // context.beginPath(); // var x = Math.random() * canvas_width; // var y = Math.random() * canvas_height; // context.moveTo(x, y); // context.lineTo(x + 1, y + 1); // context.stroke(); // } } //得到随机的颜色值 function randomColor() { // var r = Math.floor(Math.random() * 256); // var g = Math.floor(Math.random() * 256); // var b = Math.floor(Math.random() * 256); // return "rgb(" + r + "," + g + "," + b + ")"; return "rgb(107,239,255)"; } function setCookie(cname,cvalue,exdays){ var d = new Date(); d.setTime(d.getTime()+(exdays*24*60*60*1000)); var expires = "expires="+d.toGMTString(); document.cookie = cname+"="+cvalue+"; "+expires; } function getCookie(cname){ var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i