cloud-web-corejs 1.0.54-dev.627 → 1.0.54-dev.628

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.
@@ -1,1103 +0,0 @@
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;
265
- let newIndexFinal = newColumnIndex;
266
- // let oldIndexFinal = oldColumnIndex > newColumnIndex ? oldColumnIndex : newColumnIndex;
267
- // let newIndexFinal = oldColumnIndex > newColumnIndex ? newColumnIndex : oldColumnIndex;
268
- const currRow = collectColumn.splice(oldIndexFinal, 1)[0];
269
- collectColumn.splice(newIndexFinal, 0, currRow);
270
- $table.loadColumn(collectColumn);
271
- addTableJson(that, $table, tableName, collectColumn);
272
- },
273
- }
274
- );
275
- }
276
-
277
- function getSelfConfig() {
278
- let tableConfig = configUtil.tableConfig || {};
279
- let selfConfig = tableConfig.selfConfig || {};
280
- return selfConfig;
281
- }
282
-
283
- function initColumnDefaulAttrs(columns, opts) {
284
- let tableConfig = configUtil.tableConfig || {};
285
- let selfConfig = getSelfConfig();
286
- let lockCheckboxWidth = opts.lockCheckboxWidth !== false ? (opts.lockCheckboxWidth || selfConfig.lockCheckboxWidth) : null;
287
- let filterType = opts.filterType !== false && !opts.treeNodeUrl ? (opts.filterType || selfConfig.filterType || "filterContent") : null;
288
- let sortAll = opts.sortAll === true || (opts.sortAll !== false && !opts.treeNodeUrl);
289
-
290
- columns.forEach((column) => {
291
- // 只有最底层的列(没有 children)才设置默认属性
292
- if (!column.children || column.children.length === 0) {
293
- // 设置 sortable
294
- if (sortAll && column.title && (column.sortable === null || column.sortable === undefined)) {
295
- column.sortable = true;
296
- }
297
-
298
- // 设置过滤器
299
- if (filterType && column.title && column.field) {
300
- if (
301
- column.filterType === "filterContent"
302
- || ((column.filterType === null || column.filterType === undefined) && filterType === "filterContent")
303
- ) {
304
- if (!column.filters) {
305
- column.filters = [
306
- {
307
- data: {},
308
- },
309
- ];
310
- }
311
- if (!column.filterRender) {
312
- column.filterRender = {
313
- name: "FilterContent",
314
- };
315
- }
316
- } else if (
317
- column.filterType === "filterInput"
318
- || ((column.filterType === null || column.filterType === undefined) && filterType === "filterInput")
319
- ) {
320
- if (!column.filters) {
321
- column.filters = [
322
- {
323
- data: "",
324
- },
325
- ];
326
- }
327
- if (!column.filterRender) {
328
- column.filterRender = {
329
- name: "FilterInput",
330
- };
331
- }
332
- }
333
- }
334
-
335
- // 设置复选框列宽度
336
- if (lockCheckboxWidth && column.type === "checkbox") {
337
- column.width = lockCheckboxWidth;
338
- }
339
- } else {
340
- column.sortable = false;
341
- column.filterType = false;
342
- column.align = "center";
343
- column.resizable = false;
344
- // 递归处理 children
345
- initColumnDefaulAttrs(column.children, opts);
346
- }
347
- });
348
- }
349
-
350
- function initOption(opts) {
351
- let result = {};
352
- let that = opts.vue;
353
- let $grid = getGrid(that, opts.tableRef);
354
-
355
- let path = opts.path || "";
356
- // let columns = JSON.parse(JSON.stringify(opts.columns || []));
357
- let columns = opts.columns || [];
358
- let isQueryAllPage = opts.isQueryAllPage;
359
- let pagerLayouts = getPagerConfigLayouts(opts);
360
-
361
- let config = opts.config || {};
362
-
363
- initColumnDefaulAttrs(columns, opts);
364
-
365
- let defaultOptions = {
366
- columnKey: true,
367
- resizable: true,
368
- showOverflow: true,
369
- showHeaderOverflow: true,
370
- showFooterOverflow: true,
371
- highlightHoverRow: true,
372
- border: "inner",
373
- height: "auto",
374
- // maxHeight:"1000px",
375
- // rowId: 'id',
376
- emptyText: " ",
377
- sortConfig: {
378
- trigger: "cell",
379
- remote: false,
380
- },
381
- filterConfig: {
382
- remote: false,
383
- },
384
- pagerConfig: {
385
- autoHidden: true,
386
- perfect: true,
387
- pageSize: 200,
388
- pageSizes: [50, 100, 200, 500],
389
- layouts: pagerLayouts,
390
- slots: {
391
- left: (obj, b, c) => {
392
- let $grid = obj.$grid;
393
- let k = $grid.$data;
394
- let tableDataInfo = $grid.getTableData();
395
- let data = tableDataInfo.fullData;
396
- let h = $grid.$createElement;
397
-
398
- let proxyInfo = $grid.getProxyInfo();
399
- let pager = proxyInfo ? proxyInfo.pager : null;
400
-
401
- let celems = [
402
- h("span", $grid.$t2("本页记录数", "components.table.currentNum")),
403
- h(
404
- "span",
405
- {
406
- attrs: {
407
- class: "f-red",
408
- },
409
- },
410
- " " + tableDataInfo.visibleData.length + " "
411
- ),
412
- ];
413
- if (pager && $grid.isQueryAllPage) {
414
- celems.push(
415
- h(
416
- "span",
417
- "," + $grid.$t2("总记录数", "components.table.totalNum")
418
- )
419
- );
420
- celems.push(
421
- h(
422
- "span",
423
- {
424
- attrs: {
425
- class: "f-red",
426
- },
427
- },
428
- " " + pager.total + " "
429
- )
430
- );
431
- }
432
- let elem = h("span", {}, celems);
433
- return [elem];
434
- },
435
- },
436
- },
437
- exportConfig: {
438
- // 默认选中类型
439
- type: "xlsx",
440
- // 局部自定义类型
441
- types: ["xlsx", "csv", "html", "xml", "txt"],
442
- // 自定义数据量列表
443
- modes: ["current", "all"],
444
- },
445
- radioConfig: {
446
- labelField: "id",
447
- reserve: true,
448
- highlight: true,
449
- },
450
- checkboxConfig: {
451
- highlight: true,
452
- },
453
- customConfig: {
454
- storage: false,
455
- },
456
- scrollX: {
457
- // enabled: true,
458
- gt: 10,
459
- // oSize: 5
460
- },
461
- /*loadingConfig: {
462
- icon: "vxe-loading--spinner",
463
- text: ' '
464
- },*/
465
- columns: columns,
466
- };
467
- let tableDefaultConfig
468
- = corejsConfig?.componentConfig?.table?.defaultConfig || {};
469
- defaultOptions = configUtil.extendDeeply(defaultOptions, tableConfig);
470
- defaultOptions = configUtil.extendDeeply(defaultOptions, customConfig);
471
- defaultOptions = configUtil.extendDeeply(defaultOptions, tableDefaultConfig);
472
-
473
- if (opts.path) {
474
- // defaultOptions.filterInput = true;
475
- defaultOptions.pagerConfig.autoHidden = false;
476
- defaultOptions.proxyConfig = {
477
- seq: true, // 启用动态序号代理
478
- sort: true, // 启用排序代理
479
- filter: true, // 启用筛选代理
480
- props: {
481
- result: "objx.records", // 配置响应结果列表字段
482
- total: "objx.total", // 配置响应结果总页数字段
483
- },
484
- ajax: {
485
- // 接收 Promise 对象
486
- query: ({page, sorts, filters, form}) => {
487
- if (!opts.path) {
488
- return;
489
- }
490
- return new Promise((resolve, reject) => {
491
- let toDo = () => {
492
- let formData = opts.param ? opts.param() || {} : {};
493
- const queryParams = Object.assign({}, formData);
494
-
495
- // 处理排序条件
496
- /*const firstSort = sorts[0];
497
- if (firstSort) {
498
- queryParams.sort = firstSort.property;
499
- queryParams.order = firstSort.order;
500
- }*/
501
- // 处理筛选条件
502
- filters.forEach(({property, values}) => {
503
- queryParams[property] = values.join(",");
504
- });
505
- if (page.pageSize !== undefined) {
506
- queryParams["size"] = page.pageSize;
507
- queryParams["current"] = page.currentPage;
508
- }
509
-
510
- let $grid = getGrid(that, opts.tableRef);
511
- let isQueryAllPage = $grid.isQueryAllPage;
512
- let pathStr1 = "";
513
- if (isQueryAllPage === false) {
514
- queryParams.searchCount = false;
515
- }
516
-
517
- let reqPath = typeof path === "function" ? path() : path;
518
- let addUserForTableEnabled
519
- = settingConfig.addUserForTableDisabled !== true;
520
- let addCreateInfo
521
- = opts.addCreateInfo === true || addUserForTableEnabled;
522
- let queryCreateInfo
523
- = opts.queryCreateInfo === true || addUserForTableEnabled;
524
- that.$commonHttp({
525
- aes: opts.aes || false,
526
- url: reqPath,
527
- method: "post",
528
- data: queryParams,
529
- addCreateInfo: addCreateInfo,
530
- queryCreateInfo: queryCreateInfo,
531
- callback: (res) => {
532
- resolve(res);
533
- if (res.type === "success") {
534
- let rows = res.objx
535
- ? res.objx.records || res.objx || []
536
- : [];
537
- if (opts.treeNodeUrl) {
538
- if (rows.length > 0) {
539
- let $t = getGrid(that, opts.tableRef);
540
- let treeConditions = $t.originOption.treeConditions || [
541
- "enabled",
542
- ];
543
- let treeFiled = Object.keys(formData).some((key) => {
544
- return (
545
- !treeConditions.includes(key)
546
- && formData[key] !== null && formData[key] !== undefined
547
- && formData[key] !== ""
548
- );
549
- });
550
- if (treeFiled) {
551
- that.$nextTick(() => {
552
- setTimeout(function () {
553
- let isLazy = $t.treeConfig.lazy;
554
- $t.treeConfig.lazy = false;
555
- $t.setAllTreeExpand(true).then(() => {
556
- let fullAllDataRowMap
557
- = $t.$refs.xTable.fullAllDataRowMap;
558
- let fullData = $t.getTableData().fullData;
559
- fullData.forEach((lineData) => {
560
- if (
561
- $t.$refs.xTable.isTreeExpandByRow(lineData)
562
- ) {
563
- let rest = fullAllDataRowMap.get(lineData);
564
- rest.treeLoaded = true;
565
- }
566
- });
567
- $t.treeConfig.lazy = isLazy;
568
- });
569
- }, 0);
570
- });
571
- } else {
572
- let row = rows[0];
573
- if (row[result.treeConfig.hasChild]) {
574
- that.$nextTick(() => {
575
- setTimeout(function () {
576
- $t.setTreeExpand(row, true);
577
- }, 0);
578
- });
579
- }
580
- }
581
- }
582
- }
583
- if (opts.callback) {
584
- that.$nextTick(() => {
585
- setTimeout(function () {
586
- opts.callback(rows, res);
587
- }, 0);
588
- });
589
- }
590
- }
591
- },
592
- error: (error) => {
593
- reject(error);
594
- },
595
- });
596
- };
597
- let index = 0;
598
- let loopHandle = () => {
599
- if (index < 500 && $grid.tableFormStop === true) {
600
- //阻塞列表查询,或者次数达到500时,自动释放
601
- index++;
602
- setTimeout(() => {
603
- loopHandle();
604
- }, 10);
605
- } else {
606
- if ($grid.tableFormStop) $grid.tableFormStop = false;
607
- toDo();
608
- }
609
- };
610
- loopHandle();
611
- });
612
- },
613
- // 被某些特殊功能所触发,例如:导出数据 mode=all 时,会触发该方法并对返回的数据进行导出
614
- queryAll: () => fetch(path || "").then((response) => response.json()),
615
- },
616
- };
617
- /*defaultOptions.scrollX = {
618
- enabled: true,
619
- gt: 20
620
- };*/
621
- defaultOptions.scrollY = {
622
- // enabled: false,
623
- gt: 20,
624
- oSize: 20,
625
- };
626
- } else {
627
- if (!$grid.height && (!opts.config || !opts.config.height)) {
628
- defaultOptions.maxHeight = "528px";
629
- }
630
- defaultOptions.scrollY = {
631
- // enabled: false,
632
- gt: 20,
633
- oSize: 20,
634
- };
635
- }
636
-
637
- if (opts.editSaveUrl) {
638
- (defaultOptions.keepSource = true),
639
- (defaultOptions.editConfig = {
640
- trigger: "manual",
641
- mode: "row",
642
- showStatus: true,
643
- autoClear: false,
644
- });
645
- }
646
- if (opts.treeNodeUrl) {
647
- defaultOptions.proxyConfig.props.result = "objx";
648
- defaultOptions.pagerConfig.autoHidden = true;
649
- defaultOptions.treeConfig = {
650
- lazy: true,
651
- children: "children",
652
- hasChild: "hasChild", // 设置是否有子节点标识
653
- parentField: "parent",
654
- transform: true,
655
- loadMethod({$table, row}) {
656
- // 模拟后台接口
657
- return new Promise((resolve, reject) => {
658
- let treeNodeParam = opts.treeNodeParam
659
- ? opts.treeNodeParam(row) || {}
660
- : {
661
- parent: row.id,
662
- };
663
- that.$http({
664
- aes: opts.aes || false,
665
- url: opts.treeNodeUrl,
666
- method: "post",
667
- data: treeNodeParam,
668
- callback: (res) => {
669
- if (res.type === "success") {
670
- // let rows = res.objx || [];
671
- let rows = res.objx ? res.objx.records || res.objx || [] : [];
672
- let hasChildField = $grid.treeConfig.hasChild;
673
- if (row[hasChildField] && !rows.length) {
674
- row[hasChildField] = false;
675
- }
676
- resolve(rows);
677
- if (opts.treeCallback) {
678
- that.$nextTick(() => {
679
- setTimeout(function () {
680
- opts.treeCallback(rows, res);
681
- }, 0);
682
- });
683
- }
684
- } else {
685
- reject(res);
686
- }
687
- },
688
- });
689
- });
690
- },
691
- };
692
- }
693
-
694
- result = configUtil.extendDeeply(defaultOptions, config);
695
-
696
- let pageSize = result.pagerConfig.pageSize;
697
- let pageSizes = result.pagerConfig.pageSizes;
698
- if (pageSizes && !pageSizes.includes(pageSize)) {
699
- for (let i = 0; i < pageSizes.length; i++) {
700
- let item = pageSizes[i];
701
- if (item > pageSize) {
702
- pageSizes.splice(i, 0, pageSize);
703
- break;
704
- }
705
- }
706
- }
707
-
708
- return result;
709
- }
710
-
711
- function getTableJson(tableName, that, success) {
712
- if (
713
- configUtil.tableConfig.disableTableName
714
- || settingConfig.tableStorageDisabled
715
- )
716
- return false;
717
- if (!tableName) return;
718
- let url = USER_PREFIX + "/table_column/getTableJson";
719
- let data = {
720
- tableName: tableName,
721
- };
722
- let json = null;
723
- return that.$http({
724
- url: url,
725
- method: "post",
726
- data: data,
727
- success: success,
728
- });
729
- }
730
-
731
- function addTableExportJson() {
732
- }
733
-
734
- function addTableJson(that, $grid, tableName, columns, success) {
735
- if (
736
- configUtil.tableConfig.disableTableName
737
- || settingConfig.tableStorageDisabled
738
- )
739
- return false;
740
- if (!tableName) return;
741
- if (!columns) {
742
- columns = $grid.getTableColumn().collectColumn;
743
- }
744
- let saveColumn = [];
745
- columns.forEach(function (item, index) {
746
- let columnData = {
747
- field: item.field || item.property,
748
- title: item.title,
749
- visible: item.visible,
750
- width: item.renderWidth || item.width,
751
- };
752
-
753
- // 如果有 children,递归处理
754
- if (item.children && item.children.length > 0) {
755
- columnData.children = processChildren(item.children);
756
- }
757
-
758
- saveColumn.push(columnData);
759
- });
760
-
761
- // 处理 children 的递归函数
762
- function processChildren(children) {
763
- let result = [];
764
- children.forEach(function (childItem) {
765
- let childData = {
766
- field: childItem.field || childItem.property,
767
- title: childItem.title,
768
- visible: childItem.visible,
769
- width: childItem.renderWidth || childItem.width,
770
- };
771
-
772
- // 递归处理嵌套的 children
773
- if (childItem.children && childItem.children.length > 0) {
774
- childData.children = processChildren(childItem.children);
775
- }
776
-
777
- result.push(childData);
778
- });
779
- return result;
780
- }
781
-
782
- let searchColumns = $grid.searchColumns || [];
783
- let jsonData = {
784
- columns: saveColumn,
785
- searchColumns: searchColumns,
786
- };
787
- if ($grid.exportColumns && $grid.exportColumns.length) {
788
- jsonData.exportColumns = $grid.exportColumns;
789
- }
790
- if ($grid.exportItemColumns && $grid.exportItemColumns.length) {
791
- jsonData.exportItemColumns = $grid.exportItemColumns;
792
- }
793
- console.log("jsonData", jsonData);
794
- let json = encodeURIComponent(JSON.stringify(jsonData));
795
-
796
- let url = USER_PREFIX + "/table_column/addTableJson";
797
- let data = {
798
- tableName: tableName,
799
- // json: encodeURIComponent(JSON.stringify(saveColumn)),
800
- json: json,
801
- };
802
- that.$http({
803
- url: url,
804
- method: "post",
805
- data: data,
806
- success: success,
807
- });
808
- }
809
-
810
- function initColumnIndex(columns) {
811
- columns.forEach(function (column, index) {
812
- if(!column.params)column.params = {}
813
- if (column.params) {
814
- column.params._index = index;
815
- }
816
- if (column.children && column.children.length > 0) {
817
- initColumnIndex(column.children);
818
- }
819
- });
820
- }
821
-
822
- function initColumn(option, syncColumns) {
823
- let oldColumns = option.columns;
824
- let newColumns = [];
825
- if (syncColumns) {
826
- let fields = [];
827
- syncColumns.forEach(function (syncColumn) {
828
- let field = syncColumn.field;
829
- if (field) {
830
- oldColumns.some(function (oldColumn,index) {
831
- let flag = oldColumn.field === field;
832
- if (flag) {
833
- if(!oldColumn.params)oldColumn.params = {}
834
- let visibleSync = option.visibleSync !== false && oldColumn.visibleSync !== false;
835
- oldColumn.params._visible = oldColumn.visible ?? true;
836
- if (visibleSync) {
837
- oldColumn.visible = syncColumn.visible;
838
- }
839
- if(oldColumn.width !== undefined && oldColumn.width !== undefined){
840
- oldColumn.params._width = oldColumn.width;
841
- }
842
- if (syncColumn.width) oldColumn.width = syncColumn.width;
843
- newColumns.push(oldColumn);
844
- fields.push(field);
845
- }
846
- return flag;
847
- });
848
- }
849
- });
850
- oldColumns.forEach(function (oldColumn, index) {
851
- let field = oldColumn.field;
852
- if (field) {
853
- if (!fields.includes(field)) {
854
- newColumns.splice(index, 0, oldColumn);
855
- }
856
- } else {
857
- newColumns.splice(index, 0, oldColumn);
858
- }
859
- });
860
-
861
- // 处理 children 中的列
862
- if (syncColumns.length > 0) {
863
- newColumns.forEach(function (newColumn) {
864
- if (newColumn.children && newColumn.children.length > 0) {
865
- // 在 syncColumns 中查找对应的父列
866
- let syncParentColumn = syncColumns.find(function (syncCol) {
867
- return syncCol.field === newColumn.field;
868
- });
869
- if (syncParentColumn && syncParentColumn.children && syncParentColumn.children.length > 0) {
870
- // 递归处理 children
871
- newColumn.children = initColumn({ columns: newColumn.children }, syncParentColumn.children);
872
- }
873
- }
874
- });
875
- }
876
- } else {
877
- newColumns = oldColumns;
878
- }
879
- return newColumns;
880
- }
881
-
882
- function initExportColumns($grid, json) {
883
- if (json?.exportColumns?.length) {
884
- $grid.exportColumns = json.exportColumns;
885
- }
886
- if (json?.exportItemColumns?.length) {
887
- $grid.exportItemColumns = json.exportItemColumns;
888
- }
889
- }
890
-
891
- function initSearchColumns(option, syncColumns) {
892
- let oldColumns = option.searchColumns || [];
893
- let newColumns = [];
894
- if (syncColumns) {
895
- let fields = [];
896
- syncColumns.forEach(function (syncColumn) {
897
- let field = syncColumn.field;
898
- if (field) {
899
- oldColumns.some(function (oldColumn) {
900
- let flag = oldColumn.field === field && !oldColumn.fixed;
901
- if (flag) {
902
- oldColumn.common = syncColumn.common || false;
903
- if (syncColumn.defaultValue !== undefined) {
904
- oldColumn.defaultValue = syncColumn.defaultValue;
905
- }
906
- newColumns.push(oldColumn);
907
- fields.push(field);
908
- }
909
- return flag;
910
- });
911
- }
912
- });
913
- oldColumns.forEach(function (oldColumn, index) {
914
- let field = oldColumn.field;
915
- if (field && !oldColumn.fixed) {
916
- if (!fields.includes(field)) {
917
- newColumns.splice(index, 0, oldColumn);
918
- }
919
- } else {
920
- newColumns.splice(index, 0, oldColumn);
921
- }
922
- });
923
- } else {
924
- newColumns = oldColumns;
925
- }
926
- return newColumns.length ? newColumns : oldColumns;
927
- }
928
-
929
- function onColumnWitchChange(option) {
930
- let that = option.$grid.$parent;
931
- let $grid = option.$grid;
932
- let originOption = $grid.originOption;
933
- let tableName = originOption.tableName;
934
- if (tableName) {
935
- // let columns = $grid.columns;
936
- const {fullColumn, tableColumn} = $grid.getTableColumn();
937
- addTableJson(that, $grid, tableName);
938
- }
939
- }
940
-
941
- function restoreColumnPosition(currentColumns) {
942
- // 根据 params._index 排序 currentColumns
943
- let sortedColumns = [...currentColumns].sort((a, b) => {
944
- let indexA = a.params?._index ?? 0;
945
- let indexB = b.params?._index ?? 0;
946
- return indexA - indexB;
947
- });
948
- console.log("sortedColumns",sortedColumns);
949
-
950
- // 递归处理 children
951
- sortedColumns.forEach((column) => {
952
- if (column.children && column.children.length > 0) {
953
- column.children = restoreColumnPosition(column.children);
954
- }else{
955
- column.visible = column.params?._visible ?? true;
956
- if(column.params?._width !== undefined){
957
- column.width = column.params?._width
958
- }else{
959
- // delete column.width;
960
- }
961
- }
962
- });
963
-
964
- return sortedColumns;
965
- }
966
-
967
- function customHandle(option) {
968
- let that = option.$grid.$parent;
969
- let $grid = option.$grid;
970
- let originOption = $grid.originOption;
971
- if (option.type === "confirm" || option.type === "reset") {
972
- let tableName = originOption.tableName;
973
- if (option.type === "reset") {
974
- const {collectColumn} = $grid.getTableColumn();
975
- /* const loopDo = (columns)=>{
976
- columns.forEach((item)=>{
977
- if(item.children && item.children.length){
978
- loopDo(item.children);
979
- }else{
980
- if(item.params){
981
- item.visible = item.params._visible ?? true;
982
- if(item.params._width !== undefined)item.width = item.params._width;
983
- }
984
- }
985
- })
986
- }
987
- loopDo(collectColumn); */
988
-
989
- // 还原列的位置
990
- let oldColumns = originOption.columns || [];
991
- if (oldColumns.length > 0) {
992
- const restoredColumns = restoreColumnPosition(collectColumn);
993
- console.log("restoredColumns",restoredColumns);
994
- $grid.loadColumn(restoredColumns);
995
- } else {
996
- $grid.loadColumn(collectColumn);
997
- }
998
- // let columns = that.$baseLodash.cloneDeep(originOption.columns);
999
- // initColumnDefaulAttrs(columns, originOption);
1000
- // $grid.columns = columns;
1001
- }
1002
- if (tableName) {
1003
- setTimeout(() => {
1004
- addTableJson(that, $grid, tableName);
1005
- }, 200);
1006
- }
1007
-
1008
- if (option && option.$event && option.$event.preventDefault) {
1009
- option.$event.preventDefault(); // 取消事件的默认行为
1010
- }
1011
- }
1012
- originOption.customCallback && originOption.customCallback(option);
1013
- }
1014
-
1015
- function changeSelectCount(checked) {
1016
- let checkedLength = checked.records.length;
1017
- }
1018
-
1019
- function getTableData(that, tableRef, type, success) {
1020
- if (
1021
- configUtil.tableConfig.disableTableName
1022
- || settingConfig.tableStorageDisabled
1023
- )
1024
- return false;
1025
- let $grid = getGrid(that, tableRef);
1026
- let tableName = $grid.tableName;
1027
- let url = USER_PREFIX + "/table_column/getTableData";
1028
- let param = {
1029
- tableName: tableName,
1030
- type: type,
1031
- };
1032
- let data = null;
1033
- return that.$http({
1034
- async: false,
1035
- url: url,
1036
- method: "post",
1037
- data: param,
1038
- success: success,
1039
- });
1040
- }
1041
-
1042
- function addTableData(that, tableRef, value, success) {
1043
- if (
1044
- configUtil.tableConfig.disableTableName
1045
- || settingConfig.tableStorageDisabled
1046
- )
1047
- return false;
1048
- let $grid = getGrid(that, tableRef);
1049
- let tableName = $grid.tableName;
1050
- if (tableName) {
1051
- that.$http({
1052
- method: "post",
1053
- url: USER_PREFIX + "/table_column/addTableData",
1054
- data: {
1055
- tableName: tableName,
1056
- type: "isQueryAllPage",
1057
- data: value,
1058
- success: success,
1059
- },
1060
- });
1061
- }
1062
- }
1063
-
1064
- function checkQueryTotal(that, tableRef, value) {
1065
- let $grid = getGrid(that, tableRef);
1066
- $grid.isQueryAllPage = value;
1067
- let tableName = $grid.tableName;
1068
- let option = $grid.getProxyInfo();
1069
- let pagerConfig = $grid.pagerConfig;
1070
-
1071
- $grid.pagerConfig.layouts = pagerConfig.layouts || [];
1072
- addTableData(that, tableRef, value);
1073
- $grid.commitProxy("query");
1074
- }
1075
-
1076
- function getPagerConfigLayouts(opts) {
1077
- if (opts.showPageSizes !== false) {
1078
- return ["Sizes", "PrevPage", "JumpNumber", "NextPage"];
1079
- } else {
1080
- return ["PrevPage", "JumpNumber", "NextPage"];
1081
- }
1082
- }
1083
-
1084
- modules = {
1085
- initVxeTable,
1086
- columnDrop,
1087
- initOption,
1088
- getTableJson,
1089
- addTableJson,
1090
- onColumnWitchChange,
1091
- customHandle,
1092
- changeSelectCount,
1093
- getTableData,
1094
- addTableData,
1095
- checkQueryTotal,
1096
- getCellValue,
1097
- createParams,
1098
- };
1099
-
1100
- if (!configUtil.Vue.prototype.$vxeTableUtil)
1101
- configUtil.Vue.prototype.$vxeTableUtil = modules;
1102
-
1103
- export default modules;