Blame view

src/main/resources/static/huaheng/js/huahengUI.js 71.6 KB
tangying authored
1
2
3
4
/**
 * 通用方法封装处理
 * Copyright (c) 2018 huaheng
 */
5
6
7
8
9
10
// 当前table相关信息
var table = {
    config: {},
    // 当前实例配置
    options: {},
    // 设置实例配置
11
12
    set: function (id) {
        if ($.common.getLength(table.config) > 1) {
13
14
15
16
17
18
19
            var tableId = $.common.isEmpty(id) ? $(event.currentTarget).parents(".bootstrap-table").find(".table").attr("id") : id;
            if ($.common.isNotEmpty(tableId)) {
                table.options = table.get(tableId);
            }
        }
    },
    // 获取实例配置
20
    get: function (id) {
21
22
23
24
25
26
27
28
        return table.config[id];
    },
    // 记住选择实例组
    rememberSelecteds: {},
    // 记住选择ID组
    rememberSelectedIds: {}
};
tangying authored
29
30
(function ($) {
    $.extend({
31
32
        _tree: {},
        bttTable: {},
33
34
        // 表格封装处理
        table: {
tangying authored
35
            // 初始化表格
36
            init: function (options) {
37
38
39
40
41
                var defaults = {
                    id: "bootstrap-table",
                    type: 0, // 0 代表bootstrapTable 1代表bootstrapTreeTable
                    height: undefined,
                    sidePagination: "server",
42
43
44
                    createUrl: "",
                    updateUrl: "",
                    removeUrl: "",
45
                    printUrl: "",
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
                    sortName: "",
                    sortOrder: "asc",
                    pagination: true,
                    pageSize: 10,
                    pageList: [10, 25, 50],
                    toolbar: "toolbar",
                    striped: false,
                    escape: false,
                    firstLoad: true,
                    showFooter: false,
                    search: false,
                    showSearch: true,
                    showPageGo: false,
                    showRefresh: true,
                    showColumns: true,
                    showToggle: true,
                    showExport: false,
                    clickToSelect: false,
                    mobileResponsive: true,
                    rememberSelected: false,
                    fixedColumns: false,
                    fixedNumber: 0,
                    rightFixedColumns: false,
                    rightFixedNumber: 0,
DESKTOP-AO0VKC8\mahua authored
70
                    uniqueId: "id",
71
72
                    queryParams: $.table.queryParams,
                    rowStyle: {},
73
                    formId: "formId"
74
75
76
77
78
                };
                var options = $.extend(defaults, options);
                table.options = options;
                table.config[options.id] = options;
                $.table.initEvent();
79
                $('#' + options.id).bootstrapTable({
80
                    id: options.id,
tangying authored
81
82
                    url: options.url,                                   // 请求后台的URL(*)
                    contentType: "application/x-www-form-urlencoded",   // 编码类型
83
                    method: options.method?options.method:"post",       // 请求方式(*)
tangying authored
84
                    cache: false,                                       // 是否使用缓存
85
86
                    height: options.height,                             // 表格的高度
                    striped: options.striped,                           // 是否显示行间隔色
DESKTOP-AO0VKC8\mahua authored
87
                    modalName: "",
88
89
90
                    createUrl: options.createUrl,
                    updateUrl: options.updateUrl,
                    removeUrl: options.removeUrl,
91
                    printUrl: options.printUrl,
tangying authored
92
93
                    sortable: true,                                     // 是否启用排序
                    sortStable: true,                                   // 设置为 true 将获得稳定的排序
94
95
96
97
                    sortName: options.sortName,                         // 排序列名称
                    sortOrder: options.sortOrder,                       // 排序方式  asc 或者 desc
                    detailView: options.detailView,                     // 是否启用细节视图
                    pagination: options.pagination,                     // 是否显示分页(*)
tangying authored
98
                    pageNumber: 1,                                      // 初始化加载第一页,默认第一页
99
100
101
102
103
                    pageSize: options.pageSize,                         // 每页的记录行数(*)
                    pageList: options.pageList,                         // 可供选择的每页的行数(*)
                    firstLoad: options.firstLoad,                       // 是否首次请求加载数据,对于数据较大可以配置false
                    escape: options.escape,                             // 转义HTML字符串
                    showFooter: options.showFooter,                     // 是否显示表尾
tangying authored
104
                    iconSize: 'outline',                                // 图标大小:undefined默认的按钮尺寸 xs超小按钮sm小按钮lg大按钮
105
                    toolbar: '#' + options.toolbar,                       // 指定工作栏
106
107
108
109
110
111
112
113
114
115
116
117
                    sidePagination: options.sidePagination,             // 启用服务端分页
                    search: options.search,                             // 是否显示搜索框功能
                    showSearch: options.showSearch,                     // 是否显示检索信息
                    showPageGo: options.showPageGo,               		// 是否显示跳转页
                    showRefresh: options.showRefresh,                   // 是否显示刷新按钮
                    showColumns: options.showColumns,                   // 是否显示隐藏某列下拉框
                    showToggle: options.showToggle,                     // 是否显示详细视图和列表视图的切换按钮
                    showExport: options.showExport,                     // 是否支持导出文件
                    uniqueId: options.uniqueId,                         // 唯 一的标识符
                    clickToSelect: options.clickToSelect,				// 是否启用点击选中行
                    mobileResponsive: options.mobileResponsive,         // 是否支持移动端适配
                    onClickRow: options.onClickRow,                     // 点击某行触发的事件
118
                    onDblClickRow: function (row) {
119
120
121
122
                        if (typeof detail != 'undefined') {
                            detail(row.id, row.code)
                        }
                    },           // 双击某行触发的事件
123
124
125
126
127
128
129
130
131
132
133
134
                    onClickCell: options.onClickCell,                   // 单击某格触发的事件
                    onDblClickCell: options.onDblClickCell,             // 双击某格触发的事件
                    onEditableSave: options.onEditableSave,             // 行内编辑保存的事件
                    onExpandRow: options.onExpandRow,                   // 点击详细视图的事件
                    rememberSelected: options.rememberSelected,         // 启用翻页记住前面的选择
                    fixedColumns: options.fixedColumns,                 // 是否启用冻结列(左侧)
                    fixedNumber: options.fixedNumber,                   // 列冻结的个数(左侧)
                    rightFixedColumns: options.rightFixedColumns,       // 是否启用冻结列(右侧)
                    rightFixedNumber: options.rightFixedNumber,         // 列冻结的个数(右侧)
                    onReorderRow: options.onReorderRow,                 // 当拖拽结束后处理函数
                    queryParams: options.queryParams,                   // 传递参数(*)
                    rowStyle: options.rowStyle,                         // 通过自定义函数设置行样式
tangying authored
135
                    columns: options.columns,                           // 显示列信息(*)
136
137
138
139
                    responseHandler: $.table.responseHandler,           // 在加载服务器发送来的数据之前处理函数
                    onLoadSuccess: $.table.onLoadSuccess,               // 当所有数据被加载时触发处理函数
                    exportOptions: options.exportOptions,               // 前端导出忽略列索引
                    detailFormatter: options.detailFormatter,           // 在行下面展示其他数据列表
tangying authored
140
141
                });
            },
142
            // 获取实例ID,如存在多个返回#id1,#id2 delimeter分隔符
143
            getOptionsIds: function (separator) {
144
145
                var _separator = $.common.isEmpty(separator) ? "," : separator;
                var optionsIds = "";
146
                $.each(table.config, function (key, value) {
147
148
149
150
                    optionsIds += "#" + key + _separator;
                });
                return optionsIds.substring(0, optionsIds.length - 1);
            },
151
tangying authored
152
            // 查询条件
153
154
            queryParams: function (params) {
                return {
155
                    // 传递参数查询参数
156
157
158
159
160
                    pageSize: params.limit,
                    pageNum: params.offset / params.limit + 1,
                    searchValue: params.search,
                    orderByColumn: params.sort,
                    isAsc: params.order
161
                };
tangying authored
162
163
            },
            // 请求获取数据后处理回调函数
164
            responseHandler: function (res) {
tangying authored
165
                if (res.code == 200) {
166
                    return {rows: res.data, total: res.total};
tangying authored
167
                } else {
游杰 authored
168
                    $.modal.alertWarning(res.msg);
169
                    return {rows: [], total: 0};
tangying authored
170
171
                }
            },
172
            // 初始化事件
173
            initEvent: function () {
174
175
176
177
178
179
180
181
182
183
184
185
186
                // 实例ID信息
                var optionsIds = $.table.getOptionsIds();
                // 监听事件处理
                $(optionsIds).on(TABLE_EVENTS, function () {
                    table.set($(this).attr("id"));
                });
                // 选中、取消、全部选中、全部取消(事件)
                $(optionsIds).on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", function (e, rows) {
                    // 复选框分页保留保存选中数组
                    var rowIds = $.table.affectedRowIds(rows);
                    if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) {
                        func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference';
                        var selectedIds = table.rememberSelectedIds[table.options.id];
187
                        if ($.common.isNotEmpty(selectedIds)) {
188
189
190
191
192
                            table.rememberSelectedIds[table.options.id] = _[func](selectedIds, rowIds);
                        } else {
                            table.rememberSelectedIds[table.options.id] = _[func]([], rowIds);
                        }
                        var selectedRows = table.rememberSelecteds[table.options.id];
193
                        if ($.common.isNotEmpty(selectedRows)) {
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
                            table.rememberSelecteds[table.options.id] = _[func](selectedRows, rows);
                        } else {
                            table.rememberSelecteds[table.options.id] = _[func]([], rows);
                        }
                    }
                });
                // 加载成功、选中、取消、全部选中、全部取消(事件)
                $(optionsIds).on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table load-success.bs.table", function () {
                    var toolbar = table.options.toolbar;
                    var uniqueId = table.options.uniqueId;
                    // 工具栏按钮控制
                    var rows = $.common.isEmpty(uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(uniqueId);
                    // 非多个禁用
                    $('#' + toolbar + ' .multiple').toggleClass('disabled', !rows.length);
                    // 非单个禁用
209
                    $('#' + toolbar + ' .single').toggleClass('disabled', rows.length != 1);
210
211
                });
                // 图片预览事件
212
                $(optionsIds).off("click").on("click", '.img-circle', function () {
213
214
215
216
                    var src = $(this).attr('src');
                    var target = $(this).data('target');
                    var height = $(this).data('height');
                    var width = $(this).data('width');
217
                    if ($.common.equals("self", target)) {
218
219
220
221
222
223
224
225
226
227
228
229
230
                        layer.open({
                            title: false,
                            type: 1,
                            closeBtn: true,
                            shadeClose: true,
                            area: ['auto', 'auto'],
                            content: "<img src='" + src + "' height='" + height + "' width='" + width + "'/>"
                        });
                    } else if ($.common.equals("blank", target)) {
                        window.open(src);
                    }
                });
                // 单击tooltip事件
231
                $(optionsIds).on("click", '.tooltip-show', function () {
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
                    var target = $(this).data('target');
                    var input = $(this).prev();
                    if ($.common.equals("copy", target)) {
                        input.select();
                        document.execCommand("copy");
                    } else if ($.common.equals("open", target)) {
                        parent.layer.alert(input.val(), {
                            title: "信息内容",
                            shadeClose: true,
                            btn: ['确认'],
                            btnclass: ['btn btn-primary'],
                        });
                    }
                });
            },
            // 当所有数据被加载时触发
248
            onLoadSuccess: function (data) {
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
                if (typeof table.options.onLoadSuccess == "function") {
                    table.options.onLoadSuccess(data);
                }
                // 浮动提示框特效
                $("[data-toggle='tooltip']").tooltip();
            },
            // 表格销毁
            destroy: function (tableId) {
                var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
                $("#" + currentId).bootstrapTable('destroy');
            },
            // 序列号生成
            serialNumber: function (index, tableId) {
                var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
                var tableParams = $("#" + currentId).bootstrapTable('getOptions');
                var pageSize = tableParams.pageSize;
                var pageNumber = tableParams.pageNumber;
                return pageSize * (pageNumber - 1) + index + 1;
            },
            // 列超出指定长度浮动提示 target(copy单击复制文本 open弹窗打开文本)
            tooltip: function (value, length, target) {
                var _length = $.common.isEmpty(length) ? 20 : length;
                var _text = "";
                var _value = $.common.nullToStr(value);
                var _target = $.common.isEmpty(target) ? 'copy' : target;
                if (_value.length > _length) {
                    _text = _value.substr(0, _length) + "...";
276
                    _value = _value.replace(/\'/g, "’");
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
                    var actions = [];
                    actions.push($.common.sprintf('<input id="tooltip-show" style="opacity: 0;position: absolute;z-index:-1" type="text" value="%s"/>', _value));
                    actions.push($.common.sprintf("<a href='###' class='tooltip-show' data-toggle='tooltip' data-target='%s' title='%s'>%s</a>", _target, _value, _text));
                    return actions.join('');
                } else {
                    _text = _value;
                    return _text;
                }
            },
            // 下拉按钮切换
            dropdownToggle: function (value) {
                var actions = [];
                actions.push('<div class="btn-group">');
                actions.push('<button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown" aria-expanded="false">');
                actions.push('<i class="fa fa-cog"></i>&nbsp;<span class="fa fa-chevron-down"></span></button>');
                actions.push('<ul class="dropdown-menu">');
293
                actions.push(value.replace(/<a/g, "<li><a").replace(/<\/a>/g, "</a></li>"));
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
                actions.push('</ul>');
                actions.push('</div>');
                return actions.join('');
            },
            // 图片预览
            imageView: function (value, height, width, target) {
                if ($.common.isEmpty(width)) {
                    width = 'auto';
                }
                if ($.common.isEmpty(height)) {
                    height = 'auto';
                }
                // blank or self
                var _target = $.common.isEmpty(target) ? 'self' : target;
                if ($.common.isNotEmpty(value)) {
                    return $.common.sprintf("<img class='img-circle img-xs' data-height='%s' data-width='%s' data-target='%s' src='%s'/>", height, width, _target, value);
                } else {
                    return $.common.nullToStr(value);
                }
            },
tangying authored
314
            // 搜索
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
            search: function (formId) {
                var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
                var params = $("#bootstrap-table").bootstrapTable('getOptions');
                params.queryParams = function (params) {
                    var search = {};
                    $.each($("#" + currentId).serializeArray(), function (i, field) {
                        search[field.name] = field.value;
                    });
                    search.pageSize = params.limit;
                    search.pageNum = params.offset / params.limit + 1;
                    search.searchValue = params.search;
                    search.orderByColumn = params.sort;
                    search.isAsc = params.order;
                    return search;
                }
                $("#bootstrap-table").bootstrapTable('refresh', params);
            },
            // 下载
            exportExcel: function (formId) {
                var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
                $.modal.loading("正在导出数据,请稍后...");
336
                $.post(table.options.exportUrl, $("#" + currentId).serializeArray(), function (result) {
337
                    if (result.code == web_status.SUCCESS) {
游杰 authored
338
                        window.location.href = ctx + "common/download?fileName=" + result.msg + "&delete=" + true;
339
                    } else {
游杰 authored
340
                        $.modal.alertError(result.msg);
341
342
343
344
                    }
                    $.modal.closeLoading();
                });
            },
345
            // 下载模板
346
347
            importTemplate: function () {
                $.get($.table._option.importTemplateUrl, function (result) {
348
                    if (result.code == web_status.SUCCESS) {
游杰 authored
349
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
350
                    } else if (result.code == web_status.WARNING) {
游杰 authored
351
                        $.modal.alertWarning(result.msg)
352
                    } else {
游杰 authored
353
                        $.modal.alertError(result.msg);
354
355
356
357
                    }
                });
            },
            // 导入数据
358
            importExcel: function (formId) { //
359
360
361
362
363
364
365
366
                var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
                layer.open({
                    type: 1,
                    area: ['400px', '230px'],
                    fix: false,
                    //不固定
                    maxmin: true,
                    shade: 0.3,
367
                    title: '导入' + table.options.modalName + '数据',
368
369
370
371
                    content: $('#' + currentId).html(),
                    btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
                    // 弹层外区域关闭
                    shadeClose: true,
372
                    btn1: function (index, layero) {
373
                        var file = layero.find('#file').val();
374
                        if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))) {
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
                            $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
                            return false;
                        }
                        var index = layer.load(2, {shade: false});
                        $.modal.disable();
                        var formData = new FormData();
                        formData.append("file", $('#file')[0].files[0]);
                        formData.append("updateSupport", $("input[name='updateSupport']").is(':checked'));
                        $.ajax({
                            url: $.table._option.importUrl,
                            data: formData,
                            cache: false,
                            contentType: false,
                            processData: false,
                            type: 'POST',
                            success: function (result) {
                                if (result.code == web_status.SUCCESS) {
                                    $.modal.closeAll();
游杰 authored
393
                                    $.modal.alertSuccess(result.msg);
394
395
396
397
                                    $.table.refresh();
                                } else if (result.code == web_status.WARNING) {
                                    layer.close(index);
                                    $.modal.enable();
游杰 authored
398
                                    $.modal.alertWarning(result.msg)
399
400
401
                                } else {
                                    layer.close(index);
                                    $.modal.enable();
游杰 authored
402
                                    $.modal.alertError(result.msg);
403
404
405
406
407
408
                                }
                            }
                        });
                    }
                });
            },
409
            refresh: function (tableId) {
410
411
                var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
                $("#" + currentId).bootstrapTable('refresh', {
tangying authored
412
413
414
                    silent: true
                });
            },
415
            // 查询表格指定列值
416
            selectColumns: function (column) {
417
418
419
420
421
                var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) {
                    return row[column];
                });
                if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) {
                    var selectedRows = table.rememberSelecteds[table.options.id];
422
                    if ($.common.isNotEmpty(selectedRows)) {
423
424
425
426
427
428
429
430
                        rows = $.map(table.rememberSelecteds[table.options.id], function (row) {
                            return row[column];
                        });
                    }
                }
                return $.common.uniqueFn(rows);
            },
            // 获取当前页选中或者取消的行ID
431
            affectedRowIds: function (rows) {
432
433
434
                var column = $.common.isEmpty(table.options.uniqueId) ? table.options.columns[1].field : table.options.uniqueId;
                var rowIds;
                if ($.isArray(rows)) {
435
                    rowIds = $.map(rows, function (row) {
436
437
438
439
440
441
442
                        return row[column];
                    });
                } else {
                    rowIds = [rows[column]];
                }
                return rowIds;
            },
tangying authored
443
            // 查询选中首列值
444
            selectFirstColumns: function () {
445
446
447
448
449
                var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) {
                    return row[table.options.columns[1].field];
                });
                if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) {
                    var selectedRows = table.rememberSelecteds[table.options.id];
450
                    if ($.common.isNotEmpty(selectedRows)) {
451
452
453
454
455
456
                        rows = $.map(selectedRows, function (row) {
                            return row[table.options.columns[1].field];
                        });
                    }
                }
                return $.common.uniqueFn(rows);
tangying authored
457
458
            },
            // 回显数据字典
459
460
461
            selectDictLabel: function (_datas, _value) {
                var actions = [];
                $.each(_datas, function (index, dict) {
tangying authored
462
                    if (dict.dictValue == _value) {
463
                        actions.push("<span class='badge badge-" + dict.listClass + "'>" + dict.dictLabel + "</span>");
tangying authored
464
465
466
467
468
                        return false;
                    }
                });
                return actions.join('');
            },
469
            selectWhetherLabel: function (_value) {
470
471
472
473
                var actions = [];
                if (_value == 0) {
                    actions.push("<span class='badge badge-primary'>是</span>");
                } else {
mahuandong authored
474
475
476
477
                    actions.push("<span class='badge badge-danger'>否</span>");
                }
                return actions.join('');
            },
478
            selectLogicLabel: function (_value) {
mahuandong authored
479
480
481
482
                var actions = [];
                if (_value) {
                    actions.push("<span class='badge badge-primary'>是</span>");
                } else {
483
484
485
486
                    actions.push("<span class='badge badge-danger'>否</span>")
                }
                return actions.join('');
            },
487
488
            // 回显数据绑定的表格
            selectIdToName: function (_datas, _value) {
tangying authored
489
                var actions = [];
490
                $.each(_datas, function (index, dict) {
tangying authored
491
492
493
494
495
496
497
498
                    if (dict.id == _value) {
                        actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                        return false;
                    }
                });
                return actions.join('');
            },
            //回显数据绑定的表格
499
            selectCodeToName: function (_datas, _value) {
tangying authored
500
                var actions = [];
501
                $.each(_datas, function (index, dict) {
tangying authored
502
503
504
505
506
507
508
509
                    if (dict.code == _value) {
                        actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                        return false;
                    }
                });
                return actions.join('');
            },
            //回显数据绑定的表格
510
            selectPrefixToName: function (_datas, _value) {
tangying authored
511
                var actions = [];
512
                $.each(_datas, function (index, dict) {
tangying authored
513
514
515
516
517
518
                    if (dict.prefix == _value) {
                        actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                        return false;
                    }
                });
                return actions.join('');
519
520
            },
            // 导入数据
游杰 authored
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
            /*            importExcel: function (formId) {
                            var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
                            layer.open({
                                type: 1,
                                area: ['400px', '230px'],
                                fix: false,
                                //不固定
                                maxmin: true,
                                shade: 0.3,
                                title: '导入' + $.table._option.modalName + '数据',
                                content: $('#' + currentId).html(),
                                btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
                                // 弹层外区域关闭
                                shadeClose: true,
                                btn1: function (index, layero) {
                                    var file = layero.find('#file').val();
                                    if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))) {
                                        $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
                                        return false;
                                    }
                                    var index = layer.load(2, {shade: false});
                                    $.modal.disable();
                                    var formData = new FormData();
                                    formData.append("file", $('#file')[0].files[0]);
                                    formData.append("updateSupport", $("input[name='updateSupport']").is(':checked'));
                                    $.ajax({
                                        url: $.table._option.importUrl,
                                        data: formData,
                                        cache: false,
                                        contentType: false,
                                        processData: false,
                                        type: 'POST',
                                        success: function (result) {
                                            if (result.code == web_status.SUCCESS) {
                                                $.modal.closeAll();
                                                $.modal.alertSuccess(result.msg);
                                                $.table.refresh();
                                            } else if (result.code == web_status.WARNING) {
                                                layer.close(index);
                                                $.modal.enable();
                                                $.modal.alertWarning(result.msg)
                                            } else {
                                                layer.close(index);
                                                $.modal.enable();
                                                $.modal.alertError(result.msg);
                                            }
                                        }
                                    });
569
                                }
游杰 authored
570
571
                            });
                        },*/
572
            // 显示表格指定列
573
            showColumn: function (column, tableId) {
574
575
                var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
                $("#" + currentId).bootstrapTable('showColumn', column);
576
            },
577
            // 隐藏表格指定列
578
            hideColumn: function (column, tableId) {
579
580
581
                var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
                $("#" + currentId).bootstrapTable('hideColumn', column);
            }
tangying authored
582
583
584
585
        },
        // 表格树封装处理
        treeTable: {
            // 初始化表格
586
            init: function (options) {
mahuandong authored
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
                var defaults = {
                    id: "bootstrap-tree-table",
                    type: 1, // 0 代表bootstrapTable 1代表bootstrapTreeTable
                    height: 0,
                    rootIdValue: null,
                    ajaxParams: {},
                    toolbar: "toolbar",
                    striped: false,
                    expandColumn: 1,
                    showSearch: true,
                    showRefresh: true,
                    showColumns: true,
                    expandAll: true,
                    expandFirst: true
                };
                var options = $.extend(defaults, options);
                table.options = options;
                table.config[options.id] = options;
                $.table.initEvent();
                $.bttTable = $('#' + options.id).bootstrapTreeTable({
                    code: options.code,                                 // 用于设置父子关系
                    parentCode: options.parentCode,                     // 用于设置父子关系
                    type: 'get',                                       // 请求方式(*)
                    url: options.url,                                   // 请求后台的URL(*)
                    data: options.data,                                 // 无url时用于渲染的数据
                    ajaxParams: options.ajaxParams,                     // 请求数据的ajax的data属性
                    rootIdValue: options.rootIdValue,                   // 设置指定根节点id值
                    height: options.height,                             // 表格树的高度
                    expandColumn: options.expandColumn,                 // 在哪一列上面显示展开按钮
                    striped: options.striped,                           // 是否显示行间隔色
                    bordered: false,                                    // 是否显示边框
                    toolbar: '#' + options.toolbar,                     // 指定工作栏
                    showSearch: options.showSearch,                     // 是否显示检索信息
                    showRefresh: options.showRefresh,                   // 是否显示刷新按钮
                    showColumns: options.showColumns,                   // 是否显示隐藏某列下拉框
                    expandAll: options.expandAll,                       // 是否全部展开
                    expandFirst: options.expandFirst,                   // 是否默认第一级展开--expandAll为false时生效
                    columns: options.columns,                           // 显示列信息(*)
                    responseHandler: $.treeTable.responseHandler,       // 在加载服务器发送来的数据之前处理函数
                    onLoadSuccess: $.table.onLoadSuccess                // 当所有数据被加载时触发处理函数
                });
tangying authored
628
629
            },
            // 条件查询
630
            search: function (formId) {
mahuandong authored
631
632
633
                var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
                var params = $.common.formToJSON(currentId);
                $.bttTable.bootstrapTreeTable('refresh', params);
tangying authored
634
            },
635
            refresh: function () {
mahuandong authored
636
637
638
                $.bttTable.bootstrapTreeTable('refresh');
            },
            // 查询表格树指定列值
639
            selectColumns: function (column) {
mahuandong authored
640
641
642
643
644
645
                var rows = $.map($.bttTable.bootstrapTreeTable('getSelections'), function (row) {
                    return $.common.getItemField(row, column);
                });
                return $.common.uniqueFn(rows);
            },
            // 请求获取数据后处理回调函数,校验异常状态提醒
646
            responseHandler: function (res) {
mahuandong authored
647
648
649
650
                if (typeof table.options.responseHandler == "function") {
                    table.options.responseHandler(res);
                }
                if (res.code != undefined && res.code != 0) {
游杰 authored
651
                    $.modal.alertWarning(res.msg);
mahuandong authored
652
653
654
655
                    return [];
                } else {
                    return res;
                }
tangying authored
656
657
658
            },
        },
        // 表单封装处理
659
660
        form: {
            reset: function (formId) {
mahuandong authored
661
662
663
                var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
                $("#" + currentId)[0].reset();
            },
tangying authored
664
            // 获取选中复选框项
665
666
667
668
669
670
671
672
673
674
            selectCheckeds: function (name) {
                var checkeds = "";
                $('input:checkbox[name="' + name + '"]:checked').each(function (i) {
                    if (0 == i) {
                        checkeds = $(this).val();
                    } else {
                        checkeds += ("," + $(this).val());
                    }
                });
                return checkeds;
tangying authored
675
676
            },
            // 获取选中下拉框项
677
678
679
680
681
682
683
684
685
686
            selectSelects: function (name) {
                var selects = "";
                $('#' + name + ' option:selected').each(function (i) {
                    if (0 == i) {
                        selects = $(this).val();
                    } else {
                        selects += ("," + $(this).val());
                    }
                });
                return selects;
tangying authored
687
688
689
            }
        },
        // 弹出层封装处理
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
        modal: {
            // 显示图标
            icon: function (type) {
                var icon = "";
                if (type == modal_status.WARNING) {
                    icon = 0;
                } else if (type == modal_status.SUCCESS) {
                    icon = 1;
                } else if (type == modal_status.FAIL) {
                    icon = 2;
                } else {
                    icon = 3;
                }
                return icon;
            },
            // 消息提示
            msg: function (content, type) {
                if (type != undefined) {
                    layer.msg(content, {icon: $.modal.icon(type), time: 1000, shift: 5});
tangying authored
709
710
711
712
713
                } else {
                    layer.msg(content);
                }
            },
            // 错误消息
714
715
            msgError: function (content) {
                $.modal.msg(content, modal_status.FAIL);
tangying authored
716
717
            },
            // 成功消息
718
719
            msgSuccess: function (content) {
                $.modal.msg(content, modal_status.SUCCESS);
tangying authored
720
721
            },
            // 警告消息
722
723
724
725
726
727
728
729
730
731
732
            msgWarning: function (content) {
                $.modal.msg(content, modal_status.WARNING);
            },
            // 弹出提示
            alert: function (content, type) {
                layer.alert(content, {
                    icon: $.modal.icon(type),
                    title: "系统提示",
                    btn: ['确认'],
                    btnclass: ['btn btn-primary'],
                });
tangying authored
733
734
            },
            // 消息提示并刷新父窗体
735
736
737
738
739
740
741
742
743
            msgReload: function (msg, type) {
                layer.msg(msg, {
                        icon: $.modal.icon(type),
                        time: 500,
                        shade: [0.1, '#8F8F8F']
                    },
                    function () {
                        $.modal.reload();
                    });
tangying authored
744
745
            },
            // 错误提示
746
747
            alertError: function (content) {
                $.modal.alert(content, modal_status.FAIL);
tangying authored
748
749
            },
            // 成功提示
750
751
            alertSuccess: function (content) {
                $.modal.alert(content, modal_status.SUCCESS);
tangying authored
752
753
            },
            // 警告提示
754
755
            alertWarning: function (content) {
                $.modal.alert(content, modal_status.WARNING);
tangying authored
756
757
758
            },
            // 关闭窗体
            close: function () {
759
                var index = parent.layer.getFrameIndex(window.name);
tangying authored
760
761
762
                parent.layer.close(index);
            },
            // 确认窗体
DESKTOP-AO0VKC8\mahua authored
763
            confirm: function (content, callback) {
764
765
766
767
768
769
770
                layer.confirm(content, {
                    icon: 3,
                    title: "系统提示",
                    btn: ['确认', '取消'],
                    btnclass: ['btn btn-primary', 'btn btn-danger'],
                }, function (index) {
                    layer.close(index);
DESKTOP-AO0VKC8\mahua authored
771
                    callback(true);
772
                });
tangying authored
773
774
            },
            // 弹出层指定宽度
DESKTOP-AO0VKC8\mahua authored
775
            open: function (title, url, width, height, callback) {
776
777
778
779
780
781
                //如果是移动端,就使用自适应大小弹窗
                if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
                    width = 'auto';
                    height = 'auto';
                }
                if ($.common.isEmpty(title)) {
tangying authored
782
                    title = false;
783
784
                }
                ;
tangying authored
785
786
                if ($.common.isEmpty(url)) {
                    url = "404.html";
787
788
                }
                ;
tangying authored
789
                if ($.common.isEmpty(width)) {
790
791
792
                    width = 800;
                }
                ;
tangying authored
793
                if ($.common.isEmpty(height)) {
794
795
796
                    height = ($(window).height() - 50);
                }
                ;
DESKTOP-AO0VKC8\mahua authored
797
                if ($.common.isEmpty(callback)) {
798
                    callback = function (index, layero) {
DESKTOP-AO0VKC8\mahua authored
799
800
801
802
                        var iframeWin = layero.find('iframe')[0];
                        iframeWin.contentWindow.submitHandler(index, layero);
                    }
                }
803
804
805
806
807
808
809
810
811
                layer.open({
                    type: 2,
                    area: [width + 'px', height + 'px'],
                    fix: false,
                    //不固定
                    maxmin: true,
                    shade: 0.3,
                    title: title,
                    content: url,
DESKTOP-AO0VKC8\mahua authored
812
813
814
                    // 弹层外区域关闭
                    shadeClose: true,
                    yes: callback
815
                });
tangying authored
816
            },
mahuandong authored
817
818
819
820
821
822
823
824
            // 弹出层指定参数选项
            openOptions: function (options) {
                var _url = $.common.isEmpty(options.url) ? "/404.html" : options.url;
                var _title = $.common.isEmpty(options.title) ? "系统窗口" : options.title;
                var _width = $.common.isEmpty(options.width) ? "800" : options.width;
                var _height = $.common.isEmpty(options.height) ? ($(window).height() - 50) : options.height;
                var _btn = ['<i class="fa fa-check"></i> 确认', '<i class="fa fa-close"></i> 关闭'];
                if ($.common.isEmpty(options.yes)) {
825
                    options.yes = function (index, layero) {
mahuandong authored
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
                        options.callBack(index, layero);
                    }
                }
                layer.open({
                    type: 2,
                    maxmin: true,
                    shade: 0.3,
                    title: _title,
                    fix: false,
                    area: [_width + 'px', _height + 'px'],
                    content: _url,
                    shadeClose: $.common.isEmpty(options.shadeClose) ? true : options.shadeClose,
                    skin: options.skin,
                    btn: $.common.isEmpty(options.btn) ? _btn : options.btn,
                    yes: options.yes,
                    cancel: function () {
                        return true;
                    }
                });
            },
tangying authored
846
847
            // 弹出层全屏
            openFull: function (title, url, width, height) {
848
849
850
851
852
853
                //如果是移动端,就使用自适应大小弹窗
                if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
                    width = 'auto';
                    height = 'auto';
                }
                if ($.common.isEmpty(title)) {
tangying authored
854
                    title = false;
855
856
                }
                ;
tangying authored
857
858
                if ($.common.isEmpty(url)) {
                    url = "404.html";
859
860
                }
                ;
tangying authored
861
                if ($.common.isEmpty(width)) {
862
863
864
                    width = 800;
                }
                ;
tangying authored
865
                if ($.common.isEmpty(height)) {
866
867
868
                    height = ($(window).height() - 50);
                }
                ;
tangying authored
869
                var index = layer.open({
870
871
872
873
874
875
876
877
878
                    type: 2,
                    area: [width + 'px', height + 'px'],
                    fix: false,
                    //不固定
                    maxmin: true,
                    shade: 0.3,
                    title: title,
                    content: url
                });
tangying authored
879
880
881
882
                layer.full(index);
            },
            // 打开遮罩层
            loading: function (message) {
883
                $.blockUI({message: '<div class="loaderbox"><div class="loading-activity"></div> ' + message + '</div>'});
tangying authored
884
885
886
            },
            // 关闭遮罩层
            closeLoading: function () {
887
888
889
                setTimeout(function () {
                    $.unblockUI();
                }, 50);
tangying authored
890
891
892
            },
            // 重新加载
            reload: function () {
893
                parent.location.reload();
894
895
            },
            // 禁用按钮
896
            disable: function () {
897
898
899
900
                var doc = window.top == window.parent ? window.document : window.parent.document;
                $("a[class*=layui-layer-btn]", doc).addClass("layer-disabled");
            },
            // 启用按钮
901
            enable: function () {
902
903
904
                var doc = window.top == window.parent ? window.document : window.parent.document;
                $("a[class*=layui-layer-btn]", doc).removeClass("layer-disabled");
            },
905
906
907
908
909
910
911
912
913
914
915
916
917
918
            // 选卡页方式打开
            openTab: function (title, url) {
                createMenuItem(url, title);
            },
            // 选卡页同一页签打开
            parentTab: function (title, url) {
                var dataId = window.frameElement.getAttribute('data-id');
                createMenuItem(url, title);
                closeItem(dataId);
            },
            // 关闭选项卡
            closeTab: function (dataId) {
                closeItem(dataId);
            },
tangying authored
919
920
921
        },
        // 操作封装处理
        operate: {
922
923
924
925
926
927
928
929
930
            // 提交数据
            submit: function (url, type, dataType, data, callback) {
                debugger;
                $.modal.loading("正在处理中,请稍后...");
                var config = {
                    url: url,
                    type: type,
                    dataType: dataType,
                    data: data,
DESKTOP-AO0VKC8\mahua authored
931
932
933
                    beforeSend: function () {
                        $.modal.loading("正在处理中,请稍后...");
                    },
934
                    success: function (result) {
DESKTOP-AO0VKC8\mahua authored
935
936
937
938
939
                        if (typeof callback == "function") {
                            callback(result);
                        }
                        $.operate.ajaxSuccess(result);
                    }
940
941
                };
                $.ajax(config) // 将封装的数据放入ajax发送请求
tangying authored
942
943
            },
            // 提交数据,然后回调传入方法
944
            submitAndCallback: function (url, type, dataType, data, callback) {
tangying authored
945
946
947
948
949
950
                $.modal.loading("正在处理中,请稍后...");
                var config = {
                    url: url,
                    type: type,
                    dataType: dataType,
                    data: data,
951
                    success: function (result) {
tangying authored
952
                        if (result.code == web_status.SUCCESS) {
游杰 authored
953
                            $.modal.msgSuccess(result.msg);
tangying authored
954
955
                            callback();
                        } else {
游杰 authored
956
                            $.modal.alertError(result.msg);
tangying authored
957
958
959
960
961
962
963
                        }
                        $.modal.closeLoading();
                    }
                };
                $.ajax(config)
            },
            // post请求传输
964
965
            post: function (url, data) {
                $.operate.submit(url, "post", "json", data);
tangying authored
966
            },
967
            // 详细信息
968
            detail: function (id, width, height) {
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
                table.set();
                var _url = $.operate.detailUrl(id);
                var _width = $.common.isEmpty(width) ? "800" : width;
                var _height = $.common.isEmpty(height) ? ($(window).height() - 50) : height;
                //如果是移动端,就使用自适应大小弹窗
                if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
                    _width = 'auto';
                    _height = 'auto';
                }
                var options = {
                    title: table.options.modalName + "详细",
                    width: _width,
                    height: _height,
                    url: _url,
                    skin: 'layui-layer-gray',
                    btn: ['关闭'],
                    yes: function (index, layero) {
                        layer.close(index);
                    }
                };
                $.modal.openOptions(options);
            },
            // 详细访问地址
992
            detailUrl: function (id) {
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
                var url = "/404.html";
                if ($.common.isNotEmpty(id)) {
                    url = table.options.detailUrl.replace("{id}", id);
                } else {
                    var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
                    if (id.length == 0) {
                        $.modal.alertWarning("请至少选择一条记录");
                        return;
                    }
                    url = table.options.detailUrl.replace("{id}", id);
                }
                return url;
            },
1006
1007
            // 删除信息 每一条信息后面有一个删除的操作调用该函数
            remove: function (id) {
mahuandong authored
1008
                table.set();
1009
1010
1011
1012
1013
                $.modal.confirm("确定删除该条" + table.options.modalName + "信息吗?", function () {
                    var url = $.common.isEmpty(id) ? table.options.removeUrl : table.options.removeUrl.replace("{id}", id);
                    var data = {"ids": id};
                    $.operate.submit(url, "post", "json", data);
                });
tangying authored
1014
1015
            },
            // 批量删除信息
1016
            batRemove: function () {
mahuandong authored
1017
                table.set();
1018
1019
1020
1021
1022
                var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
                if (rows.length == 0) {
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }
1023
1024
                $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function () {
                    var url = table.options.removeUrl; //
1025
1026
1027
                    var data = {"ids": rows.join()};
                    $.operate.submit(url, "post", "json", data);
                });
tangying authored
1028
            },
1029
1030
            // 批量打印信息
            batPrint: function () {
1031
                debugger;
1032
                table.set(); // 将当前页的table传入这边保存table信息
游杰 authored
1033
1034
                var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() :
                    $.table.selectColumns(table.options.uniqueId); // 判断是否有选中的记录返回行或第一行
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
                if (rows.length == 0) {
                    $.modal.alertWarning("请至少选择一条记录"); // 警告框
                    return; // 返回后面都不会执行了
                }
                $.modal.confirm("确认要打印选中的" + rows.length + "条数据吗?", function () {
                    var url = table.options.printUrl; //
                    var param = "";
                    $(rows).each(function (i, item) {
                        //对集合进行操作
                        if (i < rows.length - 1)
                            param += item + ",";
                        else
                            param += item;
                    });
游杰 authored
1049
1050
                    window.open(url + "/" + param, '_blank',
                        'menubar=no,toolbar=no, status=no,scrollbars=yes'); // 弹出pdf打印预览页面
1051
1052
1053
1054
                    // $.windows.open() JQfunction
                    // 拼接参数data
                });
            },
tangying authored
1055
            // 添加信息
1056
            add: function (id) {
1057
                table.set();
1058
                var url = $.common.isEmpty(id) ? table.options.createUrl : table.options.createUrl.replace("{id}", id);
1059
                $.modal.open("添加" + table.options.modalName, url);
tangying authored
1060
1061
            },
            // 修改信息
1062
            edit: function (id) {
1063
                table.set();
1064
1065
                var url = table.options.updateUrl.replace("{id}", id);
                $.modal.open("修改" + table.options.modalName, url);
tangying authored
1066
            },
mahuandong authored
1067
            // 修改信息,以tab页展现
1068
            editTab: function (id) {
mahuandong authored
1069
1070
1071
1072
                table.set();
                $.modal.openTab("修改" + table.options.modalName, $.operate.editUrl(id));
            },
            // 修改访问地址
1073
            editUrl: function (id) {
mahuandong authored
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
                var url = "/404.html";
                if ($.common.isNotEmpty(id)) {
                    url = table.options.updateUrl.replace("{id}", id);
                } else {
                    var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
                    if (id.length == 0) {
                        $.modal.alertWarning("请至少选择一条记录");
                        return;
                    }
                    url = table.options.updateUrl.replace("{id}", id);
                }
                return url;
            },
tangying authored
1087
            //查看
1088
            checklook: function (id) {
1089
1090
1091
                table.set();
                var url = table.options.updateUrl.replace("{id}", id);
                $.modal.open("查看" + table.options.modalName, url);
tangying authored
1092
1093
            },
            // 添加信息 全屏
1094
            addFull: function (id) {
1095
                table.set();
1096
                var url = $.common.isEmpty(id) ? table.options.createUrl : $.table.options.createUrl.replace("{id}", id);
1097
                $.modal.openFull("添加" + table.options.modalName, url);
tangying authored
1098
1099
            },
            // 修改信息 全屏
1100
            editFull: function (id) {
1101
                table.set();
1102
1103
                var url = table.options.updateUrl.replace("{id}", id);
                $.modal.openFull("修改" + table.options.modalName, url);
tangying authored
1104
1105
            },
            // 保存信息
1106
1107
1108
1109
1110
1111
1112
1113
1114
            save: function (url, data) {
                $.modal.loading("正在处理中,请稍后...");
                var config = {
                    url: url,
                    type: "post",
                    dataType: "json",
                    data: data,
                    success: function (result) {
                        $.operate.saveSuccess(result);
1115
                        $.modal.close();
1116
1117
1118
                    }
                };
                $.ajax(config)
tangying authored
1119
            },
mahuandong authored
1120
            // 保存信息 弹出提示框
1121
            saveModal: function (url, data, callback) {
mahuandong authored
1122
1123
1124
1125
1126
1127
1128
1129
                var config = {
                    url: url,
                    type: "post",
                    dataType: "json",
                    data: data,
                    beforeSend: function () {
                        $.modal.loading("正在处理中,请稍后...");
                    },
1130
                    success: function (result) {
mahuandong authored
1131
1132
1133
1134
                        if (typeof callback == "function") {
                            callback(result);
                        }
                        if (result.code == web_status.SUCCESS) {
游杰 authored
1135
                            $.modal.alertSuccess(result.msg)
mahuandong authored
1136
                        } else if (result.code == web_status.WARNING) {
游杰 authored
1137
                            $.modal.alertWarning(result.msg)
mahuandong authored
1138
                        } else {
游杰 authored
1139
                            $.modal.alertError(result.msg);
mahuandong authored
1140
1141
1142
1143
1144
1145
1146
                        }
                        $.modal.closeLoading();
                    }
                };
                $.ajax(config)
            },
            // 保存选项卡信息
1147
            saveTab: function (url, data, callback) {
mahuandong authored
1148
1149
1150
1151
1152
1153
1154
1155
                var config = {
                    url: url,
                    type: "post",
                    dataType: "json",
                    data: data,
                    beforeSend: function () {
                        $.modal.loading("正在处理中,请稍后...");
                    },
1156
                    success: function (result) {
mahuandong authored
1157
1158
1159
                        if (typeof callback == "function") {
                            callback(result);
                        }
1160
1161
                        $.operate.saveSuccess(result);
                        // $.operate.successTabCallback(result); // 未能正确关闭
mahuandong authored
1162
1163
1164
1165
                    }
                };
                $.ajax(config)
            },
tangying authored
1166
1167
            // 保存结果弹出msg刷新table表格
            ajaxSuccess: function (result) {
1168
                if (result.code == web_status.SUCCESS) {
游杰 authored
1169
                    $.modal.msgSuccess(result.msg);
1170
                    $.table.refresh();
tangying authored
1171
                } else {
游杰 authored
1172
                    $.modal.alertError(result.msg);
tangying authored
1173
                }
1174
                $.modal.closeLoading();
tangying authored
1175
1176
1177
            },
            // 保存结果提示msg
            saveSuccess: function (result) {
1178
1179
                if (result.code == web_status.SUCCESS) {
                    $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
tangying authored
1180
                } else {
游杰 authored
1181
                    $.modal.alertError(result.msg);
tangying authored
1182
                }
1183
                $.modal.closeLoading();
mahuandong authored
1184
1185
            },
            // 选项卡成功回调执行事件(父窗体静默更新)
yihao.liu authored
1186
            successTabCallback: function (result) { // 只有创建tab才能正常关闭 提出框不能正常操作
mahuandong authored
1187
1188
1189
1190
1191
                if (result.code == web_status.SUCCESS) {
                    var topWindow = $(window.parent.document);
                    var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-panel');
                    var $contentWindow = $('.RuoYi_iframe[data-id="' + currentId + '"]', topWindow)[0].contentWindow;
                    $.modal.close();
游杰 authored
1192
                    $contentWindow.$.modal.msgSuccess(result.msg);
mahuandong authored
1193
1194
1195
1196
1197
1198
1199
1200
                    $contentWindow.$(".layui-layer-padding").removeAttr("style");
                    if ($contentWindow.table.options.type == table_type.bootstrapTable) {
                        $contentWindow.$.table.refresh();
                    } else if ($contentWindow.table.options.type == table_type.bootstrapTreeTable) {
                        $contentWindow.$.treeTable.refresh();
                    }
                    $.modal.closeTab();
                } else if (result.code == web_status.WARNING) {
游杰 authored
1201
                    $.modal.alertWarning(result.msg)
mahuandong authored
1202
                } else {
游杰 authored
1203
                    $.modal.alertError(result.msg);
mahuandong authored
1204
1205
                }
                $.modal.closeLoading();
tangying authored
1206
1207
            }
        },
mahuandong authored
1208
1209
1210
1211
1212
        // 树插件封装处理
        tree: {
            _option: {},
            _lastValue: {},
            // 初始化树结构
1213
            init: function (options) {
mahuandong authored
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
                var defaults = {
                    id: "tree",                    // 属性ID
                    expandLevel: 0,                // 展开等级节点
                    view: {
                        selectedMulti: false,      // 设置是否允许同时选中多个节点
                        nameIsHTML: true           // 设置 name 属性是否支持 HTML 脚本
                    },
                    check: {
                        enable: false,             // 置 zTree 的节点上是否显示 checkbox / radio
                        nocheckInherit: true,      // 设置子节点是否自动继承
                    },
                    data: {
                        key: {
                            title: "title"         // 节点数据保存节点提示信息的属性名称
                        },
                        simpleData: {
                            enable: true           // true / false 分别表示 使用 / 不使用 简单数据模式
                        }
                    },
                };
                var options = $.extend(defaults, options);
                $.tree._option = options;
                // 树结构初始化加载
                var setting = {
                    callback: {
                        onClick: options.onClick,                      // 用于捕获节点被点击的事件回调函数
                        onCheck: options.onCheck,                      // 用于捕获 checkbox / radio 被勾选 或 取消勾选的事件回调函数
                        onDblClick: options.onDblClick                 // 用于捕获鼠标双击之后的事件回调函数
                    },
                    check: options.check,
                    view: options.view,
                    data: options.data
                };
1247
                $.get(options.url, function (data) {
mahuandong authored
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
                    var treeId = $("#treeId").val();
                    tree = $.fn.zTree.init($("#" + options.id), setting, data);
                    $._tree = tree;
                    for (var i = 0; i < options.expandLevel; i++) {
                        var nodes = tree.getNodesByParam("level", i);
                        for (var j = 0; j < nodes.length; j++) {
                            tree.expandNode(nodes[j], true, false, false);
                        }
                    }
                    var node = tree.getNodesByParam("id", treeId, null)[0];
                    $.tree.selectByIdName(treeId, node);
                });
            },
            // 搜索节点
1262
            searchNode: function () {
mahuandong authored
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
                // 取得输入的关键字的值
                var value = $.common.trim($("#keyword").val());
                if ($.tree._lastValue == value) {
                    return;
                }
                // 保存最后一次搜索名称
                $.tree._lastValue = value;
                var nodes = $._tree.getNodes();
                // 如果要查空字串,就退出不查了。
                if (value == "") {
                    $.tree.showAllNode(nodes);
                    return;
                }
                $.tree.hideAllNode(nodes);
                // 根据搜索值模糊匹配
                $.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value));
            },
            // 根据Id和Name选中指定节点
1281
            selectByIdName: function (treeId, node) {
mahuandong authored
1282
1283
1284
1285
1286
                if ($.common.isNotEmpty(treeId) && treeId == node.id) {
                    $._tree.selectNode(node, true);
                }
            },
            // 显示所有节点
1287
            showAllNode: function (nodes) {
mahuandong authored
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
                nodes = $._tree.transformToArray(nodes);
                for (var i = nodes.length - 1; i >= 0; i--) {
                    if (nodes[i].getParentNode() != null) {
                        $._tree.expandNode(nodes[i], true, false, false, false);
                    } else {
                        $._tree.expandNode(nodes[i], true, true, false, false);
                    }
                    $._tree.showNode(nodes[i]);
                    $.tree.showAllNode(nodes[i].children);
                }
            },
            // 隐藏所有节点
1300
            hideAllNode: function (nodes) {
mahuandong authored
1301
1302
1303
1304
1305
1306
1307
                var tree = $.fn.zTree.getZTreeObj("tree");
                var nodes = $._tree.transformToArray(nodes);
                for (var i = nodes.length - 1; i >= 0; i--) {
                    $._tree.hideNode(nodes[i]);
                }
            },
            // 显示所有父节点
1308
            showParent: function (treeNode) {
mahuandong authored
1309
1310
1311
1312
1313
1314
1315
1316
                var parentNode;
                while ((parentNode = treeNode.getParentNode()) != null) {
                    $._tree.showNode(parentNode);
                    $._tree.expandNode(parentNode, true, false, false);
                    treeNode = parentNode;
                }
            },
            // 显示所有孩子节点
1317
            showChildren: function (treeNode) {
mahuandong authored
1318
1319
1320
1321
1322
1323
1324
1325
1326
                if (treeNode.isParent) {
                    for (var idx in treeNode.children) {
                        var node = treeNode.children[idx];
                        $._tree.showNode(node);
                        $.tree.showChildren(node);
                    }
                }
            },
            // 更新节点状态
1327
            updateNodes: function (nodeList) {
mahuandong authored
1328
1329
1330
1331
1332
1333
1334
1335
                $._tree.showNodes(nodeList);
                for (var i = 0, l = nodeList.length; i < l; i++) {
                    var treeNode = nodeList[i];
                    $.tree.showChildren(treeNode);
                    $.tree.showParent(treeNode)
                }
            },
            // 获取当前被勾选集合
1336
            getCheckedNodes: function (column) {
mahuandong authored
1337
1338
1339
1340
1341
1342
1343
                var _column = $.common.isEmpty(column) ? "id" : column;
                var nodes = $._tree.getCheckedNodes(true);
                return $.map(nodes, function (row) {
                    return row[_column];
                }).join();
            },
            // 不允许根父节点选择
1344
            notAllowParents: function (_tree) {
mahuandong authored
1345
                var nodes = _tree.getSelectedNodes();
1346
                if (nodes.length == 0) {
mahuandong authored
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
                    $.modal.msgError("请选择节点后提交");
                    return false;
                }
                for (var i = 0; i < nodes.length; i++) {
                    if (nodes[i].level == 0) {
                        $.modal.msgError("不能选择根节点(" + nodes[i].name + ")");
                        return false;
                    }
                    if (nodes[i].isParent) {
                        $.modal.msgError("不能选择父节点(" + nodes[i].name + ")");
                        return false;
                    }
                }
                return true;
            },
            // 不允许最后层级节点选择
1363
            notAllowLastLevel: function (_tree) {
mahuandong authored
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
                var nodes = _tree.getSelectedNodes();
                for (var i = 0; i < nodes.length; i++) {
                    if (!nodes[i].isParent) {
                        $.modal.msgError("不能选择最后层级节点(" + nodes[i].name + ")");
                        return false;
                    }
                }
                return true;
            },
            // 隐藏/显示搜索栏
1374
            toggleSearch: function () {
mahuandong authored
1375
1376
1377
1378
1379
1380
                $('#search').slideToggle(200);
                $('#btnShow').toggle();
                $('#btnHide').toggle();
                $('#keyword').focus();
            },
            // 折叠
1381
            collapse: function () {
mahuandong authored
1382
1383
1384
                $._tree.expandAll(false);
            },
            // 展开
1385
            expand: function () {
mahuandong authored
1386
1387
1388
                $._tree.expandAll(true);
            }
        },
tangying authored
1389
        // 通用方法封装处理
1390
        common: {
1391
            // 判断字符串是否是以start开头
1392
            startWith: function (value, start) {
1393
1394
1395
1396
                var reg = new RegExp("^" + start);
                return reg.test(value)
            },
            // 判断字符串是否是以end结尾
1397
            endWith: function (value, end) {
1398
1399
1400
                var reg = new RegExp(end + "$");
                return reg.test(value)
            },
1401
            // 判断字符串是否为空
tangying authored
1402
1403
1404
1405
1406
1407
            isEmpty: function (value) {
                if (value == null || this.trim(value) == "") {
                    return true;
                }
                return false;
            },
1408
1409
1410
1411
            // 判断一个字符串是否为非空串
            isNotEmpty: function (value) {
                return !$.common.isEmpty(value);
            },
1412
            // 空对象转字符串
1413
            nullToStr: function (value) {
1414
1415
1416
1417
1418
                if ($.common.isEmpty(value)) {
                    return "-";
                }
                return value;
            },
tangying authored
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
            // 是否显示数据 为空默认为显示
            visible: function (value) {
                if ($.common.isEmpty(value) || value == true) {
                    return true;
                }
                return false;
            },
            // 空格截取
            trim: function (value) {
                if (value == null) {
                    return "";
                }
                return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
            },
1433
1434
1435
1436
1437
1438
1439
1440
            // 比较两个字符串(大小写敏感)
            equals: function (str, that) {
                return str == that;
            },
            // 比较两个字符串(大小写不敏感)
            equalsIgnoreCase: function (str, that) {
                return String(str).toUpperCase() === String(that).toUpperCase();
            },
tangying authored
1441
1442
1443
1444
            // 指定随机数返回
            random: function (min, max) {
                return Math.floor((Math.random() * max) + min);
            },
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
            // 将字符串按指定字符分割
            split: function (str, sep, maxLen) {
                if ($.common.isEmpty(str)) {
                    return null;
                }
                var value = String(str).split(sep);
                return maxLen ? value.slice(0, maxLen - 1) : value;
            },
            // 字符串格式化(%s )
            sprintf: function (str) {
                var args = arguments, flag = true, i = 1;
                str = str.replace(/%s/g, function () {
                    var arg = args[i++];
                    if (typeof arg === 'undefined') {
                        flag = false;
                        return '';
                    }
                    return arg;
                });
                return flag ? str : '';
            },
            // 数组去重
1467
            uniqueFn: function (array) {
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
                var result = [];
                var hashObj = {};
                for (var i = 0; i < array.length; i++) {
                    if (!hashObj[array[i]]) {
                        hashObj[array[i]] = true;
                        result.push(array[i]);
                    }
                }
                return result;
            },
tangying authored
1478
1479
1480
1481
            // 序列化表单
            getTableValue: function (formName) {
                var tableValue = $(formName).serialize();
                //如果存在enable字段就从序列化中删除,然后
1482
                if ($("input[name='enable']").length > 0) {
tangying authored
1483
                    var beginIndex = tableValue.indexOf("&enable");
1484
1485
1486
                    if (beginIndex > -1) {
                        var endIndex = tableValue.indexOf("&", beginIndex + 1);
                        if (endIndex > -1) {
tangying authored
1487
                            tableValue = tableValue.substring(0, beginIndex) + tableValue.substring(endIndex, tableValue.length);
1488
                        } else {
tangying authored
1489
1490
1491
1492
1493
1494
                            tableValue = tableValue.substring(0, beginIndex);
                        }
                    }
                    tableValue = tableValue + "&enable=" + $("input[name='enable']").is(':checked')
                }
                return tableValue;
1495
1496
            },
            // 获取form下所有的字段并转换为json对象
1497
            formToJSON: function (formId) {
1498
                var json = {};
1499
1500
                $.each($("#" + formId).serializeArray(), function (i, field) {
                    if (json[field.name]) {
1501
1502
1503
1504
1505
1506
1507
1508
                        json[field.name] += ("," + field.value);
                    } else {
                        json[field.name] = field.value;
                    }
                });
                return json;
            },
            // 获取obj对象长度
1509
            getLength: function (obj) {
1510
1511
1512
1513
1514
1515
1516
                var count = 0;
                for (var i in obj) {
                    if (obj.hasOwnProperty(i)) {
                        count++;
                    }
                }
                return count;
tangying authored
1517
            }
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
        },
        // 校验封装处理
        validate: {
            // 判断返回标识是否唯一 false 不存在 true 存在
            unique: function (value) {
                if (value == "0") {
                    return true;
                }
                return false;
            },
            // 表单验证
            form: function (formId) {
                var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
                return $("#" + currentId).validate().form();
            },
            // 重置表单验证(清除提示信息)
            reset: function (formId) {
                var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
                return $("#" + currentId).validate().resetForm();
            }
        },
tangying authored
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
    });
})(jQuery);

/** 消息状态码 */
web_status = {
    SUCCESS: 200,
    FAIL: 400
};

/** 弹窗状态码 */
modal_status = {
    SUCCESS: "success",
    FAIL: "error",
    WARNING: "warning"
1553
1554
1555
1556
1557
1558
};

/** 表格类型 */
table_type = {
    bootstrapTable: 0,
    bootstrapTreeTable: 1
1559
};