Helius
2021-09-16 4d80b819948366cb0754369b1bea5e0e83cf6af1
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
<div class="layui-fluid layui-anim febs-anim" id="febs-login-log" lay-title="登录日志">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="login-log-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">登录用户</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="username" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">登录时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="createTime" id="login-log-createTime" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain  table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain  table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="loginlog:delete,loginlog:export">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="loginLogTable" lay-data="{id: 'loginLogTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="login-log-option">
    <span shiro:lacksPermission="loginlog:delete">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <a lay-event="del" shiro:hasPermission="loginlog:delete"><i class="layui-icon febs-edit-area febs-red">&#xe7f9;</i></a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'laydate', 'form', 'table', 'febs', 'dropdown'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#febs-login-log'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'loginTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo;
 
        laydate.render({
            elem: '#login-log-createTime',
            range: true,
            trigger: 'click'
        });
 
        form.render();
 
        initTable();
 
        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                if (name === 'delete') {
                    var checkStatus = table.checkStatus('loginLogTable');
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请勾选需要删除的日志');
                    } else {
                        febs.modal.confirm('删除日志', '确定删除所选日志?', function () {
                            var logIds = [];
                            layui.each(checkStatus.data, function (key, item) {
                                logIds.push(item.id)
                            });
                            deleteLogs(logIds.join(','))
                        });
                    }
                }
                if (name === 'export') {
                    var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                    params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
                    params.pageNum = $view.find(".layui-laypage-em").next().html();
                    febs.download(ctx + 'loginLog/excel', params, '登录日志表.xlsx');
                }
            },
            options: [ {
                name: 'delete',
                title: '删除日志',
                perms: 'loginlog:delete'
            }, {
                name: 'export',
                title: '导出Excel',
                perms: 'loginlog:export'
            }]
        });
 
        table.on('tool(loginLogTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                febs.modal.confirm('删除日志', '确定删除该条登录日志?', function () {
                    deleteLogs(data.id);
                });
            }
        });
 
        table.on('sort(loginLogTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });
 
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });
 
        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });
 
        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'loginLogTable',
                url: ctx + 'loginLog/list',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'username', title: '登录用户'},
                    {field: 'ip', title: 'IP地址'},
                    {field: 'location', title: '登录地点', minWidth: 180},
                    {field: 'loginTime', title: '登录时间', minWidth: 180, sort: true},
                    {field: 'system', title: '登录系统'},
                    {field: 'browser', title: '浏览器'},
                    {title: '操作', toolbar: '#login-log-option'}
                ]]
            });
        }
 
        function deleteLogs(logIds) {
            febs.get(ctx + 'loginLog/delete/' + logIds, null, function () {
                febs.alert.success('删除登录日志成功');
                $query.click();
            });
        }
 
        function getQueryParams() {
            var createTime = $searchForm.find('input[name="createTime"]').val();
            if (createTime) {
                createTimeFrom = createTime.split(' - ')[0];
                createTimeTo = createTime.split(' - ')[1];
            }
            return {
                loginTimeFrom: createTimeFrom,
                loginTimeTo: createTimeTo,
                username: $searchForm.find('input[name="username"]').val().trim()
            };
        }
    })
</script>