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.
Files changed (60) hide show
  1. package/lib/controls/entity-select/popover-entity-select.d.ts.map +1 -1
  2. package/lib/controls/entity-select/popover-entity-select.js +12 -11
  3. package/lib/controls/entity-select/popover-entity-select.js.map +1 -1
  4. package/lib/controls/entry-control.d.ts.map +1 -1
  5. package/lib/controls/entry-control.js +8 -0
  6. package/lib/controls/entry-control.js.map +1 -1
  7. package/lib/controls/tree-select/tree-entity-select.d.ts +12 -0
  8. package/lib/controls/tree-select/tree-entity-select.d.ts.map +1 -0
  9. package/lib/controls/tree-select/tree-entity-select.js +86 -0
  10. package/lib/controls/tree-select/tree-entity-select.js.map +1 -0
  11. package/lib/layout/MainPage.js +1 -1
  12. package/lib/module/dtmpl-edit-page.d.ts +1 -0
  13. package/lib/module/dtmpl-edit-page.d.ts.map +1 -1
  14. package/lib/module/dtmpl-edit-page.js.map +1 -1
  15. package/lib/table/act-table.d.ts.map +1 -1
  16. package/lib/table/act-table.js +45 -25
  17. package/lib/table/act-table.js.map +1 -1
  18. package/lib/table/column/column-builder.d.ts.map +1 -1
  19. package/lib/table/column/column-builder.js +3 -3
  20. package/lib/table/column/column-builder.js.map +1 -1
  21. package/lib/table/column/summary-builder.d.ts +39 -0
  22. package/lib/table/column/summary-builder.d.ts.map +1 -0
  23. package/lib/table/column/summary-builder.js +508 -0
  24. package/lib/table/column/summary-builder.js.map +1 -0
  25. package/lib/table/index.css +2 -2
  26. package/lib/table/query-table.d.ts +0 -20
  27. package/lib/table/query-table.d.ts.map +1 -1
  28. package/lib/table/query-table.js +14 -598
  29. package/lib/table/query-table.js.map +1 -1
  30. package/lib/tmpl/control-type-supportor.d.ts.map +1 -1
  31. package/lib/tmpl/control-type-supportor.js +6 -1
  32. package/lib/tmpl/control-type-supportor.js.map +1 -1
  33. package/lib/tmpl/interface.d.ts +0 -6
  34. package/lib/tmpl/interface.d.ts.map +1 -1
  35. package/lib/tmpl/interface.js.map +1 -1
  36. package/lib/tree/tmpl-tree.d.ts +9 -4
  37. package/lib/tree/tmpl-tree.d.ts.map +1 -1
  38. package/lib/tree/tmpl-tree.js +70 -94
  39. package/lib/tree/tmpl-tree.js.map +1 -1
  40. package/lib/tree/tree-node.js +1 -1
  41. package/lib/tree/tree-utils.d.ts +19 -0
  42. package/lib/tree/tree-utils.d.ts.map +1 -1
  43. package/lib/tree/tree-utils.js +128 -0
  44. package/lib/tree/tree-utils.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/aldehyde/controls/entity-select/popover-entity-select.tsx +9 -12
  47. package/src/aldehyde/controls/entry-control.tsx +20 -0
  48. package/src/aldehyde/controls/tree-select/tree-entity-select.tsx +113 -0
  49. package/src/aldehyde/layout/MainPage.tsx +1 -1
  50. package/src/aldehyde/module/dtmpl-edit-page.tsx +1 -0
  51. package/src/aldehyde/table/act-table.tsx +114 -69
  52. package/src/aldehyde/table/column/column-builder.tsx +4 -3
  53. package/src/aldehyde/table/column/summary-builder.tsx +713 -0
  54. package/src/aldehyde/table/index.css +2 -2
  55. package/src/aldehyde/table/query-table.tsx +16 -837
  56. package/src/aldehyde/tmpl/control-type-supportor.tsx +8 -1
  57. package/src/aldehyde/tmpl/interface.tsx +0 -2
  58. package/src/aldehyde/tree/tmpl-tree.tsx +72 -89
  59. package/src/aldehyde/tree/tree-node.tsx +1 -1
  60. package/src/aldehyde/tree/tree-utils.tsx +138 -0
@@ -1,25 +1,22 @@
1
1
  import React from "react";
2
- import { Card, Collapse, Descriptions, List } from "antd";
3
2
  import Table from "./control-table-x-axis-wrapper";
4
3
  import "./index.css";
5
4
  import {
6
5
  DtmplData,
7
6
  PageInfo,
8
7
  QueryData,
9
- SelectedRow, QueryTableProps, ActionRenderProps, FieldConfig
8
+ SelectedRow, QueryTableProps
10
9
  } from "../tmpl/interface";
11
10
  import HcserviceV3 from "../tmpl/hcservice-v3";
12
11
  import Pagination from "./pagination";
13
12
  import { TableRowSelection } from "antd/lib/table/interface";
14
13
  import { SortableContainer, SortableElement } from "react-sortable-hoc";
15
14
  import { arrayMoveImmutable } from "array-move";
16
- import ViewControl from "../controls/view-control";
17
15
  import { LocaleContext } from "../locale/LocaleProvider";
18
- import { BigNumber } from "bignumber.js";
19
16
  import { init, merge, statistic } from "../utils/dsu";
20
17
  import VerticalList from "../list/vertical-list";
18
+ import SummaryBuilder from "./column/summary-builder";
21
19
 
22
- const { Panel } = Collapse;
23
20
  const SortableItem = SortableElement((props) => (
24
21
  <tr className="sortable-item-hover" {...props} />
25
22
  ));
@@ -205,7 +202,6 @@ class QueryTable extends React.PureComponent<QueryTableProps, QueryTableStat> {
205
202
  };
206
203
 
207
204
 
208
-
209
205
  pageTo = async (pageNo: number, pageSize: number) => {
210
206
  const { onChangePage } = this.props;
211
207
  const { virtualEndPageNo } = this.state;
@@ -292,643 +288,6 @@ class QueryTable extends React.PureComponent<QueryTableProps, QueryTableStat> {
292
288
  return ds;
293
289
  };
294
290
 
295
-
296
- getTableSummaryNumberValue(value: "" | string[]) {
297
- if (value === undefined || value === null) return 0;
298
- if (typeof value === "string") return Number(value);
299
- return Number(value[0].split("@R@")[1]);
300
- }
301
-
302
- deepClone(source, hash = new WeakSet()) {
303
- try {
304
- if (
305
- typeof source !== "object" ||
306
- source === null ||
307
- React.isValidElement(source)
308
- ) {
309
- return source;
310
- }
311
- if (hash.has(source)) {
312
- return source;
313
- }
314
-
315
- hash.add(source);
316
- const target = Array.isArray(source) ? [] : {};
317
- Reflect.ownKeys(source).forEach((key) => {
318
- const val = source[key];
319
- if (typeof val === "object" && val != null) {
320
- target[key] = this.deepClone(val, hash);
321
- } else {
322
- target[key] = val;
323
- }
324
- });
325
- return target;
326
- } catch (err) {
327
- console.log("deepclone err", err, source);
328
- }
329
- }
330
-
331
- buildKeys(keys: { title: string; dataKey: string }[]) {
332
- return keys.map((i) => i.title).join("-");
333
- }
334
-
335
- buildColTag(cols, keys = []) {
336
- for (const col of cols) {
337
- if (!col.children) {
338
- col.dataIndex = this.buildKeys([
339
- ...keys,
340
- { dataKey: col._type ? col._type : col.title, title: col.title },
341
- ]);
342
- if (col.keys === undefined)
343
- col.keys = [
344
- ...keys,
345
- { dataKey: col._type ? col._type : col.title, title: col.title },
346
- ];
347
- } else {
348
- this.buildColTag(col.children, [
349
- ...keys,
350
- { dataKey: col._type ? col._type : col.title, title: col.title },
351
- ]);
352
- }
353
- }
354
- }
355
-
356
- getCurCalKeys(cols, keys = []) {
357
- for (const col of cols) {
358
- if (Array.isArray(col.children)) {
359
- this.getCurCalKeys(col.children, keys);
360
- } else {
361
- keys.push({
362
- factIndex: col.keys[col.keys.length - 1],
363
- dataIndex: col.dataIndex,
364
- });
365
- }
366
- }
367
-
368
- return keys;
369
- }
370
-
371
- setSumColKeys(sumCol, sumKeys) {
372
- if (sumKeys.length === 0) return;
373
- if (Array.isArray(sumCol.children)) {
374
- this.setSumColKeys(sumCol.children, sumKeys);
375
- } else {
376
- for (const col of sumCol) {
377
- const factKey = col.keys[col.keys.length - 1].dataKey;
378
- col.sumDataIndex = sumKeys.filter(
379
- ({ factIndex: { dataKey } }) => dataKey === factKey
380
- );
381
- col.keys[col.keys.length - 1].sumDataIndex = col.sumDataIndex.map(
382
- ({ dataIndex }) => dataIndex
383
- );
384
- }
385
- }
386
- }
387
-
388
- handleProSummaryTable(data: any[]) {
389
- const isProSumarryTable = Boolean(
390
- this.props.subtotalXColumn || this.props.subtotalYColumn
391
- );
392
- if (!isProSumarryTable)
393
- return { proSummaryTableColumns: [], proSummaryTableData: [] };
394
-
395
- const { translate } = this.context;
396
-
397
- const { subtotalXColumn, subtotalYColumn, columns: _columns } = this.props;
398
- const columns = _columns;
399
-
400
- for (const column of columns) {
401
- delete column["sorter"];
402
- }
403
-
404
- for (const d of data) {
405
- for (const [k, v] of Object.entries(d)) {
406
- if (v == null || v == "null") {
407
- d[k] = "";
408
- } else if (typeof v === "string" && (v as string)?.includes("@R@")) {
409
- d[k] = (v as string).split("@R@")[1];
410
- }
411
- }
412
- }
413
-
414
- console.log("data", data);
415
- console.log("columns", columns);
416
-
417
- const colMp = {
418
- dimension: [],
419
- fact: [],
420
- others: [
421
- {
422
- dataIndex: "orderInGroup",
423
- title: "orderInGroup",
424
- },
425
- ],
426
- };
427
- const colIdToNameMp = {};
428
- const colNameToIdMp = {};
429
- for (const col of columns) {
430
- colIdToNameMp[col["dataIndex"]] = col["title"];
431
- colNameToIdMp[col["title"]] = col["dataIndex"];
432
- if (col.statColType !== undefined) {
433
- colMp[col.statColType].push(this.deepClone(col));
434
- } else {
435
- if (col.title !== "序号") colMp["others"].push(this.deepClone(col));
436
- }
437
- }
438
- console.log("colIdToNameMp", colIdToNameMp);
439
- console.log("colNameToIdMp", colNameToIdMp);
440
- console.log("colMp", colMp);
441
-
442
- // canReadData
443
- const canReadData = [];
444
- let order = 0;
445
- for (const d of data) {
446
- const item = {};
447
- for (const [k, v] of Object.entries(d)) {
448
- let _v = v;
449
- if (
450
- colMp.fact.findIndex(({ dataIndex }) => dataIndex === k) > -1 &&
451
- v === null
452
- )
453
- _v = 0;
454
- item[colIdToNameMp[k]] = _v;
455
- }
456
- canReadData.push({ ...item, orderInGroup: order++ });
457
- }
458
- console.log("canReadData", canReadData);
459
-
460
- let proSummaryTableColumns = [
461
- ...this.deepClone(colMp.dimension),
462
- ...this.deepClone(colMp.others),
463
- ],
464
- proSummaryTableData = [],
465
- excludeGroupSumData = [];
466
- const cal = colMp.fact[0]?.cal;
467
- const calTxt = cal === "sum" ? translate("小计") : translate("均值");
468
- const calMp = {};
469
- colMp.fact.forEach(({ title, cal }) => (calMp[title] = cal));
470
-
471
- // 计算列
472
- if (
473
- subtotalYColumn &&
474
- Array.isArray(subtotalYColumn) &&
475
- subtotalYColumn.length
476
- ) {
477
- // col
478
- let tnodes = [];
479
-
480
- for (let i = 0; i < subtotalYColumn.length; i++) {
481
- const y = subtotalYColumn[i];
482
- const id = y.id;
483
- const mp = {};
484
- let _tnodes = [];
485
- for (const d of data) mp[d[id]] = colIdToNameMp[id];
486
- for (const [k, v] of Object.entries(mp)) {
487
- const tnode = {
488
- title: k,
489
- _type: v,
490
- children: [...this.deepClone(i === 0 ? colMp.fact : tnodes)],
491
- };
492
- _tnodes.push(tnode);
493
- }
494
-
495
- this.buildColTag(_tnodes);
496
- console.log("_tnodes", JSON.parse(JSON.stringify(_tnodes)));
497
-
498
- const sumCol = {
499
- title: calTxt,
500
- children: [...this.deepClone(colMp.fact)],
501
- TYPE: cal,
502
- };
503
- this.buildColTag([sumCol]);
504
- this.setSumColKeys(sumCol, this.getCurCalKeys(_tnodes));
505
- _tnodes.unshift(sumCol);
506
-
507
- tnodes = _tnodes;
508
- proSummaryTableColumns.splice(
509
- proSummaryTableColumns.findIndex((item) => item.dataIndex === id),
510
- 1
511
- );
512
- }
513
- proSummaryTableColumns.push(...tnodes);
514
- } else {
515
- proSummaryTableColumns.push(...colMp.fact);
516
- }
517
-
518
- // buildData
519
- this.buildColTag(proSummaryTableColumns);
520
-
521
- // 处理行
522
- const rowMp = {};
523
- const rowKey = [];
524
- for (const col of proSummaryTableColumns) {
525
- if (Array.isArray(col.keys) && col.keys.length === 1) rowKey.push(col);
526
- }
527
- console.log("rowKey", rowKey);
528
-
529
- for (const d of canReadData) {
530
- let t: any = rowMp;
531
- for (let i = 0; i < rowKey.length; i++) {
532
- const key = rowKey[i].title;
533
- if (t[d[key]] === undefined) {
534
- if (i !== rowKey.length - 1) t[d[key]] = {};
535
- else t[d[key]] = [];
536
- }
537
- t = t[d[key]];
538
- }
539
- if (Array.isArray(t)) t.push(d);
540
- }
541
-
542
- // 行数据处理完毕
543
- console.log("rowMp", rowMp);
544
-
545
- // 处理列
546
- const colKey = [];
547
- const colKeyTitle = this.flatSummaryCol(proSummaryTableColumns);
548
- for (const col of proSummaryTableColumns) {
549
- if (
550
- (col.statColType === "fact" || Array.isArray(col.children)) &&
551
- col.TYPE === undefined
552
- ) {
553
- colKey.push(col);
554
- }
555
- }
556
- const flatSummaryColTitle = this.flatSummaryCol(colKey);
557
- const flatSummaryRowTitle = this.flatSummaryCol(rowKey);
558
- const flatSummaryCalTitle = this.flatSummaryCol(
559
- proSummaryTableColumns.filter(({ TYPE }) => TYPE !== undefined)
560
- );
561
- console.log("colKey", colKey);
562
- console.log("colKeyTitle", colKeyTitle);
563
- console.log("flatSummaryColTitle", flatSummaryColTitle);
564
- console.log("flatSummaryRowTitle", flatSummaryRowTitle);
565
- console.log("flatSummaryCalTitle", flatSummaryCalTitle);
566
-
567
- proSummaryTableData = this.handleColData(
568
- rowMp,
569
- flatSummaryRowTitle,
570
- flatSummaryColTitle,
571
- flatSummaryCalTitle,
572
- cal
573
- );
574
-
575
- excludeGroupSumData = this.deepClone(proSummaryTableData);
576
- console.log("excludeGroupSumData", excludeGroupSumData);
577
-
578
- if (
579
- subtotalXColumn &&
580
- Array.isArray(subtotalXColumn) &&
581
- subtotalXColumn.length
582
- ) {
583
- const sortKeys = subtotalXColumn.map(({ id }) => colIdToNameMp[id]);
584
-
585
- const rowSumMp = this.buildRowMp(proSummaryTableData, sortKeys);
586
- console.log("rowSumMp", rowSumMp);
587
-
588
- const calRowKeys = [
589
- ...flatSummaryCalTitle,
590
- ...flatSummaryColTitle,
591
- ].map((i) => this.buildKeys(i));
592
- console.log("calRowKeys", calRowKeys);
593
-
594
- proSummaryTableData = this.handleRowData(
595
- rowSumMp,
596
- calRowKeys,
597
- calMp,
598
- calTxt,
599
- sortKeys[0]
600
- );
601
- }
602
-
603
- // 序号
604
- if (columns[0].title === "序号") {
605
- const col: any = {
606
- dataIndex: "序号",
607
- title: "序号",
608
- width: 60,
609
- order: -1,
610
- };
611
- if (columns[0].colWidth) {
612
- col.width = columns[0].colWidth;
613
- }
614
- proSummaryTableColumns.unshift(col);
615
- proSummaryTableData.forEach((_, idx) => {
616
- _["序号"] = idx + 1;
617
- });
618
- }
619
-
620
- // 做总计
621
- if (
622
- this.props.summaryConfigs &&
623
- this.props.summaryConfigs?.length !== 0 &&
624
- flatSummaryRowTitle.length &&
625
- proSummaryTableData.length
626
- ) {
627
- const calkeys = [
628
- ...flatSummaryCalTitle,
629
- ...flatSummaryColTitle,
630
- ].map((i) => this.buildKeys(i));
631
-
632
- const sumData = {
633
- [proSummaryTableColumns[0]?.dataIndex]:
634
- cal === "sum" ? translate("${合计}") : translate("${均值}"),
635
- _type: calMp,
636
- _calRange: "all",
637
- };
638
-
639
- for (const key of calkeys) {
640
- if (cal === "sum")
641
- sumData[key] = excludeGroupSumData.reduce(
642
- (last, d) => last.plus(BigNumber(d[key])),
643
- BigNumber(0)
644
- );
645
- if (cal === "avg")
646
- sumData[key] = excludeGroupSumData.reduce(
647
- (last, d) =>
648
- last.plus(BigNumber(d[key]).div(excludeGroupSumData.length)),
649
- BigNumber(0)
650
- );
651
-
652
- const hash = (...args) => args.join("-");
653
- const hashKey = (data, keys) => hash(...keys.map((key) => data[key]));
654
- if (calMp[key] === "groupIsum") {
655
- const allKeys = this.props.groupIColumns?.map(({ title }) => title);
656
- const set = new Set();
657
-
658
- sumData[key] = excludeGroupSumData.reduce((lastNum, item) => {
659
- if (set.has(hashKey(item, allKeys))) return lastNum;
660
- set.add(hashKey(item, allKeys));
661
- return lastNum.plus(
662
- new BigNumber(this.getTableSummaryNumberValue(item[key]))
663
- );
664
- }, new BigNumber(0));
665
- }
666
-
667
- if (calMp[key] === "groupIavg") {
668
- const set = new Set();
669
- let nums = 0;
670
- const allKeys = this.props.groupIColumns?.map(({ title }) => title);
671
-
672
- data.forEach((item) => {
673
- if (set.has(hashKey(item, allKeys))) return;
674
- set.add(hashKey(item, allKeys));
675
-
676
- nums++;
677
- });
678
-
679
- set.clear();
680
-
681
- sumData[key] = excludeGroupSumData.reduce((lastNum, item) => {
682
- if (set.has(hashKey(item, allKeys))) return lastNum;
683
- set.add(hashKey(item, allKeys));
684
- return lastNum.plus(
685
- new BigNumber(this.getTableSummaryNumberValue(item[key])).div(
686
- nums
687
- )
688
- );
689
- }, new BigNumber(0));
690
- }
691
-
692
- sumData[key] = sumData[key]?.toString();
693
- }
694
- proSummaryTableData.push(sumData);
695
- }
696
-
697
- // 给小计和总计染色
698
- this.stain(proSummaryTableColumns);
699
-
700
- // 删除默认数据在组内顺序字段
701
- proSummaryTableColumns.splice(
702
- proSummaryTableColumns.findIndex(
703
- ({ dataIndex }) => dataIndex === "orderInGroup"
704
- ),
705
- 1
706
- );
707
-
708
- proSummaryTableData.forEach((item) => delete item.orderInGroup);
709
-
710
- // 排序
711
- proSummaryTableColumns = proSummaryTableColumns.sort((a, b) => {
712
- if (a.order === undefined && b.order === undefined) return 0;
713
- if (a.order === undefined) return 1;
714
- if (b.order === undefined) return -1;
715
- return a.order < b.order ? -1 : 1;
716
- });
717
-
718
- console.log("proSummaryTableColumns", proSummaryTableColumns);
719
- console.log("proSummaryTableData", proSummaryTableData);
720
-
721
- return { proSummaryTableColumns, proSummaryTableData };
722
- }
723
-
724
- flatSummaryCol(arr, res = []) {
725
- for (const i of arr) {
726
- if (!i.children) res.push(i.keys);
727
- else this.flatSummaryCol(i.children, res);
728
- }
729
-
730
- return res;
731
- }
732
-
733
- handleColData(
734
- rowMp,
735
- flatSummaryRowTitle,
736
- flatSummaryColTitle,
737
- flatSummaryCalTitle,
738
- cal,
739
- idx = 0,
740
- data = {},
741
- list = []
742
- ) {
743
- if (Array.isArray(rowMp)) {
744
- for (const col of flatSummaryColTitle) {
745
- const key = this.buildKeys(col);
746
- const colTarget = [];
747
- const preConditions = col.slice(0, col.length - 1);
748
- const targetKey = col.slice(col.length - 1)[0].title;
749
- for (const d of rowMp) {
750
- if (
751
- preConditions.every(({ dataKey, title }) => d[dataKey] === title)
752
- ) {
753
- colTarget.push(d);
754
- }
755
- }
756
-
757
- if (data[key] === undefined || data[key] == "") {
758
- data[key] = BigNumber(0);
759
- }
760
- if (cal === "sum")
761
- data[key] = colTarget.reduce(
762
- (last, d) => last.plus(BigNumber(d[targetKey])),
763
- BigNumber(0)
764
- );
765
- if (cal === "avg")
766
- data[key] = colTarget.reduce(
767
- (last, d) =>
768
- last.plus(BigNumber(d[targetKey]).div(colTarget.length)),
769
- BigNumber(0)
770
- );
771
- data[key] =
772
- data[key]?.toString() == "NaN" ? "0" : data[key]?.toString();
773
- }
774
-
775
- for (const calCol of flatSummaryCalTitle) {
776
- const key = this.buildKeys(calCol);
777
- const sumDataIndex = calCol[calCol.length - 1].sumDataIndex;
778
-
779
- if (data[key] === undefined || data[key] == "")
780
- data[key] = BigNumber(0);
781
- if (cal === "sum")
782
- data[key] = sumDataIndex.reduce(
783
- (last, dataKey) => last.plus(BigNumber(data[dataKey])),
784
- BigNumber(0)
785
- );
786
- if (cal === "avg")
787
- data[key] = sumDataIndex.reduce(
788
- (last, dataKey) =>
789
- last.plus(BigNumber(data[dataKey]).div(sumDataIndex.length)),
790
- BigNumber(0)
791
- );
792
- data[key] = data[key]?.toString();
793
- }
794
- list.push(data);
795
- } else {
796
- for (const [k, v] of Object.entries(rowMp)) {
797
- const dataKey = flatSummaryRowTitle[idx][0].dataKey;
798
- data[dataKey] = k;
799
- this.handleColData(
800
- v,
801
- flatSummaryRowTitle,
802
- flatSummaryColTitle,
803
- flatSummaryCalTitle,
804
- cal,
805
- idx + 1,
806
- this.deepClone(data),
807
- list
808
- );
809
- }
810
- }
811
-
812
- return list;
813
- }
814
-
815
- buildRowMp(data, sortKeys, idx = 0, mp = {}) {
816
- if (idx >= sortKeys.length) return data;
817
-
818
- const dataKey = sortKeys[idx];
819
-
820
- for (const d of data) {
821
- if (mp[d[dataKey]] === undefined) mp[d[dataKey]] = [];
822
- mp[d[dataKey]].push(d);
823
- }
824
-
825
- for (const [k, v] of Object.entries(mp)) {
826
- mp[k] = this.buildRowMp(v, sortKeys, idx + 1);
827
- }
828
-
829
- return mp;
830
- }
831
-
832
- handleRowData(
833
- data,
834
- calKeys,
835
- calMp: { [key: string]: string },
836
- calTxt,
837
- calTxtKey,
838
- res = []
839
- ) {
840
- for (const [k, v] of Object.entries(data)) {
841
- if (Array.isArray(v)) {
842
- const sumData = {
843
- [calTxtKey]: calTxt,
844
- _type: calMp,
845
- _calRange: "small",
846
- };
847
-
848
- for (const calKey of calKeys) {
849
- if (calMp[calKey] === "sum")
850
- sumData[calKey] = v.reduce(
851
- (last, d) => last.plus(BigNumber(d[calKey])),
852
- BigNumber(0)
853
- );
854
- if (calMp[calKey] === "avg")
855
- sumData[calKey] = v.reduce(
856
- (last, d) => last.plus(BigNumber(d[calKey]).div(v.length)),
857
- BigNumber(0)
858
- );
859
-
860
- const hash = (...args) => args.join("-");
861
- const hashKey = (data, keys) => hash(...keys.map((key) => data[key]));
862
- if (calMp[calKey] === "groupIsum") {
863
- const allKeys = this.props.groupIColumns?.map(({ title }) => title);
864
- const set = new Set();
865
-
866
- sumData[calKey] = v.reduce((lastNum, item) => {
867
- if (set.has(hashKey(item, allKeys))) return lastNum;
868
- set.add(hashKey(item, allKeys));
869
- return lastNum.plus(
870
- new BigNumber(this.getTableSummaryNumberValue(item[calKey]))
871
- );
872
- }, new BigNumber(0));
873
- }
874
-
875
- if (calMp[calKey] === "groupIavg") {
876
- const set = new Set();
877
- let nums = 0;
878
- const allKeys = this.props.groupIColumns?.map(({ title }) => title);
879
-
880
- data.forEach((item) => {
881
- if (set.has(hashKey(item, allKeys))) return;
882
- set.add(hashKey(item, allKeys));
883
-
884
- nums++;
885
- });
886
-
887
- set.clear();
888
-
889
- sumData[calKey] = v.reduce((lastNum, item) => {
890
- if (set.has(hashKey(item, allKeys))) return lastNum;
891
- set.add(hashKey(item, allKeys));
892
- return lastNum.plus(
893
- new BigNumber(
894
- this.getTableSummaryNumberValue(item[calKey])
895
- ).div(nums)
896
- );
897
- }, new BigNumber(0));
898
- }
899
-
900
- sumData[calKey] = sumData[calKey]?.toString();
901
- }
902
-
903
- v.sort((a, b) =>
904
- Number(a.orderInGroup) < Number(b.orderInGroup) ? -1 : 1
905
- );
906
- res.push(...v, sumData);
907
- } else {
908
- this.handleRowData(v, calKeys, calMp, calTxt, calTxtKey, res);
909
- }
910
- }
911
-
912
- return res;
913
- }
914
-
915
- stain(cols) {
916
- for (const col of cols) {
917
- if (Array.isArray(col.children)) {
918
- this.stain(col.children);
919
- } else {
920
- col.render = function(text, record, index) {
921
- let className = "";
922
- if (record._type !== undefined) {
923
- if (record._calRange === "small") className = "xiaoji";
924
- else className = "zongji";
925
- }
926
- return <div className={className}>{text}</div>;
927
- };
928
- }
929
- }
930
- }
931
-
932
291
  mergeRowInCol(data, rowIdx, colIdx, mergeMp, calNum) {
933
292
  const idx = rowIdx * calNum + colIdx;
934
293
  // console.log(rowIdx, colIdx, mergeMp[idx]);
@@ -983,7 +342,6 @@ class QueryTable extends React.PureComponent<QueryTableProps, QueryTableStat> {
983
342
  viewModels,
984
343
  summaryConfigs,
985
344
  subtotalXColumn,
986
- subtotalYColumn,
987
345
  tableProps,
988
346
  groupIColumns,
989
347
  hiddenRowCodes,
@@ -992,14 +350,16 @@ class QueryTable extends React.PureComponent<QueryTableProps, QueryTableStat> {
992
350
  } = this.props;
993
351
  //debugger
994
352
  const { touchEnd, total, loading, virtualEndPageNo,dataSource } = this.state;
995
- const { translate } = this.context;
996
-
997
- const isProSumarryTable = Boolean(subtotalXColumn || subtotalYColumn);
998
353
 
354
+ const isProSumarryTable = Boolean(subtotalXColumn );
355
+ const { translate } = this.context;
999
356
  const {
1000
357
  proSummaryTableColumns,
1001
358
  proSummaryTableData,
1002
- } = this.handleProSummaryTable(this.getUnHidenDataSource());
359
+ } =SummaryBuilder.handleProSummaryTable({
360
+ subtotalXColumn,columns,data:this.getUnHidenDataSource(),
361
+ translate,groupIColumns
362
+ });
1003
363
 
1004
364
  let current_cols = isProSumarryTable
1005
365
  ? proSummaryTableColumns
@@ -1012,9 +372,16 @@ class QueryTable extends React.PureComponent<QueryTableProps, QueryTableStat> {
1012
372
  table_x = table_x + (c.width ? c.width : 140);
1013
373
  });
1014
374
 
375
+ let dat=this.getUnHidenDataSource();
1015
376
  const originData = isProSumarryTable
1016
377
  ? proSummaryTableData
1017
- : this.getUnHidenDataSource();
378
+ : dat;
379
+
380
+ let summary=(pageData1) => {
381
+ return SummaryBuilder.summary({translate,summaryConfigs,
382
+ pageData: dat,columns,
383
+ rowSelection:this.getRowSelection(),groupIColumns});
384
+ }
1018
385
 
1019
386
  console.log("%crender data: ", "color: red", originData);
1020
387
  console.log("%crender col: ", "color: red", current_cols);
@@ -1085,194 +452,6 @@ class QueryTable extends React.PureComponent<QueryTableProps, QueryTableStat> {
1085
452
  this.mergeRowInCol(_, rowIdx, colIdx, mergeMp, current_cols.length))
1086
453
  );
1087
454
 
1088
- // current_cols[10].onCell = (_, rowIdx) =>
1089
- // this.mergeRowInCol(_, rowIdx, 10, mergeMp, current_cols.length);
1090
-
1091
- let summary=(pageData) => {
1092
- if (
1093
- !summaryConfigs ||
1094
- summaryConfigs?.length === 0 ||
1095
- pageData.length === 0
1096
- )
1097
- return <></>;
1098
-
1099
- const columns = isProSumarryTable
1100
- ? proSummaryTableColumns
1101
- : this.props.columns;
1102
-
1103
- const sumConfigs: {
1104
- sum: { value: string; id: string; columnConfig?: any }[];
1105
- avg: { value: string; id: string; columnConfig?: any }[];
1106
- } = { sum: [], avg: [] };
1107
-
1108
- if (this.getRowSelection()) {
1109
- sumConfigs["avg"].push({
1110
- value: "",
1111
- id: "",
1112
- columnConfig: { align: "center" },
1113
- });
1114
- sumConfigs["sum"].push({
1115
- value: "",
1116
- id: "",
1117
- columnConfig: { align: "center" },
1118
- });
1119
- }
1120
-
1121
- sumConfigs["sum"].push({
1122
- value: translate("${合计}"),
1123
- id: "title",
1124
- columnConfig: { align: "center" },
1125
- });
1126
- sumConfigs["avg"].push({
1127
- value: translate("${均值}"),
1128
- id: "title",
1129
- columnConfig: { align: "center" },
1130
- });
1131
-
1132
- let sumLen = 0,
1133
- avgLen = 0;
1134
-
1135
- for (let i = 0; i < columns.length; i++) {
1136
- const idx = i,
1137
- dataIndex = columns[i].dataIndex;
1138
- if (idx === 0) continue;
1139
- const sum = { value: "", id: "", columnConfig: columns[i] };
1140
- const sumConfigIdx = summaryConfigs.findIndex(
1141
- ({ id }) => id === dataIndex
1142
- );
1143
- if (sumConfigIdx === -1) {
1144
- sumConfigs["sum"].push(sum);
1145
- sumConfigs["avg"].push(sum);
1146
- continue;
1147
- }
1148
- const argFun = summaryConfigs[sumConfigIdx].aggFunc;
1149
- if (argFun === "sum")
1150
- sum.value = pageData
1151
- .reduce(
1152
- (lastNum, item) =>
1153
- lastNum.plus(
1154
- new BigNumber(
1155
- this.getTableSummaryNumberValue(item[dataIndex])
1156
- )
1157
- ),
1158
- new BigNumber(0)
1159
- )
1160
- ?.toString();
1161
- if (argFun === "avg")
1162
- sum.value = pageData
1163
- .reduce(
1164
- (lastNum, item) =>
1165
- lastNum.plus(
1166
- new BigNumber(
1167
- this.getTableSummaryNumberValue(item[dataIndex])
1168
- ).div(pageData.length)
1169
- ),
1170
- new BigNumber(0)
1171
- )
1172
- ?.toString();
1173
-
1174
- const hash = (...args) => args.join("-");
1175
- const hashKey = (data, keys) =>
1176
- hash(...keys.map((key) => data[key]));
1177
-
1178
- if (argFun === "groupIsum") {
1179
- const allKeys = groupIColumns?.map(({ id }) => id);
1180
- const set = new Set();
1181
-
1182
- sum.value = pageData
1183
- .reduce((lastNum, item) => {
1184
- if (set.has(hashKey(item, allKeys))) return lastNum;
1185
- set.add(hashKey(item, allKeys));
1186
- return lastNum.plus(
1187
- new BigNumber(
1188
- this.getTableSummaryNumberValue(item[dataIndex])
1189
- )
1190
- );
1191
- }, new BigNumber(0))
1192
- ?.toString();
1193
- }
1194
-
1195
- if (argFun === "groupIavg") {
1196
- const set = new Set();
1197
- let nums = 0;
1198
- const allKeys = groupIColumns?.map(({ id }) => id);
1199
-
1200
- pageData.forEach((item) => {
1201
- if (set.has(hashKey(item, allKeys))) return;
1202
- set.add(hashKey(item, allKeys));
1203
-
1204
- nums++;
1205
- });
1206
-
1207
- set.clear();
1208
-
1209
- sum.value = pageData
1210
- .reduce((lastNum, item) => {
1211
- if (set.has(hashKey(item, allKeys))) return lastNum;
1212
- set.add(hashKey(item, allKeys));
1213
- return lastNum.plus(
1214
- new BigNumber(
1215
- this.getTableSummaryNumberValue(item[dataIndex])
1216
- ).div(nums)
1217
- );
1218
- }, new BigNumber(0))
1219
- ?.toString();
1220
- }
1221
-
1222
- sum.id = dataIndex;
1223
- if (argFun === "avg" || argFun === "groupIavg") {
1224
- sumConfigs["avg"].push(sum);
1225
- avgLen++;
1226
- } else sumConfigs["avg"].push({ value: "", id: "" });
1227
-
1228
- if (argFun === "sum" || argFun === "groupIsum") {
1229
- sumConfigs["sum"].push(sum);
1230
- sumLen++;
1231
- } else sumConfigs["sum"].push({ value: "", id: "" });
1232
- }
1233
-
1234
- console.log("sumConfigs", sumConfigs, sumLen, avgLen);
1235
-
1236
- return (
1237
- <>
1238
- {sumLen === 0 ? (
1239
- <></>
1240
- ) : (
1241
- <Table.Summary.Row>
1242
- {sumConfigs["sum"].map(
1243
- ({ id, value, columnConfig }, idx) => (
1244
- <Table.Summary.Cell
1245
- align={columnConfig?.align}
1246
- index={idx}
1247
- className="zongji"
1248
- >
1249
- {value}
1250
- </Table.Summary.Cell>
1251
- )
1252
- )}
1253
- </Table.Summary.Row>
1254
- )}
1255
- {avgLen === 0 ? (
1256
- <></>
1257
- ) : (
1258
- <Table.Summary.Row>
1259
- {sumConfigs["avg"].map(
1260
- ({ id, value, columnConfig }, idx) => (
1261
- <Table.Summary.Cell
1262
- align={columnConfig?.align}
1263
- index={idx}
1264
- className="zongji"
1265
- >
1266
- {value}
1267
- </Table.Summary.Cell>
1268
- )
1269
- )}
1270
- </Table.Summary.Row>
1271
- )}
1272
- </>
1273
- );
1274
- }
1275
-
1276
455
  return (
1277
456
  <>
1278
457
  {viewModels.includes("table") ? (