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
layui.use(['layer', 'form', 'jquery'], function() {
    //let $ = layui.jquery,
    var $ = layui.jquery,
        layer = layui.layer,
        form = layui.form;
    
    form.on('submit(login)', function () {
        var index = layer.load();
        $.ajax({
            type: 'get',
            url: nginx_url + '/login',
            data: {
                'username': $('#loginId').val(),
                'password': $('#password').val()
            },
            dataType: 'json',
            async: false,
         // 发送cookie
            xhrFields:{
                withCredentials: true
            },
            success: function (result) {
                layer.close(index);
                if (result.result) {
                    $.cookie("loginId", result.data.userCode);
                    setTimeout(function() {
                        layer.msg('登录成功', {
                            time: 800,
                            icon: 1
                        }, function () {
                            window.location.href = 'index.html';
                        });
                    }, 800);
                }else{
                    layer.msg(result.msg, {icon: 2});
                }
            }
        });
        return false;
    });
});