cloud-web-corejs 1.0.54-dev.575 → 1.0.54-dev.577

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