|
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: {}
};
|
|
29
30
|
(function ($) {
$.extend({
|
|
31
32
|
_tree: {},
bttTable: {},
|
|
33
34
|
// 表格封装处理
table: {
|
|
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,
|
|
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,
|
|
81
82
|
url: options.url, // 请求后台的URL(*)
contentType: "application/x-www-form-urlencoded", // 编码类型
|
|
83
|
method: options.method?options.method:"post", // 请求方式(*)
|
|
84
|
cache: false, // 是否使用缓存
|
|
85
86
|
height: options.height, // 表格的高度
striped: options.striped, // 是否显示行间隔色
|
|
87
|
modalName: "",
|
|
88
89
90
|
createUrl: options.createUrl,
updateUrl: options.updateUrl,
removeUrl: options.removeUrl,
|
|
91
|
printUrl: options.printUrl,
|
|
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, // 是否显示分页(*)
|
|
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, // 是否显示表尾
|
|
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
|
if (typeof detail != 'undefined') {
detail(row.id, row.code)
}
|
|
122
|
|
|
123
|
}, // 双击某行触发的事件
|
|
124
125
126
127
128
129
130
131
132
133
134
135
|
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, // 通过自定义函数设置行样式
|
|
136
|
columns: options.columns, // 显示列信息(*)
|
|
137
138
139
140
|
responseHandler: $.table.responseHandler, // 在加载服务器发送来的数据之前处理函数
onLoadSuccess: $.table.onLoadSuccess, // 当所有数据被加载时触发处理函数
exportOptions: options.exportOptions, // 前端导出忽略列索引
detailFormatter: options.detailFormatter, // 在行下面展示其他数据列表
|
|
141
142
|
});
},
|
|
143
|
// 获取实例ID,如存在多个返回#id1,#id2 delimeter分隔符
|
|
144
|
getOptionsIds: function (separator) {
|
|
145
146
|
var _separator = $.common.isEmpty(separator) ? "," : separator;
var optionsIds = "";
|
|
147
|
$.each(table.config, function (key, value) {
|
|
148
149
150
151
|
optionsIds += "#" + key + _separator;
});
return optionsIds.substring(0, optionsIds.length - 1);
},
|
|
152
|
|
|
153
|
// 查询条件
|
|
154
155
|
queryParams: function (params) {
return {
|
|
156
|
// 传递参数查询参数
|
|
157
158
159
160
161
|
pageSize: params.limit,
pageNum: params.offset / params.limit + 1,
searchValue: params.search,
orderByColumn: params.sort,
isAsc: params.order
|
|
162
|
};
|
|
163
164
|
},
// 请求获取数据后处理回调函数
|
|
165
|
responseHandler: function (res) {
|
|
166
|
if (res.code == 200) {
|
|
167
|
return {rows: res.data, total: res.total};
|
|
168
|
} else {
|
|
169
|
$.modal.alertWarning(res.msg);
|
|
170
|
return {rows: [], total: 0};
|
|
171
172
|
}
},
|
|
173
|
// 初始化事件
|
|
174
|
initEvent: function () {
|
|
175
176
177
178
179
180
181
182
183
184
185
186
187
|
// 实例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];
|
|
188
|
if ($.common.isNotEmpty(selectedIds)) {
|
|
189
190
191
192
193
|
table.rememberSelectedIds[table.options.id] = _[func](selectedIds, rowIds);
} else {
table.rememberSelectedIds[table.options.id] = _[func]([], rowIds);
}
var selectedRows = table.rememberSelecteds[table.options.id];
|
|
194
|
if ($.common.isNotEmpty(selectedRows)) {
|
|
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
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);
// 非单个禁用
|
|
210
|
$('#' + toolbar + ' .single').toggleClass('disabled', rows.length != 1);
|
|
211
212
|
});
// 图片预览事件
|
|
213
|
$(optionsIds).off("click").on("click", '.img-circle', function () {
|
|
214
215
216
217
|
var src = $(this).attr('src');
var target = $(this).data('target');
var height = $(this).data('height');
var width = $(this).data('width');
|
|
218
|
if ($.common.equals("self", target)) {
|
|
219
220
221
222
223
224
225
226
227
228
229
230
231
|
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事件
|
|
232
|
$(optionsIds).on("click", '.tooltip-show', function () {
|
|
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
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'],
});
}
});
},
// 当所有数据被加载时触发
|
|
249
|
onLoadSuccess: function (data) {
|
|
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
276
|
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) + "...";
|
|
277
|
_value = _value.replace(/\'/g, "’");
|
|
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
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> <span class="fa fa-chevron-down"></span></button>');
actions.push('<ul class="dropdown-menu">');
|
|
294
|
actions.push(value.replace(/<a/g, "<li><a").replace(/<\/a>/g, "</a></li>"));
|
|
295
296
297
298
299
300
301
|
actions.push('</ul>');
actions.push('</div>');
return actions.join('');
},
// 图片预览
imageView: function (value, height, width, target) {
if ($.common.isEmpty(width)) {
|
|
302
|
width = '500';
|
|
303
304
|
}
if ($.common.isEmpty(height)) {
|
|
305
|
height = '500';
|
|
306
307
308
309
|
}
// blank or self
var _target = $.common.isEmpty(target) ? 'self' : target;
if ($.common.isNotEmpty(value)) {
|
|
310
|
return $.common.sprintf("<img class='img-circle img-xs' data-height='%s' data-width='%s' data-target='%s' style='width: 80px; height: auto' src='%s'/>", height, width, _target, value);
|
|
311
312
313
314
|
} else {
return $.common.nullToStr(value);
}
},
|
|
315
|
// 搜索
|
|
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
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("正在导出数据,请稍后...");
|
|
337
|
$.post(table.options.exportUrl, $("#" + currentId).serializeArray(), function (result) {
|
|
338
|
if (result.code == web_status.SUCCESS) {
|
|
339
|
window.location.href = ctx + "common/download?fileName=" + result.msg + "&delete=" + true;
|
|
340
|
} else {
|
|
341
|
$.modal.alertError(result.msg);
|
|
342
343
344
345
|
}
$.modal.closeLoading();
});
},
|
|
346
|
// 下载模板
|
|
347
|
importTemplate: function () {
|
|
348
|
$.get(table.options.importTemplateUrl, function (result) {
|
|
349
|
if (result.code == web_status.SUCCESS) {
|
|
350
|
window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
|
|
351
|
} else if (result.code == web_status.WARNING) {
|
|
352
|
$.modal.alertWarning(result.msg)
|
|
353
|
} else {
|
|
354
|
$.modal.alertError(result.msg);
|
|
355
356
357
358
|
}
});
},
// 导入数据
|
|
359
|
importExcel: function (formId) { //
|
|
360
361
362
363
364
365
366
367
|
var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
layer.open({
type: 1,
area: ['400px', '230px'],
fix: false,
//不固定
maxmin: true,
shade: 0.3,
|
|
368
|
title: '导入' + table.options.modalName + '数据',
|
|
369
370
371
372
|
content: $('#' + currentId).html(),
btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
// 弹层外区域关闭
shadeClose: true,
|
|
373
|
btn1: function (index, layero) {
|
|
374
|
var file = layero.find('#file').val();
|
|
375
|
if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))) {
|
|
376
377
378
379
380
381
382
383
384
|
$.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({
|
|
385
|
url: table.options.importUrl,
|
|
386
387
388
389
390
391
392
|
data: formData,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function (result) {
if (result.code == web_status.SUCCESS) {
|
|
393
|
layer.closeAll();
|
|
394
|
$.modal.alertSuccess(result.msg);
|
|
395
396
397
398
|
$.table.refresh();
} else if (result.code == web_status.WARNING) {
layer.close(index);
$.modal.enable();
|
|
399
|
$.modal.alertWarning(result.msg)
|
|
400
401
402
|
} else {
layer.close(index);
$.modal.enable();
|
|
403
|
$.modal.alertError(result.msg);
|
|
404
405
406
407
408
409
|
}
}
});
}
});
},
|
|
410
|
refresh: function (tableId) {
|
|
411
412
|
var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
$("#" + currentId).bootstrapTable('refresh', {
|
|
413
414
415
|
silent: true
});
},
|
|
416
|
// 查询表格指定列值
|
|
417
|
selectColumns: function (column) {
|
|
418
419
420
421
422
|
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];
|
|
423
|
if ($.common.isNotEmpty(selectedRows)) {
|
|
424
425
426
427
428
429
430
431
|
rows = $.map(table.rememberSelecteds[table.options.id], function (row) {
return row[column];
});
}
}
return $.common.uniqueFn(rows);
},
// 获取当前页选中或者取消的行ID
|
|
432
|
affectedRowIds: function (rows) {
|
|
433
434
435
|
var column = $.common.isEmpty(table.options.uniqueId) ? table.options.columns[1].field : table.options.uniqueId;
var rowIds;
if ($.isArray(rows)) {
|
|
436
|
rowIds = $.map(rows, function (row) {
|
|
437
438
439
440
441
442
443
|
return row[column];
});
} else {
rowIds = [rows[column]];
}
return rowIds;
},
|
|
444
|
// 查询选中首列值
|
|
445
|
selectFirstColumns: function () {
|
|
446
447
448
449
450
|
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];
|
|
451
|
if ($.common.isNotEmpty(selectedRows)) {
|
|
452
453
454
455
456
457
|
rows = $.map(selectedRows, function (row) {
return row[table.options.columns[1].field];
});
}
}
return $.common.uniqueFn(rows);
|
|
458
459
|
},
// 回显数据字典
|
|
460
461
462
|
selectDictLabel: function (_datas, _value) {
var actions = [];
$.each(_datas, function (index, dict) {
|
|
463
|
if (dict.dictValue == _value) {
|
|
464
|
actions.push("<span class='badge badge-" + dict.listClass + "'>" + dict.dictLabel + "</span>");
|
|
465
466
467
468
469
|
return false;
}
});
return actions.join('');
},
|
|
470
|
selectWhetherLabel: function (_value) {
|
|
471
472
473
474
|
var actions = [];
if (_value == 0) {
actions.push("<span class='badge badge-primary'>是</span>");
} else {
|
|
475
476
477
478
|
actions.push("<span class='badge badge-danger'>否</span>");
}
return actions.join('');
},
|
|
479
|
selectLogicLabel: function (_value) {
|
|
480
481
482
483
|
var actions = [];
if (_value) {
actions.push("<span class='badge badge-primary'>是</span>");
} else {
|
|
484
485
486
487
|
actions.push("<span class='badge badge-danger'>否</span>")
}
return actions.join('');
},
|
|
488
489
|
// 回显数据绑定的表格
selectIdToName: function (_datas, _value) {
|
|
490
|
var actions = [];
|
|
491
|
$.each(_datas, function (index, dict) {
|
|
492
493
494
495
496
497
498
499
|
if (dict.id == _value) {
actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
return false;
}
});
return actions.join('');
},
//回显数据绑定的表格
|
|
500
|
selectCodeToName: function (_datas, _value) {
|
|
501
|
var actions = [];
|
|
502
|
$.each(_datas, function (index, dict) {
|
|
503
504
505
506
507
508
509
510
|
if (dict.code == _value) {
actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
return false;
}
});
return actions.join('');
},
//回显数据绑定的表格
|
|
511
|
selectPrefixToName: function (_datas, _value) {
|
|
512
|
var actions = [];
|
|
513
|
$.each(_datas, function (index, dict) {
|
|
514
515
516
517
518
519
|
if (dict.prefix == _value) {
actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
return false;
}
});
return actions.join('');
|
|
520
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
569
|
/* 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);
}
}
});
|
|
570
|
}
|
|
571
572
|
});
},*/
|
|
573
|
// 显示表格指定列
|
|
574
|
showColumn: function (column, tableId) {
|
|
575
576
|
var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
$("#" + currentId).bootstrapTable('showColumn', column);
|
|
577
|
},
|
|
578
|
// 隐藏表格指定列
|
|
579
|
hideColumn: function (column, tableId) {
|
|
580
581
582
|
var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
$("#" + currentId).bootstrapTable('hideColumn', column);
}
|
|
583
584
585
586
|
},
// 表格树封装处理
treeTable: {
// 初始化表格
|
|
587
|
init: function (options) {
|
|
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
628
|
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 // 当所有数据被加载时触发处理函数
});
|
|
629
630
|
},
// 条件查询
|
|
631
|
search: function (formId) {
|
|
632
633
634
|
var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
var params = $.common.formToJSON(currentId);
$.bttTable.bootstrapTreeTable('refresh', params);
|
|
635
|
},
|
|
636
|
refresh: function () {
|
|
637
638
639
|
$.bttTable.bootstrapTreeTable('refresh');
},
// 查询表格树指定列值
|
|
640
|
selectColumns: function (column) {
|
|
641
642
643
644
645
646
|
var rows = $.map($.bttTable.bootstrapTreeTable('getSelections'), function (row) {
return $.common.getItemField(row, column);
});
return $.common.uniqueFn(rows);
},
// 请求获取数据后处理回调函数,校验异常状态提醒
|
|
647
|
responseHandler: function (res) {
|
|
648
649
650
651
|
if (typeof table.options.responseHandler == "function") {
table.options.responseHandler(res);
}
if (res.code != undefined && res.code != 0) {
|
|
652
|
$.modal.alertWarning(res.msg);
|
|
653
654
655
656
|
return [];
} else {
return res;
}
|
|
657
658
659
|
},
},
// 表单封装处理
|
|
660
661
|
form: {
reset: function (formId) {
|
|
662
663
664
|
var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
$("#" + currentId)[0].reset();
},
|
|
665
|
// 获取选中复选框项
|
|
666
667
668
669
670
671
672
673
674
675
|
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;
|
|
676
677
|
},
// 获取选中下拉框项
|
|
678
679
680
681
682
683
684
685
686
687
|
selectSelects: function (name) {
var selects = "";
$('#' + name + ' option:selected').each(function (i) {
if (0 == i) {
selects = $(this).val();
} else {
selects += ("," + $(this).val());
}
});
return selects;
|
|
688
689
690
|
}
},
// 弹出层封装处理
|
|
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
|
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});
|
|
710
711
712
713
714
|
} else {
layer.msg(content);
}
},
// 错误消息
|
|
715
716
|
msgError: function (content) {
$.modal.msg(content, modal_status.FAIL);
|
|
717
718
|
},
// 成功消息
|
|
719
720
|
msgSuccess: function (content) {
$.modal.msg(content, modal_status.SUCCESS);
|
|
721
722
|
},
// 警告消息
|
|
723
724
725
726
727
728
729
730
731
732
733
|
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'],
});
|
|
734
735
|
},
// 消息提示并刷新父窗体
|
|
736
737
738
739
740
741
742
743
744
|
msgReload: function (msg, type) {
layer.msg(msg, {
icon: $.modal.icon(type),
time: 500,
shade: [0.1, '#8F8F8F']
},
function () {
$.modal.reload();
});
|
|
745
746
|
},
// 错误提示
|
|
747
748
|
alertError: function (content) {
$.modal.alert(content, modal_status.FAIL);
|
|
749
750
|
},
// 成功提示
|
|
751
752
|
alertSuccess: function (content) {
$.modal.alert(content, modal_status.SUCCESS);
|
|
753
754
|
},
// 警告提示
|
|
755
756
|
alertWarning: function (content) {
$.modal.alert(content, modal_status.WARNING);
|
|
757
758
759
|
},
// 关闭窗体
close: function () {
|
|
760
|
var index = parent.layer.getFrameIndex(window.name);
|
|
761
762
763
|
parent.layer.close(index);
},
// 确认窗体
|
|
764
|
confirm: function (content, callback) {
|
|
765
766
767
768
769
770
771
|
layer.confirm(content, {
icon: 3,
title: "系统提示",
btn: ['确认', '取消'],
btnclass: ['btn btn-primary', 'btn btn-danger'],
}, function (index) {
layer.close(index);
|
|
772
|
callback(true);
|
|
773
|
});
|
|
774
775
|
},
// 弹出层指定宽度
|
|
776
|
open: function (title, url, width, height, callback) {
|
|
777
778
779
780
781
782
|
//如果是移动端,就使用自适应大小弹窗
if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
width = 'auto';
height = 'auto';
}
if ($.common.isEmpty(title)) {
|
|
783
|
title = false;
|
|
784
785
|
}
;
|
|
786
787
|
if ($.common.isEmpty(url)) {
url = "404.html";
|
|
788
789
|
}
;
|
|
790
|
if ($.common.isEmpty(width)) {
|
|
791
792
793
|
width = 800;
}
;
|
|
794
|
if ($.common.isEmpty(height)) {
|
|
795
796
797
|
height = ($(window).height() - 50);
}
;
|
|
798
|
if ($.common.isEmpty(callback)) {
|
|
799
|
callback = function (index, layero) {
|
|
800
801
802
803
|
var iframeWin = layero.find('iframe')[0];
iframeWin.contentWindow.submitHandler(index, layero);
}
}
|
|
804
805
806
807
808
809
810
811
812
|
layer.open({
type: 2,
area: [width + 'px', height + 'px'],
fix: false,
//不固定
maxmin: true,
shade: 0.3,
title: title,
content: url,
|
|
813
814
815
|
// 弹层外区域关闭
shadeClose: true,
yes: callback
|
|
816
|
});
|
|
817
|
},
|
|
818
819
820
821
822
823
824
825
|
// 弹出层指定参数选项
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)) {
|
|
826
|
options.yes = function (index, layero) {
|
|
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
|
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;
}
});
},
|
|
847
848
|
// 弹出层全屏
openFull: function (title, url, width, height) {
|
|
849
850
851
852
853
854
|
//如果是移动端,就使用自适应大小弹窗
if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
width = 'auto';
height = 'auto';
}
if ($.common.isEmpty(title)) {
|
|
855
|
title = false;
|
|
856
857
|
}
;
|
|
858
859
|
if ($.common.isEmpty(url)) {
url = "404.html";
|
|
860
861
|
}
;
|
|
862
|
if ($.common.isEmpty(width)) {
|
|
863
864
865
|
width = 800;
}
;
|
|
866
|
if ($.common.isEmpty(height)) {
|
|
867
868
869
|
height = ($(window).height() - 50);
}
;
|
|
870
|
var index = layer.open({
|
|
871
872
873
874
875
876
877
878
879
|
type: 2,
area: [width + 'px', height + 'px'],
fix: false,
//不固定
maxmin: true,
shade: 0.3,
title: title,
content: url
});
|
|
880
881
882
883
|
layer.full(index);
},
// 打开遮罩层
loading: function (message) {
|
|
884
|
$.blockUI({message: '<div class="loaderbox"><div class="loading-activity"></div> ' + message + '</div>'});
|
|
885
886
887
|
},
// 关闭遮罩层
closeLoading: function () {
|
|
888
889
890
|
setTimeout(function () {
$.unblockUI();
}, 50);
|
|
891
892
893
|
},
// 重新加载
reload: function () {
|
|
894
|
parent.location.reload();
|
|
895
896
|
},
// 禁用按钮
|
|
897
|
disable: function () {
|
|
898
899
900
901
|
var doc = window.top == window.parent ? window.document : window.parent.document;
$("a[class*=layui-layer-btn]", doc).addClass("layer-disabled");
},
// 启用按钮
|
|
902
|
enable: function () {
|
|
903
904
905
|
var doc = window.top == window.parent ? window.document : window.parent.document;
$("a[class*=layui-layer-btn]", doc).removeClass("layer-disabled");
},
|
|
906
907
908
909
910
911
912
913
914
915
916
917
918
919
|
// 选卡页方式打开
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);
},
|
|
920
921
922
|
},
// 操作封装处理
operate: {
|
|
923
924
925
926
927
928
929
930
|
// 提交数据
submit: function (url, type, dataType, data, callback) {
$.modal.loading("正在处理中,请稍后...");
var config = {
url: url,
type: type,
dataType: dataType,
data: data,
|
|
931
932
933
|
beforeSend: function () {
$.modal.loading("正在处理中,请稍后...");
},
|
|
934
|
success: function (result) {
|
|
935
936
937
938
939
|
if (typeof callback == "function") {
callback(result);
}
$.operate.ajaxSuccess(result);
}
|
|
940
941
|
};
$.ajax(config) // 将封装的数据放入ajax发送请求
|
|
942
943
|
},
// 提交数据,然后回调传入方法
|
|
944
|
submitAndCallback: function (url, type, dataType, data, callback) {
|
|
945
946
947
948
949
950
|
$.modal.loading("正在处理中,请稍后...");
var config = {
url: url,
type: type,
dataType: dataType,
data: data,
|
|
951
|
success: function (result) {
|
|
952
|
if (result.code == web_status.SUCCESS) {
|
|
953
|
$.modal.msgSuccess(result.msg);
|
|
954
955
|
callback();
} else {
|
|
956
|
$.modal.alertError(result.msg);
|
|
957
958
959
960
961
962
963
|
}
$.modal.closeLoading();
}
};
$.ajax(config)
},
// post请求传输
|
|
964
965
|
post: function (url, data) {
$.operate.submit(url, "post", "json", data);
|
|
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) {
|
|
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);
});
|
|
1014
1015
|
},
// 批量删除信息
|
|
1016
|
batRemove: function () {
|
|
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);
});
|
|
1028
|
},
|
|
1029
1030
1031
|
// 批量打印信息
batPrint: function () {
table.set(); // 将当前页的table传入这边保存table信息
|
|
1032
1033
|
var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() :
$.table.selectColumns(table.options.uniqueId); // 判断是否有选中的记录返回行或第一行
|
|
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
|
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;
});
|
|
1048
1049
|
window.open(url + "/" + param, '_blank',
'menubar=no,toolbar=no, status=no,scrollbars=yes'); // 弹出pdf打印预览页面
|
|
1050
1051
1052
1053
|
// $.windows.open() JQfunction
// 拼接参数data
});
},
|
|
1054
|
// 添加信息
|
|
1055
|
add: function (id) {
|
|
1056
|
table.set();
|
|
1057
|
var url = $.common.isEmpty(id) ? table.options.createUrl : table.options.createUrl.replace("{id}", id);
|
|
1058
|
$.modal.open("添加" + table.options.modalName, url);
|
|
1059
1060
|
},
// 修改信息
|
|
1061
|
edit: function (id) {
|
|
1062
|
table.set();
|
|
1063
1064
|
var url = table.options.updateUrl.replace("{id}", id);
$.modal.open("修改" + table.options.modalName, url);
|
|
1065
|
},
|
|
1066
|
// 修改信息,以tab页展现
|
|
1067
|
editTab: function (id) {
|
|
1068
1069
1070
1071
|
table.set();
$.modal.openTab("修改" + table.options.modalName, $.operate.editUrl(id));
},
// 修改访问地址
|
|
1072
|
editUrl: function (id) {
|
|
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
|
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;
},
|
|
1086
|
//查看
|
|
1087
|
checklook: function (id) {
|
|
1088
1089
1090
|
table.set();
var url = table.options.updateUrl.replace("{id}", id);
$.modal.open("查看" + table.options.modalName, url);
|
|
1091
1092
|
},
// 添加信息 全屏
|
|
1093
|
addFull: function (id) {
|
|
1094
|
table.set();
|
|
1095
|
var url = $.common.isEmpty(id) ? table.options.createUrl : $.table.options.createUrl.replace("{id}", id);
|
|
1096
|
$.modal.openFull("添加" + table.options.modalName, url);
|
|
1097
1098
|
},
// 修改信息 全屏
|
|
1099
|
editFull: function (id) {
|
|
1100
|
table.set();
|
|
1101
1102
|
var url = table.options.updateUrl.replace("{id}", id);
$.modal.openFull("修改" + table.options.modalName, url);
|
|
1103
1104
|
},
// 保存信息
|
|
1105
1106
1107
1108
1109
1110
1111
1112
|
save: function (url, data) {
$.modal.loading("正在处理中,请稍后...");
var config = {
url: url,
type: "post",
dataType: "json",
data: data,
success: function (result) {
|
|
1113
|
$.operate.saveSuccess(result);
|
|
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
|
}
};
$.ajax(config)
},
// 保存信息
saveV: function (url, data) {
$.modal.loading("正在处理中,请稍后...");
var config = {
url: url,
type: "post",
dataType: "json",
data: data,
success: function (result) {
// $.operate.successCallback(result);
if (result.code == web_status.SUCCESS) {
$.operate.saveSuccess(result);
$.modal.close();
} else {
$.modal.alertError(result.msg);
}
$.modal.closeLoading();
|
|
1135
1136
1137
|
}
};
$.ajax(config)
|
|
1138
|
},
|
|
1139
|
// 保存信息 弹出提示框
|
|
1140
|
saveModal: function (url, data, callback) {
|
|
1141
1142
1143
1144
1145
1146
1147
1148
|
var config = {
url: url,
type: "post",
dataType: "json",
data: data,
beforeSend: function () {
$.modal.loading("正在处理中,请稍后...");
},
|
|
1149
|
success: function (result) {
|
|
1150
1151
1152
1153
|
if (typeof callback == "function") {
callback(result);
}
if (result.code == web_status.SUCCESS) {
|
|
1154
|
$.modal.alertSuccess(result.msg)
|
|
1155
|
} else if (result.code == web_status.WARNING) {
|
|
1156
|
$.modal.alertWarning(result.msg)
|
|
1157
|
} else {
|
|
1158
|
$.modal.alertError(result.msg);
|
|
1159
1160
1161
1162
1163
1164
1165
|
}
$.modal.closeLoading();
}
};
$.ajax(config)
},
// 保存选项卡信息
|
|
1166
|
saveTab: function (url, data, callback) {
|
|
1167
1168
1169
1170
1171
1172
1173
1174
|
var config = {
url: url,
type: "post",
dataType: "json",
data: data,
beforeSend: function () {
$.modal.loading("正在处理中,请稍后...");
},
|
|
1175
|
success: function (result) {
|
|
1176
1177
1178
|
if (typeof callback == "function") {
callback(result);
}
|
|
1179
1180
|
$.operate.saveSuccess(result);
// $.operate.successTabCallback(result); // 未能正确关闭
|
|
1181
1182
1183
1184
|
}
};
$.ajax(config)
},
|
|
1185
1186
|
// 保存结果弹出msg刷新table表格
ajaxSuccess: function (result) {
|
|
1187
|
if (result.code == web_status.SUCCESS) {
|
|
1188
|
$.modal.msgSuccess(result.msg);
|
|
1189
|
$.table.refresh();
|
|
1190
|
} else {
|
|
1191
|
$.modal.alertError(result.msg);
|
|
1192
|
}
|
|
1193
|
$.modal.closeLoading();
|
|
1194
1195
1196
|
},
// 保存结果提示msg
saveSuccess: function (result) {
|
|
1197
|
if (result.code == web_status.SUCCESS) {
|
|
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
|
var parent = activeWindow();
if($.common.isEmpty(parent.table)) {
$.modal.msgSuccess(result.msg);
} else if (parent.table.options.type == table_type.bootstrapTable) {
$.modal.close();
parent.$.modal.msgSuccess(result.msg);
parent.$.table.refresh();
} else if (parent.table.options.type == table_type.bootstrapTreeTable) {
$.modal.close();
parent.$.modal.msgSuccess(result.msg);
parent.$.treeTable.refresh();
}
} else if (result.code == web_status.WARNING) {
$.modal.alertWarning(result.msg)
} else {
|
|
1213
|
$.modal.alertError(result.msg);
|
|
1214
|
}
|
|
1215
|
$.modal.closeLoading();
|
|
1216
|
$.modal.enable();
|
|
1217
|
},
|
|
1218
1219
1220
1221
1222
|
// 成功回调执行事件(父窗体静默更新)
successCallback: function (result) {
if (result.code == web_status.SUCCESS) {
var parent = activeWindow();
if($.common.isEmpty(parent.table)) {
|
|
1223
|
$.modal.saveSuccess(result.msg);
|
|
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
|
} else if (parent.table.options.type == table_type.bootstrapTable) {
$.modal.close();
parent.$.modal.msgSuccess(result.msg);
parent.$.table.refresh();
} else if (parent.table.options.type == table_type.bootstrapTreeTable) {
$.modal.close();
parent.$.modal.msgSuccess(result.msg);
parent.$.treeTable.refresh();
resetExpandFlag();
}
} else if (result.code == web_status.WARNING) {
$.modal.alertWarning(result.msg)
|
|
1236
|
console.log("4")
|
|
1237
1238
|
} else {
$.modal.alertError(result.msg);
|
|
1239
|
console.log("5")
|
|
1240
1241
1242
1243
|
}
$.modal.closeLoading();
$.modal.enable();
},
|
|
1244
|
// 选项卡成功回调执行事件(父窗体静默更新)
|
|
1245
|
successTabCallback: function (result) { // 只有创建tab才能正常关闭 提出框不能正常操作
|
|
1246
1247
1248
1249
1250
|
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();
|
|
1251
|
$contentWindow.$.modal.msgSuccess(result.msg);
|
|
1252
1253
1254
1255
1256
1257
1258
1259
|
$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) {
|
|
1260
|
$.modal.alertWarning(result.msg)
|
|
1261
|
} else {
|
|
1262
|
$.modal.alertError(result.msg);
|
|
1263
1264
|
}
$.modal.closeLoading();
|
|
1265
1266
|
}
},
|
|
1267
1268
1269
1270
1271
|
// 树插件封装处理
tree: {
_option: {},
_lastValue: {},
// 初始化树结构
|
|
1272
|
init: function (options) {
|
|
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
|
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
};
|
|
1306
|
$.get(options.url, function (data) {
|
|
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
|
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);
});
},
// 搜索节点
|
|
1321
|
searchNode: function () {
|
|
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
|
// 取得输入的关键字的值
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选中指定节点
|
|
1340
|
selectByIdName: function (treeId, node) {
|
|
1341
1342
1343
1344
1345
|
if ($.common.isNotEmpty(treeId) && treeId == node.id) {
$._tree.selectNode(node, true);
}
},
// 显示所有节点
|
|
1346
|
showAllNode: function (nodes) {
|
|
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
|
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);
}
},
// 隐藏所有节点
|
|
1359
|
hideAllNode: function (nodes) {
|
|
1360
1361
1362
1363
1364
1365
1366
|
var tree = $.fn.zTree.getZTreeObj("tree");
var nodes = $._tree.transformToArray(nodes);
for (var i = nodes.length - 1; i >= 0; i--) {
$._tree.hideNode(nodes[i]);
}
},
// 显示所有父节点
|
|
1367
|
showParent: function (treeNode) {
|
|
1368
1369
1370
1371
1372
1373
1374
1375
|
var parentNode;
while ((parentNode = treeNode.getParentNode()) != null) {
$._tree.showNode(parentNode);
$._tree.expandNode(parentNode, true, false, false);
treeNode = parentNode;
}
},
// 显示所有孩子节点
|
|
1376
|
showChildren: function (treeNode) {
|
|
1377
1378
1379
1380
1381
1382
1383
1384
1385
|
if (treeNode.isParent) {
for (var idx in treeNode.children) {
var node = treeNode.children[idx];
$._tree.showNode(node);
$.tree.showChildren(node);
}
}
},
// 更新节点状态
|
|
1386
|
updateNodes: function (nodeList) {
|
|
1387
1388
1389
1390
1391
1392
1393
1394
|
$._tree.showNodes(nodeList);
for (var i = 0, l = nodeList.length; i < l; i++) {
var treeNode = nodeList[i];
$.tree.showChildren(treeNode);
$.tree.showParent(treeNode)
}
},
// 获取当前被勾选集合
|
|
1395
|
getCheckedNodes: function (column) {
|
|
1396
1397
1398
1399
1400
1401
1402
|
var _column = $.common.isEmpty(column) ? "id" : column;
var nodes = $._tree.getCheckedNodes(true);
return $.map(nodes, function (row) {
return row[_column];
}).join();
},
// 不允许根父节点选择
|
|
1403
|
notAllowParents: function (_tree) {
|
|
1404
|
var nodes = _tree.getSelectedNodes();
|
|
1405
|
if (nodes.length == 0) {
|
|
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
|
$.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;
},
// 不允许最后层级节点选择
|
|
1422
|
notAllowLastLevel: function (_tree) {
|
|
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
|
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;
},
// 隐藏/显示搜索栏
|
|
1433
|
toggleSearch: function () {
|
|
1434
1435
1436
1437
1438
1439
|
$('#search').slideToggle(200);
$('#btnShow').toggle();
$('#btnHide').toggle();
$('#keyword').focus();
},
// 折叠
|
|
1440
|
collapse: function () {
|
|
1441
1442
1443
|
$._tree.expandAll(false);
},
// 展开
|
|
1444
|
expand: function () {
|
|
1445
1446
1447
|
$._tree.expandAll(true);
}
},
|
|
1448
|
// 通用方法封装处理
|
|
1449
|
common: {
|
|
1450
|
// 判断字符串是否是以start开头
|
|
1451
|
startWith: function (value, start) {
|
|
1452
1453
1454
1455
|
var reg = new RegExp("^" + start);
return reg.test(value)
},
// 判断字符串是否是以end结尾
|
|
1456
|
endWith: function (value, end) {
|
|
1457
1458
1459
|
var reg = new RegExp(end + "$");
return reg.test(value)
},
|
|
1460
|
// 判断字符串是否为空
|
|
1461
1462
1463
1464
1465
1466
|
isEmpty: function (value) {
if (value == null || this.trim(value) == "") {
return true;
}
return false;
},
|
|
1467
1468
1469
1470
|
// 判断一个字符串是否为非空串
isNotEmpty: function (value) {
return !$.common.isEmpty(value);
},
|
|
1471
|
// 空对象转字符串
|
|
1472
|
nullToStr: function (value) {
|
|
1473
1474
1475
1476
1477
|
if ($.common.isEmpty(value)) {
return "-";
}
return value;
},
|
|
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
|
// 是否显示数据 为空默认为显示
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, "");
},
|
|
1492
1493
1494
1495
1496
1497
1498
1499
|
// 比较两个字符串(大小写敏感)
equals: function (str, that) {
return str == that;
},
// 比较两个字符串(大小写不敏感)
equalsIgnoreCase: function (str, that) {
return String(str).toUpperCase() === String(that).toUpperCase();
},
|
|
1500
1501
1502
1503
|
// 指定随机数返回
random: function (min, max) {
return Math.floor((Math.random() * max) + min);
},
|
|
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
|
// 将字符串按指定字符分割
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 : '';
},
// 数组去重
|
|
1526
|
uniqueFn: function (array) {
|
|
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
|
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;
},
|
|
1537
1538
1539
1540
|
// 序列化表单
getTableValue: function (formName) {
var tableValue = $(formName).serialize();
//如果存在enable字段就从序列化中删除,然后
|
|
1541
|
if ($("input[name='enable']").length > 0) {
|
|
1542
|
var beginIndex = tableValue.indexOf("&enable");
|
|
1543
1544
1545
|
if (beginIndex > -1) {
var endIndex = tableValue.indexOf("&", beginIndex + 1);
if (endIndex > -1) {
|
|
1546
|
tableValue = tableValue.substring(0, beginIndex) + tableValue.substring(endIndex, tableValue.length);
|
|
1547
|
} else {
|
|
1548
1549
1550
1551
1552
1553
|
tableValue = tableValue.substring(0, beginIndex);
}
}
tableValue = tableValue + "&enable=" + $("input[name='enable']").is(':checked')
}
return tableValue;
|
|
1554
1555
|
},
// 获取form下所有的字段并转换为json对象
|
|
1556
|
formToJSON: function (formId) {
|
|
1557
|
var json = {};
|
|
1558
1559
|
$.each($("#" + formId).serializeArray(), function (i, field) {
if (json[field.name]) {
|
|
1560
1561
1562
1563
1564
1565
1566
1567
|
json[field.name] += ("," + field.value);
} else {
json[field.name] = field.value;
}
});
return json;
},
// 获取obj对象长度
|
|
1568
|
getLength: function (obj) {
|
|
1569
1570
1571
1572
1573
1574
1575
|
var count = 0;
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
count++;
}
}
return count;
|
|
1576
|
}
|
|
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
|
},
// 校验封装处理
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();
}
},
|
|
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
|
});
})(jQuery);
/** 消息状态码 */
web_status = {
SUCCESS: 200,
FAIL: 400
};
/** 弹窗状态码 */
modal_status = {
SUCCESS: "success",
FAIL: "error",
WARNING: "warning"
|
|
1612
1613
1614
1615
1616
1617
|
};
/** 表格类型 */
table_type = {
bootstrapTable: 0,
bootstrapTreeTable: 1
|
|
1618
|
};
|