田源
2024-04-07 2ac55ce0edf4870a29691b56bfad59f4830a11a2
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
/**
 * 在线用户列表
 * @author weidy@2019-07-19
 * @constructor
 */
layui.define(['layer','table'],function(exports){
    var Class = function(){
        this.moduleKey = "vciWebOnlineUser";
        this.id='vciWebOnlineUser';
        this.sourceData={};//来源数据,需要至少包含type,如果没有则默认为批产
        this.columns = [];
        this.backPath = path;//默认流程和项目的路径是一样的
        this.url={
            dataGrid:'/webOnlineUserController/dataGrid'//列表数据和查询
        };
        this.buttonIconMap = {
            SEARCH:'layui-icon-refresh-2',
            SENIORSEARCH:'layui-icon-query'
        };
        this.getContent=function(){//返回这个组件的基础html
            var that = this;
            var html = "";
            html = [
                '<div class="layui-layout-border">',
                    '<div class="layui-center">',
                        that.getToolbarHtml(),
                        '<table id="table_', that.id , '" lay-filter="',that.id , '" style="overflow-x:auto;"></table>',//主列表
                    '</div>',
                '</div>'
            ].join("");
            return html;
        };
        this.getToolbarHtml =function(){
            var that = this;
            var html = [
                '<div layui-filter="toolbar_',that.id, '" class="layui-btn-container">',//主列表的按钮
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_refresh"><i class="layui-icon layui-icon-refresh"></i>刷新</button>',
                '</div>'
            ].join("");
            return html;
        };
        this.init=function(){//基础的html被添加后,再执行初始化
            var that = this;
            $webUtil.copyConfig(that,that.moduleKey);
            var table = layui.table;
            that.checkColumns();//主列表中列。
            table.render({
                elem: '#table_' + that.id,
                id: 'table_' + that.id,
                url: that.backPath + that.url.dataGrid,
                cols: [that.columns]
            });
            $('[layui-filter="toolbar_' + that.id + '_refresh"]').unbind("click").click(function(){
                that.refresh();
            });
        };
        this.checkColumns = function(){
            var that = this;
            var table = layui.table;
            if(that.columns==null || that.columns.length==0){//如果其他地方想使用这个组件的时候,可以自定义列
                that.columns = [table.getIndexColumn(),table.getCheckColumn(),{
                    field:'userId',
                    title:'用户名',
                    width:150
                },{
                    field:'userName',
                    title:'用户姓名',
                    width:150
                },{
                    field:'ip',
                    title:'IP地址',
                    width:150
                },{
                    field:'lastRequestTime',
                    title:'最后请求服务时间',
                    width:200
                }];
            }
        };
        this.refresh = function(){
            var that = this;
            layui.table.reload('table_' + that.id,{});
        };
    };
    var cs = new Class();
    exports('vciWebOnlineUser',cs);
});