czt
2025-06-11 283da741b2429cf5a53786e5ee1b5528b757fdf6
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
 
$(function() {
    validateKickout();
    validateRule();
    registerValidateRule();
    phoneNumberValidateRule();
    $('.imgcode').click(function() {
        var url = ctx + "captcha/captchaImage?type=" + captchaType + "&s=" + Math.random();
        $(".imgcode").attr("src", url);
    });
});
 
$.validator.setDefaults({
    submitHandler: function(from) {
        console.log(from.id)
        if("registerForm"==from.id){
            register();
        }else if("signupForm"==from.id){
            login();
        }else {
            messageLogin();
        }
    }
});
function login() {
    $.modal.loading($("#btnSubmit").data("loading"));
    var username = $.common.trim($("input[name='username']").val());
    var password = $.common.trim($("input[name='password']").val());
    var validateCode = $("input[name='validateCode']").val();
    var rememberMe = $("input[name='rememberme']").is(':checked');
    $.ajax({
        type: "post",
        url: ctx + "login",
        data: {
            "username": username,
            "password": password,
            "validateCode": validateCode,
            "rememberMe": rememberMe
        },
        success: function(r) {
            if (r.code == web_status.SUCCESS) {
                location.href = ctx + 'dzhwk/index';
            } else {
                $('.imgcode').click();
                $(".code").val("");
                $.modal.msg(r.msg);
            }
            $.modal.closeLoading();
        }
    });
}
function register() {
    $.modal.loading($("#btnSubmitRegister").data("loading"));
    var username = $.common.trim($("input[name='registerUsername']").val());
    var password = $.common.trim($("input[name='registerPassword']").val());
    var validateCode = $("input[name='registerValidateCode']").val();
    $.ajax({
        type: "post",
        url: ctx + "register",
        data: {
            "loginName": username,
            "password": password,
            "validateCode": validateCode
        },
        success: function(r) {
            if (r.code == web_status.SUCCESS) {
                layer.alert("<font color='red'>恭喜你,您的账号 " + username + " 注册成功!</font>", {
                        icon: 1,
                        title: "系统提示"
                    },
                    function(index) {
                        //关闭弹窗
                        layer.close(index);
                        location.href = ctx + 'login';
                    });
            } else {
                $.modal.closeLoading();
                $('.imgcode').click();
                $(".code").val("");
                $.modal.msg(r.msg);
            }
        }
    });
}
function messageLogin() {
    $.modal.loading($("#btnMessageLogin").data("loading"));
    var phoneNumber = $.common.trim($("input[name='phoneNumber']").val());
    var validateCode = $("input[name='phoneNumberValidateCode']").val();
    $.ajax({
        type: "post",
        url: ctx + "messageLogin",
        data: {
            "phoneNumber": phoneNumber,
            "validateCode": validateCode
        },
        success: function(r) {
            if (r.code == web_status.SUCCESS) {
                console.log(ctx + 'index');
                location.href = ctx + 'index';
            } else {
                $.modal.msg(r.msg);
            }
            $.modal.closeLoading();
        }
    })
}
 
 
function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            username: {
                required: true
            },
            password: {
                required: true
            }
        },
        messages: {
            username: {
                required: icon + "请输入您的用户名",
            },
            password: {
                required: icon + "请输入您的密码",
            }
        }
    })
}
function validateKickout() {
    if (getParam("kickout") == 1) {
        layer.alert("<font color='red'>您已在别处登录,请您修改密码或重新登录</font>", {
                icon: 0,
                title: "系统提示"
            },
            function(index) {
                //关闭弹窗
                layer.close(index);
                if (top != self) {
                    top.location = self.location;
                } else {
                    var url = location.search;
                    if (url) {
                        var oldUrl = window.location.href;
                        var newUrl = oldUrl.substring(0, oldUrl.indexOf('?'));
                        self.location = newUrl;
                    }
                }
            });
    }
}
function registerValidateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#registerForm").validate({
        rules: {
            registerUsername: {
                required: true,
                minlength: 2
            },
            registerPassword: {
                required: true,
                minlength: 5
            },
            confirmRegisterPassword: {
                required: true,
                equalTo: "[name='registerPassword']"
            }
        },
        messages: {
            registerUsername: {
                required: icon + "请输入您的用户名",
                minlength: icon + "用户名不能小于2个字符"
            },
            registerPassword: {
                required: icon + "请输入您的密码",
                minlength: icon + "密码不能小于5个字符",
            },
            confirmRegisterPassword: {
                required: icon + "请再次输入您的密码",
                equalTo: icon + "两次密码输入不一致"
            }
        }
    })
}
function phoneNumberValidateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#messageLoginForm").validate({
        rules: {
            phoneNumber: {
                required: true,
                minlength: 11,
                maxlength: 11,
                isPhoneNum:true
            },
            phoneNumberValidateCode: {
                required: true,
                minlength: 6,
                maxlength: 6
            }
        },
        messages: {
            phoneNumber: {
                required: icon + "请输入您的手机号",
                minlength: icon + "手机号不能小于11个字符",
                maxlength: icon + "手机号最大11个字符",
                isPhoneNum:icon+"请正确填写您的手机号码"
            },
            phoneNumberValidateCode: {
                required: icon + "请输入您的验证码",
                minlength: icon + "验证码最小为6位号码",
                 maxlength: icon + "验证码最大6位号码"
            }
        }
    })
}
 
 
 
function getParam(paramName) {
    var reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURI(r[2]);
    return null;
}
//自定义手机号验证
jQuery.validator.addMethod("isPhoneNum", function(value, element) {
 
    var length = value.length;
    var mobile =/^1[34578]\d{9}$/;
    return this.optional(element) || (length == 11 && mobile.test(value));
}, "请正确填写您的手机号码");
var duration = 60; //60秒
// 获取验证码按钮点击事件
function sendMsgCode() {
    $("#secondShow").css('display', 'block');
    $("#sendMessageCode").css('display', 'none');
    $("#secondShow").html('重新发送(' + duration + 's)');
    var timer = setInterval(function () {
        if (duration == 0) {
            clearInterval(timer);
            $("#secondShow").css('display', 'none');
            $("#sendMessageCode").css('display', 'block');
            duration = 60;
        }
        $("#secondShow").html('重新发送(' + (duration - 1) + 's)');
        duration--;
    }, 1000);
    //TODO
    //发短信业务
    var phoneNumber = $.common.trim($("input[name='phoneNumber']").val());
    $.ajax({
        type: "GET",
        url: ctx + "login/sendMessageCode",
        data: {
            phoneNumber: phoneNumber
        },
        success: function (r) {
            if (r.code == web_status.SUCCESS) {
                layer.alert("<font color='red'>恭喜你,您的验证码发送成功!</font>", {
                        icon: 1,
                        title: "系统提示"
                    },
                    function(index) {
                    //关闭弹窗
                        layer.close(index);
                    }
                )
            } else {
                // 显示错误信息
                layer.alert(r.msg || "发送验证码失败", {
                    icon: 2,
                    title: "系统提示"
                });
            }
        }
    })
};