hjg
2023-11-17 3780c5e65b05bf23020810798babc6d20311fa79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//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);
}