王佳豪
2021-06-25 eb3f8587aa7466fd6d2d3ca712d0f9baf4e27dcb
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
/**
 * 登陆
 */
 
//表单验证
$(function(){
    //键盘回车键,响应登录
    document.onkeydown=keyDownSearch; 
    function keyDownSearch(e) {          
        // 兼容FF和IE和Opera  
        var theEvent = e || window.event;  
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;  
        if (code == 13) {   
            doLogin();
            return false;  
        }  
        return true;  
    } 
    
    $('#form').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
                },
 
                fields: {
                    user_account: {
                        message: '登录名验证失败',
                        validators: {
                            notEmpty: {
                                message: '登录账号不能为空'
                            }
                        }
                    },
                    user_password: {
                        validators: {
                            notEmpty: {
                                message: '登录密码不能为空'
                            },
//                            regexp: {
//                                regexp: /^[a-zA-Z0-9_\.]+$/,
//                                message: '密码非法'
//                            },
                            stringLength: {
                                min: 6,
                                max: 12,
                                message: '密码长度必须在6到18之间'
                            }
                        }
                    },
                 
                }
            });
    });
 
//登陆
function doLogin(){
    if($("#form").data('bootstrapValidator').validate().isValid()){
        //layer.msg('玩命提示中');
        //layer.msg('的确很重要', {icon: 1});
        $.ajax({
            type:'post',
            dataType:'json',
            url:'login/doLogin.action',
            data:$("#form").serialize(),
            success:function(data){
                if(data.i==0){
                    location.href="login/login.action?uid="+data.id;
                }else if(data.i==1){
                    layer.msg('登录密码不正确',{
                        time:30000,
                        btn:['确定']
                    });
                    //location.reload();
                }else{
                    layer.msg('此账号不存在',{
                        time:30000,
                        btn:['确定']
                    });
                    //location.reload();
                }
            },
            error:function(){
                layer.msg("请求失败!");
            }
        });
        
    }else{
        /*layer.msg('取消',{
            time:2000,
            btn:['明白了','知道了']
        });*/
        return false;
    }
    
    
}