loginlogmanage.js 6 KB
/**
 * Created by chenbiao on 2017/11/14.
 */
/**
 * Created by chenbiao on 2017/11/13.
 */
//

(function() {
    var fun = {

        init: function() {
            //初始化下拉框
            // fun.initSelect();
            fun.createTableData();
        },
        //生成表格数据
        createTableData: function() {
            $('#recordtable').bootstrapTable('destroy').bootstrapTable({
                striped: true, //表格显示条纹
                pagination: true, //启动分页
                pageNumber: 1, //当前第几页
                showColumns: false,
                pageSize: 10, //每页显示的记录数
                pageList: [10, 15, 20], //记录数可选列表
                sidePagination: 'server', //表示服务端分页
                queryParamsType: 'limit',
                method: 'POST', //请求方法
                // fixedColumns:true,
                // fixedNumber:1,
                // leftFixedColumns: true,
                // leftFixedNumber: 2,
                paginationPreText: '<',
                paginationNextText: '>',
                ajax: tableLoadRequest, //自定义ajax加载数据
                uniqueId: 'id',
                columns: [
                    {
                        field: 'loginCode',
                        title: '登录账号',
                        width: '5%',
                        align: 'center'
                    },
                    {
                        field: 'opName',
                        title: '操作员名称',
                        width: '5%',
                        align: 'center',
                        formatter: fun.carTypeFormatter
                    },
                    {
                        field: 'loginType',
                        title: '登录类型',
                        width: '10%',
                        align: 'center',
                        formatter: function(value, row, index) {
                            if(undefined != value && null != value) {
                                if(value == "1" ) {
                                    return "登录";
                                } else {
                                    return "登出";
                                }
                            }
                        }
                    },
                    {
                        field: 'loginIp',
                        title: '登录IP',
                        width: '8%',
                        align: 'center'
                    },
                    {
                        field: 'resultDesc',
                        title: '结果描述',
                        width: '10%',
                        align: 'center'
                    },
                    {
                        field: 'createDate',
                        title: '登录时间',
                        width: '10%',
                        align: 'center',
                        formatter: fun.outDatatimeFormatter
                    }
                ]
            });

        },

        /*获取查询参数*/
        getQueryParam: function() {
            /*登录账号*/
            var loginCode = $("#loginCode").val();
            /*开始时间*/
            var beginTime = $('#beginTime').val();
            /*结束时间*/
            var endTime = $('#endTime').val();
            beginTime = beginTime == null || beginTime.length == 0 ? null : new Date(beginTime);
            endTime = endTime == null || endTime.length == 0 ? null : new Date(endTime+" 23:59:59");
//			console.log(beginTime);
//			console.log(endTime);
            /*解析时间*/
            var req = {
                loginCode: loginCode,
                beginTime: beginTime,
                endTime: endTime
            };
            console.log(req);
            return req;
        },

        outDatatimeFormatter: function(value, row, index) {
            if(value == null) {
                return "";
            } else {
                return DateUtils.long2String(value, 7);
            }
        },

    };

    //初始执行
    fun.init();
   documentBindFunc.on('click', '#queryBtn', function() {
        fun.createTableData();
    });
    /*进场时间筛选框*/
    $("#beginTime").datetimepicker({
        endDate: moment().subtract('seconds', 0).format('YYYY-MM-DD'),

        format: 'yyyy-mm-dd',

        autoclose: true,

        // //maxDate:moment().subtract('months', 3),
        minView: 3,
        forceParse: false,
        locale: "zh-CN",
        language: 'zh-CN',
        pickerPosition: "bottom-left"
    }).on("click", function () {
        $("#beginTime").datetimepicker("setEndDate", $("#endTime").val())
    });
    $("#endTime").datetimepicker({
        endDate: moment().subtract('seconds', 0).format('YYYY-MM-DD'),

        format: 'yyyy-mm-dd',

        autoclose: true,
        // startView: 3,
        // //maxDate:moment().subtract('months', 3),
        minView: 3,
        forceParse: false,
        locale: "zh-CN",
        language: 'zh-CN',
        pickerPosition: "bottom-left"
    }).on("click", function () {
        $("#endTime").datetimepicker("setStartDate", $("#beginTime").val())
    });

    /**
     * 自定义table AJAX请求
     * @param {Object} params
     */
    function tableLoadRequest(params) {
        var req = fun.getQueryParam();
        //设置请求参数
        var pageNum = (params.data.offset / params.data.limit) + 1;

        //条件查询
        req.baseRequest = {
            pageNum: pageNum,
            pageSize: params.data.limit
        };
        req.sysCode = sysComm.sysCode;
        var opt = {
            method: 'post',
            url: dataUrl.util.queryLoginLog(),
            data: JSON.stringify(req),
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function(res) {
                console.log(res);
                if(res.code == '8888') {
                    params.success(res.data);
                }
            }
        };
        sysAjax(opt);
    }
})
();