//author: neeler date: 151218 /**********TEST DATA START**********************************/ // var data_ = Mock.mock("", {}) // var data_ntypeahead = Mock.mock("/admin/admincon/login.htm", {code: 0, errmsg: "用户名或密码错误!"}) /**********TEST DATA END************************************/ window.I = { un: $("#username"), pw: $("#password"), c: $("#code"), e: $("#err"), l: $("#login"), ric: $("#reICode"), ci: $("#codeImg"), err: { unerr: "用户名为空", pwerr: "密码为空", cerr: "验证码为空" }, isPosting: false } $(function(){ I.un.focus(); if(self != top){ parent.window.location.replace(window.location.href); } autoHeight(); setErr(); pageInit(); }); function pageInit(){ I.un.keydown(function(event) { if (event.keyCode == 13){ if (!isNull($(this))) { I.e.empty(); I.pw.focus(); } } }); I.pw.keydown(function(event) { if (event.keyCode == 13){ if (!isNull($(this))) { I.e.empty(); login(); // I.c.focus(); } } }); I.c.keydown(function(event) { if (event.keyCode == 13){ login(); } }); I.l.click(function(event){ login(); }) I.ric.click(function(event) { I.ci.attr("src", "/kaptcha/kaptcha/kaptcha.ktc?tttiid=" + Math.random()); }); } //登录 function login() { if (I.isPosting) { return; } if (!(isNull(I.un) || isNull(I.pw)||isNull(I.c) )) {//|| isNull(I.c) I.e.empty(); var o = {}; o.username = I.un.val(); o.password = I.pw.val(); o.valicode = I.c.val(); // console.log(o); I.isPosting = true; $.post("/system/login.htm", o, function(data, textStatus, xhr) { I.isPosting = false; if (data.code >= 1) { I.ci.attr("src", "/kaptcha/kaptcha/kaptcha.ktc?tttiid=" + Math.random()); I.e.text(data.errmsg); } if (data.code == 0) { window.open(data.bb != null && data.bb !== "" ? data.bb : "/index.jsf", "_self"); } }, "json"); } } //验证 function isNull(jObj) { var v = $.trim(jObj.val()); var b = (v == "" || v == null) ? true : false; if (b) { jObj.focus(); I.e.text(jObj.err).show(); } return b; } //设置错误信息 function setErr(){ I.un.err = I.err.unerr; I.pw.err = I.err.pwerr; I.c.err = I.err.cerr; } function autoHeight() { var height = $(window).height(); $('.bg').css('min-height', height - 185); $('.xbga img').css('margin-top', (height - 330) / 2 - 200); $('.contbox').css('margin-top', (height - 330) / 2 - 230); $('.n-dcode').css('left', $(window).width() * 0.1 - 60); }