login.1.js 2.2 KB
Newer Older
X
init  
xueli.xue 已提交
1 2 3 4 5 6 7
$(function(){
	// 复选框
    $('input').iCheck({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue',
      increaseArea: '20%' // optional
    });
X
xueli.xue 已提交
8
    
X
xueli.xue 已提交
9
	// 登录.规则校验
X
init  
xueli.xue 已提交
10 11 12 13 14 15 16
	var loginFormValid = $("#loginForm").validate({
		errorElement : 'span',  
        errorClass : 'help-block',
        focusInvalid : true,  
        rules : {  
        	userName : {  
        		required : true ,
X
xueli.xue 已提交
17
                minlength: 5,
X
init  
xueli.xue 已提交
18 19 20 21
                maxlength: 18
            },  
            password : {  
            	required : true ,
X
xueli.xue 已提交
22
                minlength: 5,
X
init  
xueli.xue 已提交
23 24 25 26 27
                maxlength: 18
            } 
        }, 
        messages : {  
        	userName : {  
X
xueli.xue 已提交
28 29 30
                required :"请输入登录账号."  ,
                minlength:"登录账号不应低于5位",
                maxlength:"登录账号不应超过18位"
X
init  
xueli.xue 已提交
31 32
            },  
            password : {
X
xueli.xue 已提交
33 34 35
            	required :"请输入登录密码."  ,
                minlength:"登录密码不应低于5位",
                maxlength:"登录密码不应超过18位"
X
init  
xueli.xue 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49
            }
        }, 
		highlight : function(element) {  
            $(element).closest('.form-group').addClass('has-error');  
        },
        success : function(label) {  
            label.closest('.form-group').removeClass('has-error');  
            label.remove();  
        },
        errorPlacement : function(error, element) {  
            element.parent('div').append(error);  
        },
        submitHandler : function(form) {
			$.post(base_url + "/login", $("#loginForm").serialize(), function(data, status) {
X
xueli.xue 已提交
50
				if (data.code == "200") {
X
xueli.xue 已提交
51 52 53 54 55 56 57 58
                    layer.open({
                        title: '系统提示',
                        content: '登录成功',
                        icon: '1',
                        end: function(layero, index){
                            window.location.href = base_url;
                        }
                    });
X
init  
xueli.xue 已提交
59
				} else {
X
xueli.xue 已提交
60 61 62 63 64
                    layer.open({
                        title: '系统提示',
                        content: (data.msg || "登录失败"),
                        icon: '2'
                    });
X
init  
xueli.xue 已提交
65 66 67 68 69
				}
			});
		}
	});
});