aldehyde 0.2.228 → 0.2.231
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/lib/controls/entity-select/popover-entity-select.d.ts.map +1 -1
- package/lib/controls/entity-select/popover-entity-select.js +12 -11
- package/lib/controls/entity-select/popover-entity-select.js.map +1 -1
- package/lib/controls/entry-control.d.ts.map +1 -1
- package/lib/controls/entry-control.js +8 -0
- package/lib/controls/entry-control.js.map +1 -1
- package/lib/controls/tree-select/tree-entity-select.d.ts +12 -0
- package/lib/controls/tree-select/tree-entity-select.d.ts.map +1 -0
- package/lib/controls/tree-select/tree-entity-select.js +86 -0
- package/lib/controls/tree-select/tree-entity-select.js.map +1 -0
- package/lib/layout/MainPage.js +1 -1
- package/lib/module/dtmpl-edit-page.d.ts +1 -0
- package/lib/module/dtmpl-edit-page.d.ts.map +1 -1
- package/lib/module/dtmpl-edit-page.js.map +1 -1
- package/lib/table/act-table.d.ts.map +1 -1
- package/lib/table/act-table.js +45 -25
- package/lib/table/act-table.js.map +1 -1
- package/lib/table/column/column-builder.d.ts.map +1 -1
- package/lib/table/column/column-builder.js +3 -3
- package/lib/table/column/column-builder.js.map +1 -1
- package/lib/table/column/summary-builder.d.ts +39 -0
- package/lib/table/column/summary-builder.d.ts.map +1 -0
- package/lib/table/column/summary-builder.js +508 -0
- package/lib/table/column/summary-builder.js.map +1 -0
- package/lib/table/index.css +2 -2
- package/lib/table/query-table.d.ts +0 -20
- package/lib/table/query-table.d.ts.map +1 -1
- package/lib/table/query-table.js +14 -598
- package/lib/table/query-table.js.map +1 -1
- package/lib/tmpl/control-type-supportor.d.ts.map +1 -1
- package/lib/tmpl/control-type-supportor.js +6 -1
- package/lib/tmpl/control-type-supportor.js.map +1 -1
- package/lib/tmpl/interface.d.ts +0 -6
- package/lib/tmpl/interface.d.ts.map +1 -1
- package/lib/tmpl/interface.js.map +1 -1
- package/lib/tree/tmpl-tree.d.ts +9 -4
- package/lib/tree/tmpl-tree.d.ts.map +1 -1
- package/lib/tree/tmpl-tree.js +70 -94
- package/lib/tree/tmpl-tree.js.map +1 -1
- package/lib/tree/tree-node.js +1 -1
- package/lib/tree/tree-utils.d.ts +19 -0
- package/lib/tree/tree-utils.d.ts.map +1 -1
- package/lib/tree/tree-utils.js +128 -0
- package/lib/tree/tree-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/aldehyde/controls/entity-select/popover-entity-select.tsx +9 -12
- package/src/aldehyde/controls/entry-control.tsx +20 -0
- package/src/aldehyde/controls/tree-select/tree-entity-select.tsx +113 -0
- package/src/aldehyde/layout/MainPage.tsx +1 -1
- package/src/aldehyde/module/dtmpl-edit-page.tsx +1 -0
- package/src/aldehyde/table/act-table.tsx +114 -69
- package/src/aldehyde/table/column/column-builder.tsx +4 -3
- package/src/aldehyde/table/column/summary-builder.tsx +713 -0
- package/src/aldehyde/table/index.css +2 -2
- package/src/aldehyde/table/query-table.tsx +16 -837
- package/src/aldehyde/tmpl/control-type-supportor.tsx +8 -1
- package/src/aldehyde/tmpl/interface.tsx +0 -2
- package/src/aldehyde/tree/tmpl-tree.tsx +72 -89
- package/src/aldehyde/tree/tree-node.tsx +1 -1
- package/src/aldehyde/tree/tree-utils.tsx +138 -0
package/lib/table/query-table.js
CHANGED
|
@@ -19,7 +19,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import React from "react";
|
|
22
|
-
import { Collapse } from "antd";
|
|
23
22
|
import Table from "./control-table-x-axis-wrapper";
|
|
24
23
|
import "./index.css";
|
|
25
24
|
import HcserviceV3 from "../tmpl/hcservice-v3";
|
|
@@ -27,10 +26,9 @@ import Pagination from "./pagination";
|
|
|
27
26
|
import { SortableContainer, SortableElement } from "react-sortable-hoc";
|
|
28
27
|
import { arrayMoveImmutable } from "array-move";
|
|
29
28
|
import { LocaleContext } from "../locale/LocaleProvider";
|
|
30
|
-
import { BigNumber } from "bignumber.js";
|
|
31
29
|
import { init, merge, statistic } from "../utils/dsu";
|
|
32
30
|
import VerticalList from "../list/vertical-list";
|
|
33
|
-
|
|
31
|
+
import SummaryBuilder from "./column/summary-builder";
|
|
34
32
|
const SortableItem = SortableElement((props) => (React.createElement("tr", Object.assign({ className: "sortable-item-hover" }, props))));
|
|
35
33
|
const SortableBody = SortableContainer((props) => React.createElement("tbody", Object.assign({}, props)));
|
|
36
34
|
class QueryTable extends React.PureComponent {
|
|
@@ -224,493 +222,6 @@ class QueryTable extends React.PureComponent {
|
|
|
224
222
|
}
|
|
225
223
|
});
|
|
226
224
|
}
|
|
227
|
-
getTableSummaryNumberValue(value) {
|
|
228
|
-
if (value === undefined || value === null)
|
|
229
|
-
return 0;
|
|
230
|
-
if (typeof value === "string")
|
|
231
|
-
return Number(value);
|
|
232
|
-
return Number(value[0].split("@R@")[1]);
|
|
233
|
-
}
|
|
234
|
-
deepClone(source, hash = new WeakSet()) {
|
|
235
|
-
try {
|
|
236
|
-
if (typeof source !== "object" ||
|
|
237
|
-
source === null ||
|
|
238
|
-
React.isValidElement(source)) {
|
|
239
|
-
return source;
|
|
240
|
-
}
|
|
241
|
-
if (hash.has(source)) {
|
|
242
|
-
return source;
|
|
243
|
-
}
|
|
244
|
-
hash.add(source);
|
|
245
|
-
const target = Array.isArray(source) ? [] : {};
|
|
246
|
-
Reflect.ownKeys(source).forEach((key) => {
|
|
247
|
-
const val = source[key];
|
|
248
|
-
if (typeof val === "object" && val != null) {
|
|
249
|
-
target[key] = this.deepClone(val, hash);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
target[key] = val;
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
return target;
|
|
256
|
-
}
|
|
257
|
-
catch (err) {
|
|
258
|
-
console.log("deepclone err", err, source);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
buildKeys(keys) {
|
|
262
|
-
return keys.map((i) => i.title).join("-");
|
|
263
|
-
}
|
|
264
|
-
buildColTag(cols, keys = []) {
|
|
265
|
-
for (const col of cols) {
|
|
266
|
-
if (!col.children) {
|
|
267
|
-
col.dataIndex = this.buildKeys([
|
|
268
|
-
...keys,
|
|
269
|
-
{ dataKey: col._type ? col._type : col.title, title: col.title },
|
|
270
|
-
]);
|
|
271
|
-
if (col.keys === undefined)
|
|
272
|
-
col.keys = [
|
|
273
|
-
...keys,
|
|
274
|
-
{ dataKey: col._type ? col._type : col.title, title: col.title },
|
|
275
|
-
];
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
this.buildColTag(col.children, [
|
|
279
|
-
...keys,
|
|
280
|
-
{ dataKey: col._type ? col._type : col.title, title: col.title },
|
|
281
|
-
]);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
getCurCalKeys(cols, keys = []) {
|
|
286
|
-
for (const col of cols) {
|
|
287
|
-
if (Array.isArray(col.children)) {
|
|
288
|
-
this.getCurCalKeys(col.children, keys);
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
keys.push({
|
|
292
|
-
factIndex: col.keys[col.keys.length - 1],
|
|
293
|
-
dataIndex: col.dataIndex,
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
return keys;
|
|
298
|
-
}
|
|
299
|
-
setSumColKeys(sumCol, sumKeys) {
|
|
300
|
-
if (sumKeys.length === 0)
|
|
301
|
-
return;
|
|
302
|
-
if (Array.isArray(sumCol.children)) {
|
|
303
|
-
this.setSumColKeys(sumCol.children, sumKeys);
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
for (const col of sumCol) {
|
|
307
|
-
const factKey = col.keys[col.keys.length - 1].dataKey;
|
|
308
|
-
col.sumDataIndex = sumKeys.filter(({ factIndex: { dataKey } }) => dataKey === factKey);
|
|
309
|
-
col.keys[col.keys.length - 1].sumDataIndex = col.sumDataIndex.map(({ dataIndex }) => dataIndex);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
handleProSummaryTable(data) {
|
|
314
|
-
var _a, _b, _c, _d, _e, _f;
|
|
315
|
-
const isProSumarryTable = Boolean(this.props.subtotalXColumn || this.props.subtotalYColumn);
|
|
316
|
-
if (!isProSumarryTable)
|
|
317
|
-
return { proSummaryTableColumns: [], proSummaryTableData: [] };
|
|
318
|
-
const { translate } = this.context;
|
|
319
|
-
const { subtotalXColumn, subtotalYColumn, columns: _columns } = this.props;
|
|
320
|
-
const columns = _columns;
|
|
321
|
-
for (const column of columns) {
|
|
322
|
-
delete column["sorter"];
|
|
323
|
-
}
|
|
324
|
-
for (const d of data) {
|
|
325
|
-
for (const [k, v] of Object.entries(d)) {
|
|
326
|
-
if (v == null || v == "null") {
|
|
327
|
-
d[k] = "";
|
|
328
|
-
}
|
|
329
|
-
else if (typeof v === "string" && (v === null || v === void 0 ? void 0 : v.includes("@R@"))) {
|
|
330
|
-
d[k] = v.split("@R@")[1];
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
console.log("data", data);
|
|
335
|
-
console.log("columns", columns);
|
|
336
|
-
const colMp = {
|
|
337
|
-
dimension: [],
|
|
338
|
-
fact: [],
|
|
339
|
-
others: [
|
|
340
|
-
{
|
|
341
|
-
dataIndex: "orderInGroup",
|
|
342
|
-
title: "orderInGroup",
|
|
343
|
-
},
|
|
344
|
-
],
|
|
345
|
-
};
|
|
346
|
-
const colIdToNameMp = {};
|
|
347
|
-
const colNameToIdMp = {};
|
|
348
|
-
for (const col of columns) {
|
|
349
|
-
colIdToNameMp[col["dataIndex"]] = col["title"];
|
|
350
|
-
colNameToIdMp[col["title"]] = col["dataIndex"];
|
|
351
|
-
if (col.statColType !== undefined) {
|
|
352
|
-
colMp[col.statColType].push(this.deepClone(col));
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
if (col.title !== "序号")
|
|
356
|
-
colMp["others"].push(this.deepClone(col));
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
console.log("colIdToNameMp", colIdToNameMp);
|
|
360
|
-
console.log("colNameToIdMp", colNameToIdMp);
|
|
361
|
-
console.log("colMp", colMp);
|
|
362
|
-
// canReadData
|
|
363
|
-
const canReadData = [];
|
|
364
|
-
let order = 0;
|
|
365
|
-
for (const d of data) {
|
|
366
|
-
const item = {};
|
|
367
|
-
for (const [k, v] of Object.entries(d)) {
|
|
368
|
-
let _v = v;
|
|
369
|
-
if (colMp.fact.findIndex(({ dataIndex }) => dataIndex === k) > -1 &&
|
|
370
|
-
v === null)
|
|
371
|
-
_v = 0;
|
|
372
|
-
item[colIdToNameMp[k]] = _v;
|
|
373
|
-
}
|
|
374
|
-
canReadData.push(Object.assign(Object.assign({}, item), { orderInGroup: order++ }));
|
|
375
|
-
}
|
|
376
|
-
console.log("canReadData", canReadData);
|
|
377
|
-
let proSummaryTableColumns = [
|
|
378
|
-
...this.deepClone(colMp.dimension),
|
|
379
|
-
...this.deepClone(colMp.others),
|
|
380
|
-
], proSummaryTableData = [], excludeGroupSumData = [];
|
|
381
|
-
const cal = (_a = colMp.fact[0]) === null || _a === void 0 ? void 0 : _a.cal;
|
|
382
|
-
const calTxt = cal === "sum" ? translate("小计") : translate("均值");
|
|
383
|
-
const calMp = {};
|
|
384
|
-
colMp.fact.forEach(({ title, cal }) => (calMp[title] = cal));
|
|
385
|
-
// 计算列
|
|
386
|
-
if (subtotalYColumn &&
|
|
387
|
-
Array.isArray(subtotalYColumn) &&
|
|
388
|
-
subtotalYColumn.length) {
|
|
389
|
-
// col
|
|
390
|
-
let tnodes = [];
|
|
391
|
-
for (let i = 0; i < subtotalYColumn.length; i++) {
|
|
392
|
-
const y = subtotalYColumn[i];
|
|
393
|
-
const id = y.id;
|
|
394
|
-
const mp = {};
|
|
395
|
-
let _tnodes = [];
|
|
396
|
-
for (const d of data)
|
|
397
|
-
mp[d[id]] = colIdToNameMp[id];
|
|
398
|
-
for (const [k, v] of Object.entries(mp)) {
|
|
399
|
-
const tnode = {
|
|
400
|
-
title: k,
|
|
401
|
-
_type: v,
|
|
402
|
-
children: [...this.deepClone(i === 0 ? colMp.fact : tnodes)],
|
|
403
|
-
};
|
|
404
|
-
_tnodes.push(tnode);
|
|
405
|
-
}
|
|
406
|
-
this.buildColTag(_tnodes);
|
|
407
|
-
console.log("_tnodes", JSON.parse(JSON.stringify(_tnodes)));
|
|
408
|
-
const sumCol = {
|
|
409
|
-
title: calTxt,
|
|
410
|
-
children: [...this.deepClone(colMp.fact)],
|
|
411
|
-
TYPE: cal,
|
|
412
|
-
};
|
|
413
|
-
this.buildColTag([sumCol]);
|
|
414
|
-
this.setSumColKeys(sumCol, this.getCurCalKeys(_tnodes));
|
|
415
|
-
_tnodes.unshift(sumCol);
|
|
416
|
-
tnodes = _tnodes;
|
|
417
|
-
proSummaryTableColumns.splice(proSummaryTableColumns.findIndex((item) => item.dataIndex === id), 1);
|
|
418
|
-
}
|
|
419
|
-
proSummaryTableColumns.push(...tnodes);
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
proSummaryTableColumns.push(...colMp.fact);
|
|
423
|
-
}
|
|
424
|
-
// buildData
|
|
425
|
-
this.buildColTag(proSummaryTableColumns);
|
|
426
|
-
// 处理行
|
|
427
|
-
const rowMp = {};
|
|
428
|
-
const rowKey = [];
|
|
429
|
-
for (const col of proSummaryTableColumns) {
|
|
430
|
-
if (Array.isArray(col.keys) && col.keys.length === 1)
|
|
431
|
-
rowKey.push(col);
|
|
432
|
-
}
|
|
433
|
-
console.log("rowKey", rowKey);
|
|
434
|
-
for (const d of canReadData) {
|
|
435
|
-
let t = rowMp;
|
|
436
|
-
for (let i = 0; i < rowKey.length; i++) {
|
|
437
|
-
const key = rowKey[i].title;
|
|
438
|
-
if (t[d[key]] === undefined) {
|
|
439
|
-
if (i !== rowKey.length - 1)
|
|
440
|
-
t[d[key]] = {};
|
|
441
|
-
else
|
|
442
|
-
t[d[key]] = [];
|
|
443
|
-
}
|
|
444
|
-
t = t[d[key]];
|
|
445
|
-
}
|
|
446
|
-
if (Array.isArray(t))
|
|
447
|
-
t.push(d);
|
|
448
|
-
}
|
|
449
|
-
// 行数据处理完毕
|
|
450
|
-
console.log("rowMp", rowMp);
|
|
451
|
-
// 处理列
|
|
452
|
-
const colKey = [];
|
|
453
|
-
const colKeyTitle = this.flatSummaryCol(proSummaryTableColumns);
|
|
454
|
-
for (const col of proSummaryTableColumns) {
|
|
455
|
-
if ((col.statColType === "fact" || Array.isArray(col.children)) &&
|
|
456
|
-
col.TYPE === undefined) {
|
|
457
|
-
colKey.push(col);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
const flatSummaryColTitle = this.flatSummaryCol(colKey);
|
|
461
|
-
const flatSummaryRowTitle = this.flatSummaryCol(rowKey);
|
|
462
|
-
const flatSummaryCalTitle = this.flatSummaryCol(proSummaryTableColumns.filter(({ TYPE }) => TYPE !== undefined));
|
|
463
|
-
console.log("colKey", colKey);
|
|
464
|
-
console.log("colKeyTitle", colKeyTitle);
|
|
465
|
-
console.log("flatSummaryColTitle", flatSummaryColTitle);
|
|
466
|
-
console.log("flatSummaryRowTitle", flatSummaryRowTitle);
|
|
467
|
-
console.log("flatSummaryCalTitle", flatSummaryCalTitle);
|
|
468
|
-
proSummaryTableData = this.handleColData(rowMp, flatSummaryRowTitle, flatSummaryColTitle, flatSummaryCalTitle, cal);
|
|
469
|
-
excludeGroupSumData = this.deepClone(proSummaryTableData);
|
|
470
|
-
console.log("excludeGroupSumData", excludeGroupSumData);
|
|
471
|
-
if (subtotalXColumn &&
|
|
472
|
-
Array.isArray(subtotalXColumn) &&
|
|
473
|
-
subtotalXColumn.length) {
|
|
474
|
-
const sortKeys = subtotalXColumn.map(({ id }) => colIdToNameMp[id]);
|
|
475
|
-
const rowSumMp = this.buildRowMp(proSummaryTableData, sortKeys);
|
|
476
|
-
console.log("rowSumMp", rowSumMp);
|
|
477
|
-
const calRowKeys = [
|
|
478
|
-
...flatSummaryCalTitle,
|
|
479
|
-
...flatSummaryColTitle,
|
|
480
|
-
].map((i) => this.buildKeys(i));
|
|
481
|
-
console.log("calRowKeys", calRowKeys);
|
|
482
|
-
proSummaryTableData = this.handleRowData(rowSumMp, calRowKeys, calMp, calTxt, sortKeys[0]);
|
|
483
|
-
}
|
|
484
|
-
// 序号
|
|
485
|
-
if (columns[0].title === "序号") {
|
|
486
|
-
const col = {
|
|
487
|
-
dataIndex: "序号",
|
|
488
|
-
title: "序号",
|
|
489
|
-
width: 60,
|
|
490
|
-
order: -1,
|
|
491
|
-
};
|
|
492
|
-
if (columns[0].colWidth) {
|
|
493
|
-
col.width = columns[0].colWidth;
|
|
494
|
-
}
|
|
495
|
-
proSummaryTableColumns.unshift(col);
|
|
496
|
-
proSummaryTableData.forEach((_, idx) => {
|
|
497
|
-
_["序号"] = idx + 1;
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
// 做总计
|
|
501
|
-
if (this.props.summaryConfigs &&
|
|
502
|
-
((_b = this.props.summaryConfigs) === null || _b === void 0 ? void 0 : _b.length) !== 0 &&
|
|
503
|
-
flatSummaryRowTitle.length &&
|
|
504
|
-
proSummaryTableData.length) {
|
|
505
|
-
const calkeys = [
|
|
506
|
-
...flatSummaryCalTitle,
|
|
507
|
-
...flatSummaryColTitle,
|
|
508
|
-
].map((i) => this.buildKeys(i));
|
|
509
|
-
const sumData = {
|
|
510
|
-
[(_c = proSummaryTableColumns[0]) === null || _c === void 0 ? void 0 : _c.dataIndex]: cal === "sum" ? translate("${合计}") : translate("${均值}"),
|
|
511
|
-
_type: calMp,
|
|
512
|
-
_calRange: "all",
|
|
513
|
-
};
|
|
514
|
-
for (const key of calkeys) {
|
|
515
|
-
if (cal === "sum")
|
|
516
|
-
sumData[key] = excludeGroupSumData.reduce((last, d) => last.plus(BigNumber(d[key])), BigNumber(0));
|
|
517
|
-
if (cal === "avg")
|
|
518
|
-
sumData[key] = excludeGroupSumData.reduce((last, d) => last.plus(BigNumber(d[key]).div(excludeGroupSumData.length)), BigNumber(0));
|
|
519
|
-
const hash = (...args) => args.join("-");
|
|
520
|
-
const hashKey = (data, keys) => hash(...keys.map((key) => data[key]));
|
|
521
|
-
if (calMp[key] === "groupIsum") {
|
|
522
|
-
const allKeys = (_d = this.props.groupIColumns) === null || _d === void 0 ? void 0 : _d.map(({ title }) => title);
|
|
523
|
-
const set = new Set();
|
|
524
|
-
sumData[key] = excludeGroupSumData.reduce((lastNum, item) => {
|
|
525
|
-
if (set.has(hashKey(item, allKeys)))
|
|
526
|
-
return lastNum;
|
|
527
|
-
set.add(hashKey(item, allKeys));
|
|
528
|
-
return lastNum.plus(new BigNumber(this.getTableSummaryNumberValue(item[key])));
|
|
529
|
-
}, new BigNumber(0));
|
|
530
|
-
}
|
|
531
|
-
if (calMp[key] === "groupIavg") {
|
|
532
|
-
const set = new Set();
|
|
533
|
-
let nums = 0;
|
|
534
|
-
const allKeys = (_e = this.props.groupIColumns) === null || _e === void 0 ? void 0 : _e.map(({ title }) => title);
|
|
535
|
-
data.forEach((item) => {
|
|
536
|
-
if (set.has(hashKey(item, allKeys)))
|
|
537
|
-
return;
|
|
538
|
-
set.add(hashKey(item, allKeys));
|
|
539
|
-
nums++;
|
|
540
|
-
});
|
|
541
|
-
set.clear();
|
|
542
|
-
sumData[key] = excludeGroupSumData.reduce((lastNum, item) => {
|
|
543
|
-
if (set.has(hashKey(item, allKeys)))
|
|
544
|
-
return lastNum;
|
|
545
|
-
set.add(hashKey(item, allKeys));
|
|
546
|
-
return lastNum.plus(new BigNumber(this.getTableSummaryNumberValue(item[key])).div(nums));
|
|
547
|
-
}, new BigNumber(0));
|
|
548
|
-
}
|
|
549
|
-
sumData[key] = (_f = sumData[key]) === null || _f === void 0 ? void 0 : _f.toString();
|
|
550
|
-
}
|
|
551
|
-
proSummaryTableData.push(sumData);
|
|
552
|
-
}
|
|
553
|
-
// 给小计和总计染色
|
|
554
|
-
this.stain(proSummaryTableColumns);
|
|
555
|
-
// 删除默认数据在组内顺序字段
|
|
556
|
-
proSummaryTableColumns.splice(proSummaryTableColumns.findIndex(({ dataIndex }) => dataIndex === "orderInGroup"), 1);
|
|
557
|
-
proSummaryTableData.forEach((item) => delete item.orderInGroup);
|
|
558
|
-
// 排序
|
|
559
|
-
proSummaryTableColumns = proSummaryTableColumns.sort((a, b) => {
|
|
560
|
-
if (a.order === undefined && b.order === undefined)
|
|
561
|
-
return 0;
|
|
562
|
-
if (a.order === undefined)
|
|
563
|
-
return 1;
|
|
564
|
-
if (b.order === undefined)
|
|
565
|
-
return -1;
|
|
566
|
-
return a.order < b.order ? -1 : 1;
|
|
567
|
-
});
|
|
568
|
-
console.log("proSummaryTableColumns", proSummaryTableColumns);
|
|
569
|
-
console.log("proSummaryTableData", proSummaryTableData);
|
|
570
|
-
return { proSummaryTableColumns, proSummaryTableData };
|
|
571
|
-
}
|
|
572
|
-
flatSummaryCol(arr, res = []) {
|
|
573
|
-
for (const i of arr) {
|
|
574
|
-
if (!i.children)
|
|
575
|
-
res.push(i.keys);
|
|
576
|
-
else
|
|
577
|
-
this.flatSummaryCol(i.children, res);
|
|
578
|
-
}
|
|
579
|
-
return res;
|
|
580
|
-
}
|
|
581
|
-
handleColData(rowMp, flatSummaryRowTitle, flatSummaryColTitle, flatSummaryCalTitle, cal, idx = 0, data = {}, list = []) {
|
|
582
|
-
var _a, _b, _c;
|
|
583
|
-
if (Array.isArray(rowMp)) {
|
|
584
|
-
for (const col of flatSummaryColTitle) {
|
|
585
|
-
const key = this.buildKeys(col);
|
|
586
|
-
const colTarget = [];
|
|
587
|
-
const preConditions = col.slice(0, col.length - 1);
|
|
588
|
-
const targetKey = col.slice(col.length - 1)[0].title;
|
|
589
|
-
for (const d of rowMp) {
|
|
590
|
-
if (preConditions.every(({ dataKey, title }) => d[dataKey] === title)) {
|
|
591
|
-
colTarget.push(d);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
if (data[key] === undefined || data[key] == "") {
|
|
595
|
-
data[key] = BigNumber(0);
|
|
596
|
-
}
|
|
597
|
-
if (cal === "sum")
|
|
598
|
-
data[key] = colTarget.reduce((last, d) => last.plus(BigNumber(d[targetKey])), BigNumber(0));
|
|
599
|
-
if (cal === "avg")
|
|
600
|
-
data[key] = colTarget.reduce((last, d) => last.plus(BigNumber(d[targetKey]).div(colTarget.length)), BigNumber(0));
|
|
601
|
-
data[key] =
|
|
602
|
-
((_a = data[key]) === null || _a === void 0 ? void 0 : _a.toString()) == "NaN" ? "0" : (_b = data[key]) === null || _b === void 0 ? void 0 : _b.toString();
|
|
603
|
-
}
|
|
604
|
-
for (const calCol of flatSummaryCalTitle) {
|
|
605
|
-
const key = this.buildKeys(calCol);
|
|
606
|
-
const sumDataIndex = calCol[calCol.length - 1].sumDataIndex;
|
|
607
|
-
if (data[key] === undefined || data[key] == "")
|
|
608
|
-
data[key] = BigNumber(0);
|
|
609
|
-
if (cal === "sum")
|
|
610
|
-
data[key] = sumDataIndex.reduce((last, dataKey) => last.plus(BigNumber(data[dataKey])), BigNumber(0));
|
|
611
|
-
if (cal === "avg")
|
|
612
|
-
data[key] = sumDataIndex.reduce((last, dataKey) => last.plus(BigNumber(data[dataKey]).div(sumDataIndex.length)), BigNumber(0));
|
|
613
|
-
data[key] = (_c = data[key]) === null || _c === void 0 ? void 0 : _c.toString();
|
|
614
|
-
}
|
|
615
|
-
list.push(data);
|
|
616
|
-
}
|
|
617
|
-
else {
|
|
618
|
-
for (const [k, v] of Object.entries(rowMp)) {
|
|
619
|
-
const dataKey = flatSummaryRowTitle[idx][0].dataKey;
|
|
620
|
-
data[dataKey] = k;
|
|
621
|
-
this.handleColData(v, flatSummaryRowTitle, flatSummaryColTitle, flatSummaryCalTitle, cal, idx + 1, this.deepClone(data), list);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
return list;
|
|
625
|
-
}
|
|
626
|
-
buildRowMp(data, sortKeys, idx = 0, mp = {}) {
|
|
627
|
-
if (idx >= sortKeys.length)
|
|
628
|
-
return data;
|
|
629
|
-
const dataKey = sortKeys[idx];
|
|
630
|
-
for (const d of data) {
|
|
631
|
-
if (mp[d[dataKey]] === undefined)
|
|
632
|
-
mp[d[dataKey]] = [];
|
|
633
|
-
mp[d[dataKey]].push(d);
|
|
634
|
-
}
|
|
635
|
-
for (const [k, v] of Object.entries(mp)) {
|
|
636
|
-
mp[k] = this.buildRowMp(v, sortKeys, idx + 1);
|
|
637
|
-
}
|
|
638
|
-
return mp;
|
|
639
|
-
}
|
|
640
|
-
handleRowData(data, calKeys, calMp, calTxt, calTxtKey, res = []) {
|
|
641
|
-
var _a, _b, _c;
|
|
642
|
-
for (const [k, v] of Object.entries(data)) {
|
|
643
|
-
if (Array.isArray(v)) {
|
|
644
|
-
const sumData = {
|
|
645
|
-
[calTxtKey]: calTxt,
|
|
646
|
-
_type: calMp,
|
|
647
|
-
_calRange: "small",
|
|
648
|
-
};
|
|
649
|
-
for (const calKey of calKeys) {
|
|
650
|
-
if (calMp[calKey] === "sum")
|
|
651
|
-
sumData[calKey] = v.reduce((last, d) => last.plus(BigNumber(d[calKey])), BigNumber(0));
|
|
652
|
-
if (calMp[calKey] === "avg")
|
|
653
|
-
sumData[calKey] = v.reduce((last, d) => last.plus(BigNumber(d[calKey]).div(v.length)), BigNumber(0));
|
|
654
|
-
const hash = (...args) => args.join("-");
|
|
655
|
-
const hashKey = (data, keys) => hash(...keys.map((key) => data[key]));
|
|
656
|
-
if (calMp[calKey] === "groupIsum") {
|
|
657
|
-
const allKeys = (_a = this.props.groupIColumns) === null || _a === void 0 ? void 0 : _a.map(({ title }) => title);
|
|
658
|
-
const set = new Set();
|
|
659
|
-
sumData[calKey] = v.reduce((lastNum, item) => {
|
|
660
|
-
if (set.has(hashKey(item, allKeys)))
|
|
661
|
-
return lastNum;
|
|
662
|
-
set.add(hashKey(item, allKeys));
|
|
663
|
-
return lastNum.plus(new BigNumber(this.getTableSummaryNumberValue(item[calKey])));
|
|
664
|
-
}, new BigNumber(0));
|
|
665
|
-
}
|
|
666
|
-
if (calMp[calKey] === "groupIavg") {
|
|
667
|
-
const set = new Set();
|
|
668
|
-
let nums = 0;
|
|
669
|
-
const allKeys = (_b = this.props.groupIColumns) === null || _b === void 0 ? void 0 : _b.map(({ title }) => title);
|
|
670
|
-
data.forEach((item) => {
|
|
671
|
-
if (set.has(hashKey(item, allKeys)))
|
|
672
|
-
return;
|
|
673
|
-
set.add(hashKey(item, allKeys));
|
|
674
|
-
nums++;
|
|
675
|
-
});
|
|
676
|
-
set.clear();
|
|
677
|
-
sumData[calKey] = v.reduce((lastNum, item) => {
|
|
678
|
-
if (set.has(hashKey(item, allKeys)))
|
|
679
|
-
return lastNum;
|
|
680
|
-
set.add(hashKey(item, allKeys));
|
|
681
|
-
return lastNum.plus(new BigNumber(this.getTableSummaryNumberValue(item[calKey])).div(nums));
|
|
682
|
-
}, new BigNumber(0));
|
|
683
|
-
}
|
|
684
|
-
sumData[calKey] = (_c = sumData[calKey]) === null || _c === void 0 ? void 0 : _c.toString();
|
|
685
|
-
}
|
|
686
|
-
v.sort((a, b) => Number(a.orderInGroup) < Number(b.orderInGroup) ? -1 : 1);
|
|
687
|
-
res.push(...v, sumData);
|
|
688
|
-
}
|
|
689
|
-
else {
|
|
690
|
-
this.handleRowData(v, calKeys, calMp, calTxt, calTxtKey, res);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
return res;
|
|
694
|
-
}
|
|
695
|
-
stain(cols) {
|
|
696
|
-
for (const col of cols) {
|
|
697
|
-
if (Array.isArray(col.children)) {
|
|
698
|
-
this.stain(col.children);
|
|
699
|
-
}
|
|
700
|
-
else {
|
|
701
|
-
col.render = function (text, record, index) {
|
|
702
|
-
let className = "";
|
|
703
|
-
if (record._type !== undefined) {
|
|
704
|
-
if (record._calRange === "small")
|
|
705
|
-
className = "xiaoji";
|
|
706
|
-
else
|
|
707
|
-
className = "zongji";
|
|
708
|
-
}
|
|
709
|
-
return React.createElement("div", { className: className }, text);
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
225
|
mergeRowInCol(data, rowIdx, colIdx, mergeMp, calNum) {
|
|
715
226
|
const idx = rowIdx * calNum + colIdx;
|
|
716
227
|
// console.log(rowIdx, colIdx, mergeMp[idx]);
|
|
@@ -754,12 +265,15 @@ class QueryTable extends React.PureComponent {
|
|
|
754
265
|
}
|
|
755
266
|
}
|
|
756
267
|
render() {
|
|
757
|
-
const { pageInfo, columns, viewModels, summaryConfigs, subtotalXColumn,
|
|
268
|
+
const { pageInfo, columns, viewModels, summaryConfigs, subtotalXColumn, tableProps, groupIColumns, hiddenRowCodes, columnConfigs, serverKey, } = this.props;
|
|
758
269
|
//debugger
|
|
759
270
|
const { touchEnd, total, loading, virtualEndPageNo, dataSource } = this.state;
|
|
271
|
+
const isProSumarryTable = Boolean(subtotalXColumn);
|
|
760
272
|
const { translate } = this.context;
|
|
761
|
-
const
|
|
762
|
-
|
|
273
|
+
const { proSummaryTableColumns, proSummaryTableData, } = SummaryBuilder.handleProSummaryTable({
|
|
274
|
+
subtotalXColumn, columns, data: this.getUnHidenDataSource(),
|
|
275
|
+
translate, groupIColumns
|
|
276
|
+
});
|
|
763
277
|
let current_cols = isProSumarryTable
|
|
764
278
|
? proSummaryTableColumns
|
|
765
279
|
: columns
|
|
@@ -770,9 +284,15 @@ class QueryTable extends React.PureComponent {
|
|
|
770
284
|
current_cols.forEach((c) => {
|
|
771
285
|
table_x = table_x + (c.width ? c.width : 140);
|
|
772
286
|
});
|
|
287
|
+
let dat = this.getUnHidenDataSource();
|
|
773
288
|
const originData = isProSumarryTable
|
|
774
289
|
? proSummaryTableData
|
|
775
|
-
:
|
|
290
|
+
: dat;
|
|
291
|
+
let summary = (pageData1) => {
|
|
292
|
+
return SummaryBuilder.summary({ translate, summaryConfigs,
|
|
293
|
+
pageData: dat, columns,
|
|
294
|
+
rowSelection: this.getRowSelection(), groupIColumns });
|
|
295
|
+
};
|
|
776
296
|
console.log("%crender data: ", "color: red", originData);
|
|
777
297
|
console.log("%crender col: ", "color: red", current_cols);
|
|
778
298
|
const washOriginData = originData.map((i, idx) => {
|
|
@@ -829,110 +349,6 @@ class QueryTable extends React.PureComponent {
|
|
|
829
349
|
console.log("统计结果", mergeMp);
|
|
830
350
|
// 给 col 添加 mergeRowInCol
|
|
831
351
|
current_cols.forEach((col, colIdx) => (col.onCell = (_, rowIdx) => this.mergeRowInCol(_, rowIdx, colIdx, mergeMp, current_cols.length)));
|
|
832
|
-
// current_cols[10].onCell = (_, rowIdx) =>
|
|
833
|
-
// this.mergeRowInCol(_, rowIdx, 10, mergeMp, current_cols.length);
|
|
834
|
-
let summary = (pageData) => {
|
|
835
|
-
var _a, _b, _c, _d;
|
|
836
|
-
if (!summaryConfigs ||
|
|
837
|
-
(summaryConfigs === null || summaryConfigs === void 0 ? void 0 : summaryConfigs.length) === 0 ||
|
|
838
|
-
pageData.length === 0)
|
|
839
|
-
return React.createElement(React.Fragment, null);
|
|
840
|
-
const columns = isProSumarryTable
|
|
841
|
-
? proSummaryTableColumns
|
|
842
|
-
: this.props.columns;
|
|
843
|
-
const sumConfigs = { sum: [], avg: [] };
|
|
844
|
-
if (this.getRowSelection()) {
|
|
845
|
-
sumConfigs["avg"].push({
|
|
846
|
-
value: "",
|
|
847
|
-
id: "",
|
|
848
|
-
columnConfig: { align: "center" },
|
|
849
|
-
});
|
|
850
|
-
sumConfigs["sum"].push({
|
|
851
|
-
value: "",
|
|
852
|
-
id: "",
|
|
853
|
-
columnConfig: { align: "center" },
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
sumConfigs["sum"].push({
|
|
857
|
-
value: translate("${合计}"),
|
|
858
|
-
id: "title",
|
|
859
|
-
columnConfig: { align: "center" },
|
|
860
|
-
});
|
|
861
|
-
sumConfigs["avg"].push({
|
|
862
|
-
value: translate("${均值}"),
|
|
863
|
-
id: "title",
|
|
864
|
-
columnConfig: { align: "center" },
|
|
865
|
-
});
|
|
866
|
-
let sumLen = 0, avgLen = 0;
|
|
867
|
-
for (let i = 0; i < columns.length; i++) {
|
|
868
|
-
const idx = i, dataIndex = columns[i].dataIndex;
|
|
869
|
-
if (idx === 0)
|
|
870
|
-
continue;
|
|
871
|
-
const sum = { value: "", id: "", columnConfig: columns[i] };
|
|
872
|
-
const sumConfigIdx = summaryConfigs.findIndex(({ id }) => id === dataIndex);
|
|
873
|
-
if (sumConfigIdx === -1) {
|
|
874
|
-
sumConfigs["sum"].push(sum);
|
|
875
|
-
sumConfigs["avg"].push(sum);
|
|
876
|
-
continue;
|
|
877
|
-
}
|
|
878
|
-
const argFun = summaryConfigs[sumConfigIdx].aggFunc;
|
|
879
|
-
if (argFun === "sum")
|
|
880
|
-
sum.value = (_a = pageData
|
|
881
|
-
.reduce((lastNum, item) => lastNum.plus(new BigNumber(this.getTableSummaryNumberValue(item[dataIndex]))), new BigNumber(0))) === null || _a === void 0 ? void 0 : _a.toString();
|
|
882
|
-
if (argFun === "avg")
|
|
883
|
-
sum.value = (_b = pageData
|
|
884
|
-
.reduce((lastNum, item) => lastNum.plus(new BigNumber(this.getTableSummaryNumberValue(item[dataIndex])).div(pageData.length)), new BigNumber(0))) === null || _b === void 0 ? void 0 : _b.toString();
|
|
885
|
-
const hash = (...args) => args.join("-");
|
|
886
|
-
const hashKey = (data, keys) => hash(...keys.map((key) => data[key]));
|
|
887
|
-
if (argFun === "groupIsum") {
|
|
888
|
-
const allKeys = groupIColumns === null || groupIColumns === void 0 ? void 0 : groupIColumns.map(({ id }) => id);
|
|
889
|
-
const set = new Set();
|
|
890
|
-
sum.value = (_c = pageData
|
|
891
|
-
.reduce((lastNum, item) => {
|
|
892
|
-
if (set.has(hashKey(item, allKeys)))
|
|
893
|
-
return lastNum;
|
|
894
|
-
set.add(hashKey(item, allKeys));
|
|
895
|
-
return lastNum.plus(new BigNumber(this.getTableSummaryNumberValue(item[dataIndex])));
|
|
896
|
-
}, new BigNumber(0))) === null || _c === void 0 ? void 0 : _c.toString();
|
|
897
|
-
}
|
|
898
|
-
if (argFun === "groupIavg") {
|
|
899
|
-
const set = new Set();
|
|
900
|
-
let nums = 0;
|
|
901
|
-
const allKeys = groupIColumns === null || groupIColumns === void 0 ? void 0 : groupIColumns.map(({ id }) => id);
|
|
902
|
-
pageData.forEach((item) => {
|
|
903
|
-
if (set.has(hashKey(item, allKeys)))
|
|
904
|
-
return;
|
|
905
|
-
set.add(hashKey(item, allKeys));
|
|
906
|
-
nums++;
|
|
907
|
-
});
|
|
908
|
-
set.clear();
|
|
909
|
-
sum.value = (_d = pageData
|
|
910
|
-
.reduce((lastNum, item) => {
|
|
911
|
-
if (set.has(hashKey(item, allKeys)))
|
|
912
|
-
return lastNum;
|
|
913
|
-
set.add(hashKey(item, allKeys));
|
|
914
|
-
return lastNum.plus(new BigNumber(this.getTableSummaryNumberValue(item[dataIndex])).div(nums));
|
|
915
|
-
}, new BigNumber(0))) === null || _d === void 0 ? void 0 : _d.toString();
|
|
916
|
-
}
|
|
917
|
-
sum.id = dataIndex;
|
|
918
|
-
if (argFun === "avg" || argFun === "groupIavg") {
|
|
919
|
-
sumConfigs["avg"].push(sum);
|
|
920
|
-
avgLen++;
|
|
921
|
-
}
|
|
922
|
-
else
|
|
923
|
-
sumConfigs["avg"].push({ value: "", id: "" });
|
|
924
|
-
if (argFun === "sum" || argFun === "groupIsum") {
|
|
925
|
-
sumConfigs["sum"].push(sum);
|
|
926
|
-
sumLen++;
|
|
927
|
-
}
|
|
928
|
-
else
|
|
929
|
-
sumConfigs["sum"].push({ value: "", id: "" });
|
|
930
|
-
}
|
|
931
|
-
console.log("sumConfigs", sumConfigs, sumLen, avgLen);
|
|
932
|
-
return (React.createElement(React.Fragment, null,
|
|
933
|
-
sumLen === 0 ? (React.createElement(React.Fragment, null)) : (React.createElement(Table.Summary.Row, null, sumConfigs["sum"].map(({ id, value, columnConfig }, idx) => (React.createElement(Table.Summary.Cell, { align: columnConfig === null || columnConfig === void 0 ? void 0 : columnConfig.align, index: idx, className: "zongji" }, value))))),
|
|
934
|
-
avgLen === 0 ? (React.createElement(React.Fragment, null)) : (React.createElement(Table.Summary.Row, null, sumConfigs["avg"].map(({ id, value, columnConfig }, idx) => (React.createElement(Table.Summary.Cell, { align: columnConfig === null || columnConfig === void 0 ? void 0 : columnConfig.align, index: idx, className: "zongji" }, value)))))));
|
|
935
|
-
};
|
|
936
352
|
return (React.createElement(React.Fragment, null,
|
|
937
353
|
viewModels.includes("table") ? (React.createElement(Table, { size: tableProps.size ? tableProps.size : undefined, rowSelection: this.getRowSelection(), columns: current_cols, dataSource: originData, scroll: tableProps.scrollY == -1 || tableProps.scrollY == 0
|
|
938
354
|
? null
|