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