cloud-web-corejs 1.0.54-dev.589 → 1.0.54-dev.590

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1101 @@
1
+ /**version-1.0*/
2
+ let modules = {};
3
+ import Sortable from "sortablejs";
4
+ import tableConfig from "./config.js";
5
+ import customConfig from "./customConfig.js";
6
+ import Vue from "vue";
7
+ import {extendDeeply} from "../../utils/index.js";
8
+ import corejsConfig from "@/corejsConfig";
9
+ import settingConfig from "@/settings.js";
10
+ import {getCellValue, createParams} from "./util/index";
11
+
12
+ let configUtil = {
13
+ Sortable,
14
+ extendDeeply,
15
+ tableConfig,
16
+ Vue,
17
+ };
18
+
19
+ function getGrid(that, tableRef) {
20
+ let $grid;
21
+ if (Array.isArray(that.$refs[tableRef])) {
22
+ $grid = that.$refs[tableRef][0];
23
+ } else {
24
+ $grid = that.$refs[tableRef];
25
+ }
26
+ return $grid;
27
+ }
28
+
29
+ async function initVxeTable(option) {
30
+ let tableName = option.tableName;
31
+ if (
32
+ !configUtil.tableConfig.disableTableName
33
+ && option.tableNameRequired !== false
34
+ && !tableName
35
+ && settingConfig.tableStorageDisabled !== true
36
+ ) {
37
+ return false;
38
+ }
39
+ let that = option.vue;
40
+ if (!that.$refs[option.tableRef]) {
41
+ await that.$nextTick();
42
+ }
43
+ let $grid = getGrid(that, option.tableRef);
44
+ if (!$grid) {
45
+ return false;
46
+ }
47
+ delete option.vue;
48
+
49
+ //操作列自动补全
50
+ handleCustomAlign(option);
51
+
52
+ initColumnIndex(option.columns);
53
+
54
+ $grid.originOption = that.$baseLodash.cloneDeep(option);
55
+ $grid.originOption.vue = that;
56
+ option.vue = that;
57
+
58
+ let isQueryAllPage = true;
59
+ if (option.isQueryAllPage !== null && option.isQueryAllPage !== undefined) {
60
+ isQueryAllPage = option.isQueryAllPage;
61
+ }
62
+
63
+ if (tableName) {
64
+ $grid.tableName = tableName;
65
+ if (option.path) {
66
+ await getTableData(that, option.tableRef, "isQueryAllPage", (res1) => {
67
+ let result = res1.objx ? res1.objx.data : null;
68
+ if (result !== null && result !== undefined) {
69
+ if (result === "false" || result === false) {
70
+ isQueryAllPage = false;
71
+ } else {
72
+ isQueryAllPage = true;
73
+ }
74
+ }
75
+ });
76
+ }
77
+ await getTableJson(tableName, that, (resultMsg) => {
78
+ let objx = resultMsg.objx;
79
+ if (objx !== null && objx !== undefined) {
80
+ let jsonStr = objx.data;
81
+ if (jsonStr) {
82
+ let json = JSON.parse(decodeURIComponent(jsonStr));
83
+ let columnData = json.columns ? json.columns : json;
84
+ if (columnData) {
85
+ option.columns = initColumn(option, columnData);
86
+ }
87
+ $grid.searchColumns = initSearchColumns(option, json.searchColumns);
88
+ initExportColumns($grid, json);
89
+ }
90
+ }
91
+ if (!$grid.searchColumns || !$grid.searchColumns.length) {
92
+ $grid.searchColumns = initSearchColumns(option);
93
+ }
94
+ });
95
+ } else {
96
+ $grid.searchColumns = initSearchColumns(option);
97
+ }
98
+
99
+ if(!!$grid?.$refs?.xTable){
100
+ $grid.$refs.xTable.getCellValue = getCellValue;
101
+ $grid.$refs.xTable.createParams = createParams;
102
+ }
103
+
104
+ $grid.getCellValue = getCellValue;
105
+ $grid.createParams = createParams;
106
+
107
+ option.isQueryAllPage = isQueryAllPage;
108
+ let nOption = initOption(option);
109
+
110
+ $grid.isQueryAllPage = isQueryAllPage;
111
+
112
+ if (tableName) {
113
+ nOption.tableName = tableName;
114
+ }
115
+
116
+ nOption.vue = that;
117
+ //绑定列位置拖拽
118
+ columnDrop(that, tableName, option.tableRef);
119
+
120
+ //自动绑定toobar
121
+ handleToolbar($grid, option);
122
+
123
+ return nOption;
124
+ }
125
+
126
+ //自动绑定toobar
127
+ function handleToolbar($grid, option) {
128
+ let selfConfig = getSelfConfig();
129
+ if (
130
+ option.bindToolbar
131
+ || (option.bindToolbar !== false && selfConfig.bindToolbar)
132
+ ) {
133
+ let loopDo = function (children) {
134
+ if (children && children.length) {
135
+ children.forEach((item) => {
136
+ if (item.$options.name === "VxeToolbar") {
137
+ $grid.connect(item);
138
+ } else {
139
+ loopDo(item.$children);
140
+ }
141
+ });
142
+ }
143
+ };
144
+ that.$nextTick(() => {
145
+ loopDo($grid.$children);
146
+ });
147
+ }
148
+ }
149
+
150
+ //操作列自动补全
151
+ function handleCustomAlign(option) {
152
+ let selfConfig = getSelfConfig();
153
+ // let customAlign = option.customAlign || selfConfig.customAlign || "right";
154
+ let customAlign
155
+ = selfConfig.customAlign === false
156
+ ? false
157
+ : selfConfig.customAlign || "right";
158
+ customAlign
159
+ = option.customAlign === false ? false : option.customAlign || customAlign;
160
+
161
+ let customColumnWidth
162
+ = option.customColumnWidth || selfConfig.customColumnWidth || 47;
163
+ let checkBoxColumnWidth
164
+ = option.checkBoxColumnWidth || selfConfig.checkBoxColumnWidth || 48;
165
+
166
+ let checkBoxRequired = selfConfig.checkBoxRequired !== false;
167
+ if (option.checkBoxRequired === false) {
168
+ checkBoxRequired = false;
169
+ }
170
+
171
+ let columnSize = option.columns.length;
172
+ if (columnSize > 0) {
173
+ if (checkBoxRequired) {
174
+ let firstColumn = option.columns[0];
175
+ if (firstColumn.type !== "checkbox") {
176
+ option.columns.splice(0, 0, {
177
+ type: "checkbox",
178
+ width: checkBoxColumnWidth,
179
+ resizable: false,
180
+ fixed: "left",
181
+ });
182
+ }
183
+ }
184
+ if (customAlign !== false) {
185
+ let lastColumn = option.columns[columnSize - 1];
186
+ if (customAlign === "left") {
187
+ if (!lastColumn.field && lastColumn.fixed === "right") {
188
+ option.columns.splice(columnSize - 1, 1);
189
+ lastColumn.fixed = "left";
190
+ option.columns.splice(1, 0, lastColumn);
191
+ } else if (columnSize > 1) {
192
+ if (option.columns[1].field) {
193
+ option.columns.splice(1, 0, {
194
+ width: customColumnWidth,
195
+ fixed: "left",
196
+ title: "",
197
+ sortable: false,
198
+ });
199
+ }
200
+ }
201
+ } else if (customAlign === "right") {
202
+ let column1 = option.columns[1];
203
+ if (!column1.field && column1.fixed === "left") {
204
+ option.columns.splice(1, 1);
205
+ column1.fixed = "right";
206
+ option.columns.push(column1);
207
+ } else if (lastColumn.field || lastColumn.fixed !== "right") {
208
+ option.columns.push({
209
+ width: customColumnWidth,
210
+ fixed: "right",
211
+ title: "",
212
+ sortable: false,
213
+ });
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+
220
+ //列位置拖拽
221
+ function columnDrop(t, tableName, tableRef) {
222
+ let that = t;
223
+ const $table = getGrid(that, tableRef);
224
+ if (!$table) {
225
+ return;
226
+ }
227
+ if ($table.sortable) {
228
+ $table.sortable.destroy();
229
+ }
230
+ $table.sortable = configUtil.Sortable.create(
231
+ $table.$el.querySelector(
232
+ ".body--wrapper>.vxe-table--header .vxe-header--row"
233
+ ),
234
+ {
235
+ handle: ".vxe-header--column:not(.col--fixed)",
236
+ onEnd: ({item, newIndex, oldIndex}) => {
237
+ const {fullColumn, tableColumn,collectColumn} = $table.getTableColumn();
238
+ const targetThElem = item;
239
+ const wrapperElem = targetThElem.parentNode;
240
+ const newColumn = tableColumn[newIndex];
241
+ if (newColumn.fixed) {
242
+ // 错误的移动
243
+ if (newIndex > oldIndex) {
244
+ wrapperElem.insertBefore(
245
+ targetThElem,
246
+ wrapperElem.children[oldIndex]
247
+ );
248
+ } else {
249
+ wrapperElem.insertBefore(
250
+ wrapperElem.children[oldIndex],
251
+ targetThElem
252
+ );
253
+ }
254
+ return;
255
+ /* return that.$XModal.message({
256
+ content: '固定列不允许拖动!',
257
+ status: 'error'
258
+ }) */
259
+ }
260
+ // 转换真实索引
261
+ const oldColumnIndex = $table.getColumnIndex(collectColumn[oldIndex]);
262
+ const newColumnIndex = $table.getColumnIndex(collectColumn[newIndex]);
263
+ // 移动到目标列
264
+ let oldIndexFinal = oldColumnIndex > newColumnIndex ? oldColumnIndex : newColumnIndex;
265
+ let newIndexFinal = oldColumnIndex > newColumnIndex ? newColumnIndex : oldColumnIndex;
266
+ const currRow = collectColumn.splice(oldIndexFinal, 1)[0];
267
+ collectColumn.splice(newIndexFinal, 0, currRow);
268
+ $table.loadColumn(collectColumn);
269
+ addTableJson(that, $table, tableName, collectColumn);
270
+ },
271
+ }
272
+ );
273
+ }
274
+
275
+ function getSelfConfig() {
276
+ let tableConfig = configUtil.tableConfig || {};
277
+ let selfConfig = tableConfig.selfConfig || {};
278
+ return selfConfig;
279
+ }
280
+
281
+ function initColumnDefaulAttrs(columns, opts) {
282
+ let tableConfig = configUtil.tableConfig || {};
283
+ let selfConfig = getSelfConfig();
284
+ let lockCheckboxWidth = opts.lockCheckboxWidth !== false ? (opts.lockCheckboxWidth || selfConfig.lockCheckboxWidth) : null;
285
+ let filterType = opts.filterType !== false && !opts.treeNodeUrl ? (opts.filterType || selfConfig.filterType || "filterContent") : null;
286
+ let sortAll = opts.sortAll === true || (opts.sortAll !== false && !opts.treeNodeUrl);
287
+
288
+ columns.forEach((column) => {
289
+ // 只有最底层的列(没有 children)才设置默认属性
290
+ if (!column.children || column.children.length === 0) {
291
+ // 设置 sortable
292
+ if (sortAll && column.title && (column.sortable === null || column.sortable === undefined)) {
293
+ column.sortable = true;
294
+ }
295
+
296
+ // 设置过滤器
297
+ if (filterType && column.title && column.field) {
298
+ if (
299
+ column.filterType === "filterContent"
300
+ || ((column.filterType === null || column.filterType === undefined) && filterType === "filterContent")
301
+ ) {
302
+ if (!column.filters) {
303
+ column.filters = [
304
+ {
305
+ data: {},
306
+ },
307
+ ];
308
+ }
309
+ if (!column.filterRender) {
310
+ column.filterRender = {
311
+ name: "FilterContent",
312
+ };
313
+ }
314
+ } else if (
315
+ column.filterType === "filterInput"
316
+ || ((column.filterType === null || column.filterType === undefined) && filterType === "filterInput")
317
+ ) {
318
+ if (!column.filters) {
319
+ column.filters = [
320
+ {
321
+ data: "",
322
+ },
323
+ ];
324
+ }
325
+ if (!column.filterRender) {
326
+ column.filterRender = {
327
+ name: "FilterInput",
328
+ };
329
+ }
330
+ }
331
+ }
332
+
333
+ // 设置复选框列宽度
334
+ if (lockCheckboxWidth && column.type === "checkbox") {
335
+ column.width = lockCheckboxWidth;
336
+ }
337
+ } else {
338
+ column.sortable = false;
339
+ column.filterType = false;
340
+ column.align = "center";
341
+ column.resizable = false;
342
+ // 递归处理 children
343
+ initColumnDefaulAttrs(column.children, opts);
344
+ }
345
+ });
346
+ }
347
+
348
+ function initOption(opts) {
349
+ let result = {};
350
+ let that = opts.vue;
351
+ let $grid = getGrid(that, opts.tableRef);
352
+
353
+ let path = opts.path || "";
354
+ // let columns = JSON.parse(JSON.stringify(opts.columns || []));
355
+ let columns = opts.columns || [];
356
+ let isQueryAllPage = opts.isQueryAllPage;
357
+ let pagerLayouts = getPagerConfigLayouts(opts);
358
+
359
+ let config = opts.config || {};
360
+
361
+ initColumnDefaulAttrs(columns, opts);
362
+
363
+ let defaultOptions = {
364
+ columnKey: true,
365
+ resizable: true,
366
+ showOverflow: true,
367
+ showHeaderOverflow: true,
368
+ showFooterOverflow: true,
369
+ highlightHoverRow: true,
370
+ border: "inner",
371
+ height: "auto",
372
+ // maxHeight:"1000px",
373
+ // rowId: 'id',
374
+ emptyText: " ",
375
+ sortConfig: {
376
+ trigger: "cell",
377
+ remote: false,
378
+ },
379
+ filterConfig: {
380
+ remote: false,
381
+ },
382
+ pagerConfig: {
383
+ autoHidden: true,
384
+ perfect: true,
385
+ pageSize: 200,
386
+ pageSizes: [50, 100, 200, 500],
387
+ layouts: pagerLayouts,
388
+ slots: {
389
+ left: (obj, b, c) => {
390
+ let $grid = obj.$grid;
391
+ let k = $grid.$data;
392
+ let tableDataInfo = $grid.getTableData();
393
+ let data = tableDataInfo.fullData;
394
+ let h = $grid.$createElement;
395
+
396
+ let proxyInfo = $grid.getProxyInfo();
397
+ let pager = proxyInfo ? proxyInfo.pager : null;
398
+
399
+ let celems = [
400
+ h("span", $grid.$t2("本页记录数", "components.table.currentNum")),
401
+ h(
402
+ "span",
403
+ {
404
+ attrs: {
405
+ class: "f-red",
406
+ },
407
+ },
408
+ " " + tableDataInfo.visibleData.length + " "
409
+ ),
410
+ ];
411
+ if (pager && $grid.isQueryAllPage) {
412
+ celems.push(
413
+ h(
414
+ "span",
415
+ "," + $grid.$t2("总记录数", "components.table.totalNum")
416
+ )
417
+ );
418
+ celems.push(
419
+ h(
420
+ "span",
421
+ {
422
+ attrs: {
423
+ class: "f-red",
424
+ },
425
+ },
426
+ " " + pager.total + " "
427
+ )
428
+ );
429
+ }
430
+ let elem = h("span", {}, celems);
431
+ return [elem];
432
+ },
433
+ },
434
+ },
435
+ exportConfig: {
436
+ // 默认选中类型
437
+ type: "xlsx",
438
+ // 局部自定义类型
439
+ types: ["xlsx", "csv", "html", "xml", "txt"],
440
+ // 自定义数据量列表
441
+ modes: ["current", "all"],
442
+ },
443
+ radioConfig: {
444
+ labelField: "id",
445
+ reserve: true,
446
+ highlight: true,
447
+ },
448
+ checkboxConfig: {
449
+ highlight: true,
450
+ },
451
+ customConfig: {
452
+ storage: false,
453
+ },
454
+ scrollX: {
455
+ // enabled: true,
456
+ gt: 10,
457
+ // oSize: 5
458
+ },
459
+ /*loadingConfig: {
460
+ icon: "vxe-loading--spinner",
461
+ text: ' '
462
+ },*/
463
+ columns: columns,
464
+ };
465
+ let tableDefaultConfig
466
+ = corejsConfig?.componentConfig?.table?.defaultConfig || {};
467
+ defaultOptions = configUtil.extendDeeply(defaultOptions, tableConfig);
468
+ defaultOptions = configUtil.extendDeeply(defaultOptions, customConfig);
469
+ defaultOptions = configUtil.extendDeeply(defaultOptions, tableDefaultConfig);
470
+
471
+ if (opts.path) {
472
+ // defaultOptions.filterInput = true;
473
+ defaultOptions.pagerConfig.autoHidden = false;
474
+ defaultOptions.proxyConfig = {
475
+ seq: true, // 启用动态序号代理
476
+ sort: true, // 启用排序代理
477
+ filter: true, // 启用筛选代理
478
+ props: {
479
+ result: "objx.records", // 配置响应结果列表字段
480
+ total: "objx.total", // 配置响应结果总页数字段
481
+ },
482
+ ajax: {
483
+ // 接收 Promise 对象
484
+ query: ({page, sorts, filters, form}) => {
485
+ if (!opts.path) {
486
+ return;
487
+ }
488
+ return new Promise((resolve, reject) => {
489
+ let toDo = () => {
490
+ let formData = opts.param ? opts.param() || {} : {};
491
+ const queryParams = Object.assign({}, formData);
492
+
493
+ // 处理排序条件
494
+ /*const firstSort = sorts[0];
495
+ if (firstSort) {
496
+ queryParams.sort = firstSort.property;
497
+ queryParams.order = firstSort.order;
498
+ }*/
499
+ // 处理筛选条件
500
+ filters.forEach(({property, values}) => {
501
+ queryParams[property] = values.join(",");
502
+ });
503
+ if (page.pageSize !== undefined) {
504
+ queryParams["size"] = page.pageSize;
505
+ queryParams["current"] = page.currentPage;
506
+ }
507
+
508
+ let $grid = getGrid(that, opts.tableRef);
509
+ let isQueryAllPage = $grid.isQueryAllPage;
510
+ let pathStr1 = "";
511
+ if (isQueryAllPage === false) {
512
+ queryParams.searchCount = false;
513
+ }
514
+
515
+ let reqPath = typeof path === "function" ? path() : path;
516
+ let addUserForTableEnabled
517
+ = settingConfig.addUserForTableDisabled !== true;
518
+ let addCreateInfo
519
+ = opts.addCreateInfo === true || addUserForTableEnabled;
520
+ let queryCreateInfo
521
+ = opts.queryCreateInfo === true || addUserForTableEnabled;
522
+ that.$commonHttp({
523
+ aes: opts.aes || false,
524
+ url: reqPath,
525
+ method: "post",
526
+ data: queryParams,
527
+ addCreateInfo: addCreateInfo,
528
+ queryCreateInfo: queryCreateInfo,
529
+ callback: (res) => {
530
+ resolve(res);
531
+ if (res.type === "success") {
532
+ let rows = res.objx
533
+ ? res.objx.records || res.objx || []
534
+ : [];
535
+ if (opts.treeNodeUrl) {
536
+ if (rows.length > 0) {
537
+ let $t = getGrid(that, opts.tableRef);
538
+ let treeConditions = $t.originOption.treeConditions || [
539
+ "enabled",
540
+ ];
541
+ let treeFiled = Object.keys(formData).some((key) => {
542
+ return (
543
+ !treeConditions.includes(key)
544
+ && formData[key] !== null && formData[key] !== undefined
545
+ && formData[key] !== ""
546
+ );
547
+ });
548
+ if (treeFiled) {
549
+ that.$nextTick(() => {
550
+ setTimeout(function () {
551
+ let isLazy = $t.treeConfig.lazy;
552
+ $t.treeConfig.lazy = false;
553
+ $t.setAllTreeExpand(true).then(() => {
554
+ let fullAllDataRowMap
555
+ = $t.$refs.xTable.fullAllDataRowMap;
556
+ let fullData = $t.getTableData().fullData;
557
+ fullData.forEach((lineData) => {
558
+ if (
559
+ $t.$refs.xTable.isTreeExpandByRow(lineData)
560
+ ) {
561
+ let rest = fullAllDataRowMap.get(lineData);
562
+ rest.treeLoaded = true;
563
+ }
564
+ });
565
+ $t.treeConfig.lazy = isLazy;
566
+ });
567
+ }, 0);
568
+ });
569
+ } else {
570
+ let row = rows[0];
571
+ if (row[result.treeConfig.hasChild]) {
572
+ that.$nextTick(() => {
573
+ setTimeout(function () {
574
+ $t.setTreeExpand(row, true);
575
+ }, 0);
576
+ });
577
+ }
578
+ }
579
+ }
580
+ }
581
+ if (opts.callback) {
582
+ that.$nextTick(() => {
583
+ setTimeout(function () {
584
+ opts.callback(rows, res);
585
+ }, 0);
586
+ });
587
+ }
588
+ }
589
+ },
590
+ error: (error) => {
591
+ reject(error);
592
+ },
593
+ });
594
+ };
595
+ let index = 0;
596
+ let loopHandle = () => {
597
+ if (index < 500 && $grid.tableFormStop === true) {
598
+ //阻塞列表查询,或者次数达到500时,自动释放
599
+ index++;
600
+ setTimeout(() => {
601
+ loopHandle();
602
+ }, 10);
603
+ } else {
604
+ if ($grid.tableFormStop) $grid.tableFormStop = false;
605
+ toDo();
606
+ }
607
+ };
608
+ loopHandle();
609
+ });
610
+ },
611
+ // 被某些特殊功能所触发,例如:导出数据 mode=all 时,会触发该方法并对返回的数据进行导出
612
+ queryAll: () => fetch(path || "").then((response) => response.json()),
613
+ },
614
+ };
615
+ /*defaultOptions.scrollX = {
616
+ enabled: true,
617
+ gt: 20
618
+ };*/
619
+ defaultOptions.scrollY = {
620
+ // enabled: false,
621
+ gt: 20,
622
+ oSize: 20,
623
+ };
624
+ } else {
625
+ if (!$grid.height && (!opts.config || !opts.config.height)) {
626
+ defaultOptions.maxHeight = "528px";
627
+ }
628
+ defaultOptions.scrollY = {
629
+ // enabled: false,
630
+ gt: 20,
631
+ oSize: 20,
632
+ };
633
+ }
634
+
635
+ if (opts.editSaveUrl) {
636
+ (defaultOptions.keepSource = true),
637
+ (defaultOptions.editConfig = {
638
+ trigger: "manual",
639
+ mode: "row",
640
+ showStatus: true,
641
+ autoClear: false,
642
+ });
643
+ }
644
+ if (opts.treeNodeUrl) {
645
+ defaultOptions.proxyConfig.props.result = "objx";
646
+ defaultOptions.pagerConfig.autoHidden = true;
647
+ defaultOptions.treeConfig = {
648
+ lazy: true,
649
+ children: "children",
650
+ hasChild: "hasChild", // 设置是否有子节点标识
651
+ parentField: "parent",
652
+ transform: true,
653
+ loadMethod({$table, row}) {
654
+ // 模拟后台接口
655
+ return new Promise((resolve, reject) => {
656
+ let treeNodeParam = opts.treeNodeParam
657
+ ? opts.treeNodeParam(row) || {}
658
+ : {
659
+ parent: row.id,
660
+ };
661
+ that.$http({
662
+ aes: opts.aes || false,
663
+ url: opts.treeNodeUrl,
664
+ method: "post",
665
+ data: treeNodeParam,
666
+ callback: (res) => {
667
+ if (res.type === "success") {
668
+ // let rows = res.objx || [];
669
+ let rows = res.objx ? res.objx.records || res.objx || [] : [];
670
+ let hasChildField = $grid.treeConfig.hasChild;
671
+ if (row[hasChildField] && !rows.length) {
672
+ row[hasChildField] = false;
673
+ }
674
+ resolve(rows);
675
+ if (opts.treeCallback) {
676
+ that.$nextTick(() => {
677
+ setTimeout(function () {
678
+ opts.treeCallback(rows, res);
679
+ }, 0);
680
+ });
681
+ }
682
+ } else {
683
+ reject(res);
684
+ }
685
+ },
686
+ });
687
+ });
688
+ },
689
+ };
690
+ }
691
+
692
+ result = configUtil.extendDeeply(defaultOptions, config);
693
+
694
+ let pageSize = result.pagerConfig.pageSize;
695
+ let pageSizes = result.pagerConfig.pageSizes;
696
+ if (pageSizes && !pageSizes.includes(pageSize)) {
697
+ for (let i = 0; i < pageSizes.length; i++) {
698
+ let item = pageSizes[i];
699
+ if (item > pageSize) {
700
+ pageSizes.splice(i, 0, pageSize);
701
+ break;
702
+ }
703
+ }
704
+ }
705
+
706
+ return result;
707
+ }
708
+
709
+ function getTableJson(tableName, that, success) {
710
+ if (
711
+ configUtil.tableConfig.disableTableName
712
+ || settingConfig.tableStorageDisabled
713
+ )
714
+ return false;
715
+ if (!tableName) return;
716
+ let url = USER_PREFIX + "/table_column/getTableJson";
717
+ let data = {
718
+ tableName: tableName,
719
+ };
720
+ let json = null;
721
+ return that.$http({
722
+ url: url,
723
+ method: "post",
724
+ data: data,
725
+ success: success,
726
+ });
727
+ }
728
+
729
+ function addTableExportJson() {
730
+ }
731
+
732
+ function addTableJson(that, $grid, tableName, columns, success) {
733
+ if (
734
+ configUtil.tableConfig.disableTableName
735
+ || settingConfig.tableStorageDisabled
736
+ )
737
+ return false;
738
+ if (!tableName) return;
739
+ if (!columns) {
740
+ columns = $grid.getTableColumn().collectColumn;
741
+ }
742
+ let saveColumn = [];
743
+ columns.forEach(function (item, index) {
744
+ let columnData = {
745
+ field: item.field || item.property,
746
+ title: item.title,
747
+ visible: item.visible,
748
+ width: item.renderWidth || item.width,
749
+ };
750
+
751
+ // 如果有 children,递归处理
752
+ if (item.children && item.children.length > 0) {
753
+ columnData.children = processChildren(item.children);
754
+ }
755
+
756
+ saveColumn.push(columnData);
757
+ });
758
+
759
+ // 处理 children 的递归函数
760
+ function processChildren(children) {
761
+ let result = [];
762
+ children.forEach(function (childItem) {
763
+ let childData = {
764
+ field: childItem.field || childItem.property,
765
+ title: childItem.title,
766
+ visible: childItem.visible,
767
+ width: childItem.renderWidth || childItem.width,
768
+ };
769
+
770
+ // 递归处理嵌套的 children
771
+ if (childItem.children && childItem.children.length > 0) {
772
+ childData.children = processChildren(childItem.children);
773
+ }
774
+
775
+ result.push(childData);
776
+ });
777
+ return result;
778
+ }
779
+
780
+ let searchColumns = $grid.searchColumns || [];
781
+ let jsonData = {
782
+ columns: saveColumn,
783
+ searchColumns: searchColumns,
784
+ };
785
+ if ($grid.exportColumns && $grid.exportColumns.length) {
786
+ jsonData.exportColumns = $grid.exportColumns;
787
+ }
788
+ if ($grid.exportItemColumns && $grid.exportItemColumns.length) {
789
+ jsonData.exportItemColumns = $grid.exportItemColumns;
790
+ }
791
+ console.log("jsonData", jsonData);
792
+ let json = encodeURIComponent(JSON.stringify(jsonData));
793
+
794
+ let url = USER_PREFIX + "/table_column/addTableJson";
795
+ let data = {
796
+ tableName: tableName,
797
+ // json: encodeURIComponent(JSON.stringify(saveColumn)),
798
+ json: json,
799
+ };
800
+ that.$http({
801
+ url: url,
802
+ method: "post",
803
+ data: data,
804
+ success: success,
805
+ });
806
+ }
807
+
808
+ function initColumnIndex(columns) {
809
+ columns.forEach(function (column, index) {
810
+ if(!column.params)column.params = {}
811
+ if (column.params) {
812
+ column.params._index = index;
813
+ }
814
+ if (column.children && column.children.length > 0) {
815
+ initColumnIndex(column.children);
816
+ }
817
+ });
818
+ }
819
+
820
+ function initColumn(option, syncColumns) {
821
+ let oldColumns = option.columns;
822
+ let newColumns = [];
823
+ if (syncColumns) {
824
+ let fields = [];
825
+ syncColumns.forEach(function (syncColumn) {
826
+ let field = syncColumn.field;
827
+ if (field) {
828
+ oldColumns.some(function (oldColumn,index) {
829
+ let flag = oldColumn.field === field;
830
+ if (flag) {
831
+ if(!oldColumn.params)oldColumn.params = {}
832
+ let visibleSync = option.visibleSync !== false && oldColumn.visibleSync !== false;
833
+ oldColumn.params._visible = oldColumn.visible ?? true;
834
+ if (visibleSync) {
835
+ oldColumn.visible = syncColumn.visible;
836
+ }
837
+ if(oldColumn.width !== undefined && oldColumn.width !== undefined){
838
+ oldColumn.params._width = oldColumn.width;
839
+ }
840
+ if (syncColumn.width) oldColumn.width = syncColumn.width;
841
+ newColumns.push(oldColumn);
842
+ fields.push(field);
843
+ }
844
+ return flag;
845
+ });
846
+ }
847
+ });
848
+ oldColumns.forEach(function (oldColumn, index) {
849
+ let field = oldColumn.field;
850
+ if (field) {
851
+ if (!fields.includes(field)) {
852
+ newColumns.splice(index, 0, oldColumn);
853
+ }
854
+ } else {
855
+ newColumns.splice(index, 0, oldColumn);
856
+ }
857
+ });
858
+
859
+ // 处理 children 中的列
860
+ if (syncColumns.length > 0) {
861
+ newColumns.forEach(function (newColumn) {
862
+ if (newColumn.children && newColumn.children.length > 0) {
863
+ // 在 syncColumns 中查找对应的父列
864
+ let syncParentColumn = syncColumns.find(function (syncCol) {
865
+ return syncCol.field === newColumn.field;
866
+ });
867
+ if (syncParentColumn && syncParentColumn.children && syncParentColumn.children.length > 0) {
868
+ // 递归处理 children
869
+ newColumn.children = initColumn({ columns: newColumn.children }, syncParentColumn.children);
870
+ }
871
+ }
872
+ });
873
+ }
874
+ } else {
875
+ newColumns = oldColumns;
876
+ }
877
+ return newColumns;
878
+ }
879
+
880
+ function initExportColumns($grid, json) {
881
+ if (json?.exportColumns?.length) {
882
+ $grid.exportColumns = json.exportColumns;
883
+ }
884
+ if (json?.exportItemColumns?.length) {
885
+ $grid.exportItemColumns = json.exportItemColumns;
886
+ }
887
+ }
888
+
889
+ function initSearchColumns(option, syncColumns) {
890
+ let oldColumns = option.searchColumns || [];
891
+ let newColumns = [];
892
+ if (syncColumns) {
893
+ let fields = [];
894
+ syncColumns.forEach(function (syncColumn) {
895
+ let field = syncColumn.field;
896
+ if (field) {
897
+ oldColumns.some(function (oldColumn) {
898
+ let flag = oldColumn.field === field && !oldColumn.fixed;
899
+ if (flag) {
900
+ oldColumn.common = syncColumn.common || false;
901
+ if (syncColumn.defaultValue !== undefined) {
902
+ oldColumn.defaultValue = syncColumn.defaultValue;
903
+ }
904
+ newColumns.push(oldColumn);
905
+ fields.push(field);
906
+ }
907
+ return flag;
908
+ });
909
+ }
910
+ });
911
+ oldColumns.forEach(function (oldColumn, index) {
912
+ let field = oldColumn.field;
913
+ if (field && !oldColumn.fixed) {
914
+ if (!fields.includes(field)) {
915
+ newColumns.splice(index, 0, oldColumn);
916
+ }
917
+ } else {
918
+ newColumns.splice(index, 0, oldColumn);
919
+ }
920
+ });
921
+ } else {
922
+ newColumns = oldColumns;
923
+ }
924
+ return newColumns.length ? newColumns : oldColumns;
925
+ }
926
+
927
+ function onColumnWitchChange(option) {
928
+ let that = option.$grid.$parent;
929
+ let $grid = option.$grid;
930
+ let originOption = $grid.originOption;
931
+ let tableName = originOption.tableName;
932
+ if (tableName) {
933
+ // let columns = $grid.columns;
934
+ const {fullColumn, tableColumn} = $grid.getTableColumn();
935
+ addTableJson(that, $grid, tableName);
936
+ }
937
+ }
938
+
939
+ function restoreColumnPosition(currentColumns) {
940
+ // 根据 params._index 排序 currentColumns
941
+ let sortedColumns = [...currentColumns].sort((a, b) => {
942
+ let indexA = a.params?._index ?? 0;
943
+ let indexB = b.params?._index ?? 0;
944
+ return indexA - indexB;
945
+ });
946
+ console.log("sortedColumns",sortedColumns);
947
+
948
+ // 递归处理 children
949
+ sortedColumns.forEach((column) => {
950
+ if (column.children && column.children.length > 0) {
951
+ column.children = restoreColumnPosition(column.children);
952
+ }else{
953
+ column.visible = column.params?._visible ?? true;
954
+ if(column.params?._width !== undefined){
955
+ column.width = column.params?._width
956
+ }else{
957
+ // delete column.width;
958
+ }
959
+ }
960
+ });
961
+
962
+ return sortedColumns;
963
+ }
964
+
965
+ function customHandle(option) {
966
+ let that = option.$grid.$parent;
967
+ let $grid = option.$grid;
968
+ let originOption = $grid.originOption;
969
+ if (option.type === "confirm" || option.type === "reset") {
970
+ let tableName = originOption.tableName;
971
+ if (option.type === "reset") {
972
+ const {collectColumn} = $grid.getTableColumn();
973
+ /* const loopDo = (columns)=>{
974
+ columns.forEach((item)=>{
975
+ if(item.children && item.children.length){
976
+ loopDo(item.children);
977
+ }else{
978
+ if(item.params){
979
+ item.visible = item.params._visible ?? true;
980
+ if(item.params._width !== undefined)item.width = item.params._width;
981
+ }
982
+ }
983
+ })
984
+ }
985
+ loopDo(collectColumn); */
986
+
987
+ // 还原列的位置
988
+ let oldColumns = originOption.columns || [];
989
+ if (oldColumns.length > 0) {
990
+ const restoredColumns = restoreColumnPosition(collectColumn);
991
+ console.log("restoredColumns",restoredColumns);
992
+ $grid.loadColumn(restoredColumns);
993
+ } else {
994
+ $grid.loadColumn(collectColumn);
995
+ }
996
+ // let columns = that.$baseLodash.cloneDeep(originOption.columns);
997
+ // initColumnDefaulAttrs(columns, originOption);
998
+ // $grid.columns = columns;
999
+ }
1000
+ if (tableName) {
1001
+ setTimeout(() => {
1002
+ addTableJson(that, $grid, tableName);
1003
+ }, 200);
1004
+ }
1005
+
1006
+ if (option && option.$event && option.$event.preventDefault) {
1007
+ option.$event.preventDefault(); // 取消事件的默认行为
1008
+ }
1009
+ }
1010
+ originOption.customCallback && originOption.customCallback(option);
1011
+ }
1012
+
1013
+ function changeSelectCount(checked) {
1014
+ let checkedLength = checked.records.length;
1015
+ }
1016
+
1017
+ function getTableData(that, tableRef, type, success) {
1018
+ if (
1019
+ configUtil.tableConfig.disableTableName
1020
+ || settingConfig.tableStorageDisabled
1021
+ )
1022
+ return false;
1023
+ let $grid = getGrid(that, tableRef);
1024
+ let tableName = $grid.tableName;
1025
+ let url = USER_PREFIX + "/table_column/getTableData";
1026
+ let param = {
1027
+ tableName: tableName,
1028
+ type: type,
1029
+ };
1030
+ let data = null;
1031
+ return that.$http({
1032
+ async: false,
1033
+ url: url,
1034
+ method: "post",
1035
+ data: param,
1036
+ success: success,
1037
+ });
1038
+ }
1039
+
1040
+ function addTableData(that, tableRef, value, success) {
1041
+ if (
1042
+ configUtil.tableConfig.disableTableName
1043
+ || settingConfig.tableStorageDisabled
1044
+ )
1045
+ return false;
1046
+ let $grid = getGrid(that, tableRef);
1047
+ let tableName = $grid.tableName;
1048
+ if (tableName) {
1049
+ that.$http({
1050
+ method: "post",
1051
+ url: USER_PREFIX + "/table_column/addTableData",
1052
+ data: {
1053
+ tableName: tableName,
1054
+ type: "isQueryAllPage",
1055
+ data: value,
1056
+ success: success,
1057
+ },
1058
+ });
1059
+ }
1060
+ }
1061
+
1062
+ function checkQueryTotal(that, tableRef, value) {
1063
+ let $grid = getGrid(that, tableRef);
1064
+ $grid.isQueryAllPage = value;
1065
+ let tableName = $grid.tableName;
1066
+ let option = $grid.getProxyInfo();
1067
+ let pagerConfig = $grid.pagerConfig;
1068
+
1069
+ $grid.pagerConfig.layouts = pagerConfig.layouts || [];
1070
+ addTableData(that, tableRef, value);
1071
+ $grid.commitProxy("query");
1072
+ }
1073
+
1074
+ function getPagerConfigLayouts(opts) {
1075
+ if (opts.showPageSizes !== false) {
1076
+ return ["Sizes", "PrevPage", "JumpNumber", "NextPage"];
1077
+ } else {
1078
+ return ["PrevPage", "JumpNumber", "NextPage"];
1079
+ }
1080
+ }
1081
+
1082
+ modules = {
1083
+ initVxeTable,
1084
+ columnDrop,
1085
+ initOption,
1086
+ getTableJson,
1087
+ addTableJson,
1088
+ onColumnWitchChange,
1089
+ customHandle,
1090
+ changeSelectCount,
1091
+ getTableData,
1092
+ addTableData,
1093
+ checkQueryTotal,
1094
+ getCellValue,
1095
+ createParams,
1096
+ };
1097
+
1098
+ if (!configUtil.Vue.prototype.$vxeTableUtil)
1099
+ configUtil.Vue.prototype.$vxeTableUtil = modules;
1100
+
1101
+ export default modules;