#
Junjie
昨天 a637cdb04ab7e0954196ad0d8e7cc24ae22ee93a
src/main/webapp/static/js/operateLog/operateLog.js
@@ -1,396 +1,1294 @@
var pageCurr;
layui.use(['table','laydate', 'form'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    // 数据渲染
    tableIns = table.render({
        elem: '#operateLog',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/operateLog/list/auth',
        page: true,
        limit: 16,
        limits: [16, 30, 50, 100, 200, 500],
        even: true,
        toolbar: '#toolbar',
        cellMinWidth: 50,
        cols: [[
            // {type: 'checkbox'}
            {field: 'id', title: 'ID', sort: true,align: 'center', width: 80}
            ,{field: 'userId$', align: 'center',title: '用户'}
            ,{field: 'action', align: 'center',title: '操作内容'}
            ,{field: 'ip', align: 'center',title: '客户端IP'}
            ,{field: 'request', align: 'center',title: '请求数据'}
            ,{field: 'response', align: 'center',title: '响应数据'}
            ,{field: 'createTime$', align: 'center',title: '添加时间'}
            // ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:100}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
(function () {
    var simpleEntityName = 'operateLog';
    var entityName = 'OperateLog';
    var primaryKeyField = 'id';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'id',
        columnName: 'id',
        label: 'ID',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
        },
        parseData: function (res) {
    {
        field: 'action',
        columnName: 'action',
        label: '操作内容',
        tableProp: 'action',
        exportField: 'action',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'userId',
        columnName: 'user_id',
        label: '用户',
        tableProp: 'userId',
        exportField: 'userId',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'ip',
        columnName: 'ip',
        label: '客户端IP',
        tableProp: 'ip',
        exportField: 'ip',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'request',
        columnName: 'request',
        label: '请求数据',
        tableProp: 'request',
        exportField: 'request',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'response',
        columnName: 'response',
        label: '响应数据',
        tableProp: 'response',
        exportField: 'response',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '添加时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'id',
        columnName: 'id',
        label: 'ID',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'action',
        columnName: 'action',
        label: '操作内容',
        tableProp: 'action',
        exportField: 'action',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'userId',
        columnName: 'user_id',
        label: '用户',
        tableProp: 'userId',
        exportField: 'userId',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'ip',
        columnName: 'ip',
        label: '客户端IP',
        tableProp: 'ip',
        exportField: 'ip',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'request',
        columnName: 'request',
        label: '请求数据',
        tableProp: 'request',
        exportField: 'request',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'response',
        columnName: 'response',
        label: '响应数据',
        tableProp: 'response',
        exportField: 'response',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '添加时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'id',
        columnName: 'id',
        label: 'ID',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'action',
        columnName: 'action',
        label: '操作内容',
        tableProp: 'action',
        exportField: 'action',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'userId',
        columnName: 'user_id',
        label: '用户',
        tableProp: 'userId',
        exportField: 'userId',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'ip',
        columnName: 'ip',
        label: '客户端IP',
        tableProp: 'ip',
        exportField: 'ip',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'request',
        columnName: 'request',
        label: '请求数据',
        tableProp: 'request',
        exportField: 'request',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'response',
        columnName: 'response',
        label: '响应数据',
        tableProp: 'response',
        exportField: 'response',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '添加时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'id',
        columnName: 'id',
        label: 'ID',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'action',
        columnName: 'action',
        label: '操作内容',
        tableProp: 'action',
        exportField: 'action',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'userId',
        columnName: 'user_id',
        label: '用户',
        tableProp: 'userId',
        exportField: 'userId',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'ip',
        columnName: 'ip',
        label: '客户端IP',
        tableProp: 'ip',
        exportField: 'ip',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'request',
        columnName: 'request',
        label: '请求数据',
        tableProp: 'request',
        exportField: 'request',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'response',
        columnName: 'response',
        label: '响应数据',
        tableProp: 'response',
        exportField: 'response',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '添加时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    ]);
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'date' && isEmptyValue(value)) {
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
        }
    });
    table.on('edit(operateLog)', function (obj) {
        $('body').keydown(function () {
            if (event.keyCode === 13) {
                layer.confirm('保存修改?', function(){
                });
            }
        });
    });
    // 监听排序事件
    table.on('sort(operateLog)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {
                curr: 1
            },
            done: function (res, curr, count) {
                if (res.code === 403) {
                    top.location.href = baseUrl+"/";
                }
                pageCurr=curr;
                limit();
            }
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(operateLog)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event) {
            case 'addData':
                layer.open({
                    type: 2,
                    title: '新增',
                    maxmin: true,
                    area: [top.detailWidth, top.detailHeight],
                    shadeClose: false,
                    content: 'operateLog_detail.html',
                    success: function(layero, index){
                       clearFormVal(layer.getChildFrame('#detail', index));
                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                    }
                });
                break;
            case 'refreshData':
                tableIns.reload({
                    page: {
                        curr: pageCurr
                    }
                });
                limit();
                break;
            case 'deleteData':
                var data = checkStatus.data;
                var ids=[];
                data.map(function (track) {
                    ids.push(track.id);
                });
                if (ids.length === 0){
                    layer.msg('请选择数据');
                } else {
                    layer.confirm('确定删除'+(ids.length===1?'此':ids.length)+'条数据吗', function(){
                        $.ajax({
                            url: baseUrl+"/operateLog/delete/auth",
                            headers: {'token': localStorage.getItem('token')},
                            data: {ids: ids},
                            method: 'POST',
                            traditional:true,
                            success: function (res) {
                                if (res.code === 200){
                                    layer.closeAll();
                                    tableReload(false);
                                } else if (res.code === 403){
                                    top.location.href = baseUrl+"/";
                                } else {
                                    layer.msg(res.msg)
                                }
                            }
                        })
                    });
                }
                break;
            case 'exportData':
                layer.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'operateLog': exportData,
                        'fields': fields
            token: localStorage.getItem('token')
                    };
                    $.ajax({
                        url: baseUrl+"/operateLog/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg)
                            }
                        }
                    });
                });
                break;
        }
    });
    // 监听行工具事件
    table.on('tool(operateLog)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            // 详情
            case 'detail':
                layer.open({
                    type: 2,
                    title: '详情',
                    maxmin: true,
                    area: [top.detailWidth, top.detailHeight],
                    shadeClose: false,
                    content: 'operateLog_detail.html',
                    success: function(layero, index){
                        setFormVal(layer.getChildFrame('#detail', index), data, true);
                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
                        layer.getChildFrame('#data-detail-submit,#prompt', index).hide();
                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                        layero.find('iframe')[0].contentWindow.layui.form.render('select');
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
                    }
                });
                break;
            // 编辑
            case 'edit':
                layer.open({
                    type: 2,
                    title: '修改',
                    maxmin: true,
                    area: [top.detailWidth, top.detailHeight],
                    shadeClose: false,
                    content: 'operateLog_detail.html',
                    success: function(layero, index){
                        setFormVal(layer.getChildFrame('#detail', index), data, false);
                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                        layero.find('iframe')[0].contentWindow.layui.form.render('select');
        return false;
                    }
                });
                break;
            case 'userId':
                var param = top.reObject(data).userId;
                if (param === undefined) {
                    layer.msg("无数据");
                } else {
                   layer.open({
                       type: 2,
                       title: '详情',
                       maxmin: true,
                       area: [top.detailHeight, top.detailWidth],
                       shadeClose: false,
                       content: '../user/user_detail.html',
                       success: function(layero, index){
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
                           $.ajax({
                               url: baseUrl+"/user/"+ param +"/auth",
                               headers: {'token': localStorage.getItem('token')},
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                               method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                               success: function (res) {
                                   if (res.code === 200){
                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
                                       layer.getChildFrame('#data-detail-submit,#prompt', index).hide();
                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
                                   } else if (res.code === 403){
                                       parent.location.href = "/";
                                   }else {
                                       layer.msg(res.msg)
                    if (self.handleForbidden(res)) {
                        return;
                                   }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                               }
                           })
                       }
                   });
                }
                break;
        }
    });
    // 数据修改动作
    form.on('submit(edit)', function () {
        var index = layer.load(1, {
            shade: [0.5,'#000'] //0.1透明度的背景
        });
        var data = {
            id: $('#id').val(),
            action: $('#action').val(),
            userId: $('#userId').val(),
            ip: $('#ip').val(),
            request: $('#request').val(),
            response: $('#response').val(),
            createTime: top.strToDate($('#createTime\\$').val()),
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
        };
        $.ajax({
            url: baseUrl+"/operateLog/edit/auth",
            headers: {'token': localStorage.getItem('token')},
            data: top.reObject(data),
            method: 'POST',
            success: function (res) {
                if (res.code === 200){
                    parent.layer.closeAll();
                    tableReload(true);
                    $("#data-detail :input").each(function () {
                        $(this).val("");
                    });
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                }else {
                    layer.msg(res.msg)
                    }));
                },
                error: function () {
                    callback([]);
                }
                layer.close(index);
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
            }
        })
    });
    // 搜索栏搜索事件
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 搜索栏重置事件
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    layDate.render({
        elem: '#createTime\\$',
        type: 'datetime'
    });
    layDate.render({
        elem: '.layui-laydate-range'
        ,type: 'datetime'
        ,range: true
    });
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    (child ? parent.tableIns : tableIns).reload({
        where: searchData,
        page: {
            curr: pageCurr
        },
        done: function (res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            if (res.data.length === 0 && count !== 0) {
                tableIns.reload({
                    where: searchData,
                    page: {
                        curr: pageCurr-1
                    }
                });
                pageCurr -= 1;
            }
            limit(child);
        }
    });
}
function setFormVal(el, data, showImg) {
    for (var val in data) {
        var find = el.find(":input[id='" + val + "']");
        find.val(data[val]);
        if (showImg){
            var next = find.next();
            if (next.get(0)){
                if (next.get(0).localName === "img") {
                    find.hide();
                    next.attr("src", data[val]);
                    next.show();
                }
            }
        }
    }
}
function clearFormVal(el) {
    $(':input', el)
        .val('')
        .removeAttr('checked')
        .removeAttr('selected');
}
function detailScreen(index) {
    var detail = layer.getChildFrame('#data-detail', index);
    var height = detail.height()+60;
    if (height > ($(window).height()*0.9)) {
        height = ($(window).height()*0.9);
    }
    layer.style(index, {
        top: (($(window).height()-height)/3)+"px",
        height: height+'px'
    });
    $(".layui-layer-shade").remove();
}
})();