4
hao
2025-04-16 c5fb1fbcbb2bf4d511773d348f9ef625855c61fc
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**
 * 登录
 */
var picCode;
 $(function(){
     $("#waitMessage").hide();
     
     //picCode=drawPic();
     layui.use(['form' ,'layer'], function() {
         var form = layui.form;
         var layer = layui.layer;
         //监控提交
         /*form.on("submit(sendMsg)",function (data) {
             //sendMsg();
             var flag=checkParams();
             if(flag!=false){
                 send(this,true);
             }
             return false;
         });*/
         form.on("submit(login)",function () {
             login();
             return false;
         });
         var path=window.location.href;
//         console.info("==请求的uri:"+path);
         if(path.indexOf("kickout")>0){
             layer.alert("您的账号已在别处登录;若不是您本人操作,请立即修改密码!",function(){
                 window.location.href=context+"/login";
             });
         }
     })
 })
//定时发送验证码
var wait = 60;
 var startJob;
//o 对象
/*function send(o, flag) {
        if (!flag) {
            return false;
        }
        //第一次秒数
        if (wait == 60) {
            o.setAttribute("disabled", true);
            //自定义验证规则
            $.post("/user/sendMsg", $("#useLogin").serialize(), function (data) {
                console.log("data:" + data)
                if (data.code == "1000") {
                    layer.msg("发送短信成功");
                } else {
                    $("#password").val("");
                    picCode = drawPic();
                    $("#code").val("");
                    //禁用发送短信验证码按钮
                    o.removeAttribute("disabled");
                    //o.value = "获取验证码";
                    wait = 60;
                    flag = false;
                    layer.alert(data.message);
                }
                return false;
            });
        }
        if (wait == 0) {
            o.removeAttribute("disabled");
            $("#msgBtn").html("获取验证码");
            wait = 60;
        } else {
            o.setAttribute("disabled", true);
            if (wait <60) {
                $("#msgBtn").html("<span style='margin-left: -12px;'>"+wait + "s后可重新发送</span>");
            }
            wait--;
            startJob=setTimeout(function () {
                if (wait == 0) {
                    flag = true
                }
                ;
                send(o, flag)
            }, 1000)
        }
}*/
function closeSend(){
    $("#msgBtn").removeAttr("disabled");
    $("#msgBtn").html("获取验证码");
    clearTimeout(startJob);
}
function sendMsg(){
    var flag=checkParams();
    if(flag!=false) {
 
        //自定义验证规则
        $.post("/user/sendMsg", $("#useLogin").serialize(), function (data) {
 
            if (data.code == "1000") {
                layer.msg("发送短信成功");
            } else {
                //$("#password").val("");
                picCode = drawPic();
                $("#code").val("");
                layer.alert(data.message);
            }
        });
    }
}
 
function login(){
    var flag=checkParams();
    if(flag!=false){
        //校验短信验证码
        // var smsCode=$("#smsCode").val();
        // if("ok"!=ValidateUtils.checkCode(smsCode)){
        //     //tips层-右
        //     layer.tips(ValidateUtils.checkCode(smsCode), '#smsCode', {
        //         tips: [3, '#78BA32'], //还可配置颜色
        //         tipsMore: true
        //     });
        //     return false;
        // }
        $.ajax({
            type: "get",
            url: context+"/login1",
            data: { "username":$("#username").val(), "password":$("#password").val(), "rememberMe":$("[name='rememberMe']").is(":checked") },
            dataType: 'json',
            success: function (res) {
                if(res.result){
                    //window.location.href = "/home";
                    setTimeout(function() {
                        layer.msg('登录成功', {
                            time: 800,
                            icon: 1
                        }, function () {
                            window.location.href = context+"/home";
                        });
                    }, 800);
                    /*layer.alert("登录成功",function () {
                        window.location.href="/home";
                    });*/
                }else{
                   // picCode=drawPic();
                    $("#code").val("");
                    // $("#smsCode").val("");
                    layer.alert(res.msg,function(){
                        layer.closeAll();//关闭所有弹框
                        //关闭发送验证码按钮倒计时
                        //closeSend();
                    });
                }
            }
        })
 
        // $.post("/user/login",$("#useLogin").serialize(),function(data){
        //     console.log("data:"+data)
        //     if(data.code=="1000"){
        //         layer.alert("登录成功",function () {
        //             window.location.href="/home";
        //         });
        //     }else{
        //         //$("#password").val("");
        //         picCode=drawPic();
        //         $("#code").val("");
        //         $("#smsCode").val("");
        //         layer.alert(data.message,function(){
        //             layer.closeAll();//关闭所有弹框
        //             //关闭发送验证码按钮倒计时
        //             closeSend();
        //         });
        //     }
        // });
    }
}
 
function checkParams(){
    //  校验
    var username=$("#username").val();
    var password=$("#password").val();
    // var mobile=$("#mobile").val();
   // var code=$("#code").val();
    // if("ok"!=ValidateUtils.checkUserName(username) || "ok"!=ValidateUtils.checkSimplePassword(password)){
    //     layer.alert("请您输入正确的用户名和密码");
    //     return false;
    // }
 
    // if("ok"!=ValidateUtils.checkMobile(mobile)){
    //     //tips层-右
    //     layer.tips(ValidateUtils.checkMobile(mobile), '#mobile', {
    //         tips: [2, '#78BA32'], //还可配置颜色
    //         tipsMore: true
    //     });
    //     return false;
    // }
    /*if("ok"!=ValidateUtils.checkPicCode(code)){
        //tips层-右
        layer.tips(ValidateUtils.checkPicCode(code), '#canvas', {
            tips: [2, '#78BA32'], //还可配置颜色
            tipsMore: true
        });
        return false;
    }
    if(picCode.toLowerCase()!=code.toLowerCase()){
        //tips层-右
        layer.tips("请您输入正确的验证码", '#canvas', {
            tips: [2, '#78BA32'], //还可配置颜色
            tipsMore: true
        });
        return false;
    }*/
}