cloud-web-corejs 1.0.54-dev.633 → 1.0.54-dev.636

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