aldehyde 0.2.144 → 0.2.145

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 (39) hide show
  1. package/lib/controls/entity-select/entity-select.d.ts.map +1 -1
  2. package/lib/controls/entity-select/entity-select.js +1 -3
  3. package/lib/controls/entity-select/entity-select.js.map +1 -1
  4. package/lib/controls/entry-control.js +3 -3
  5. package/lib/controls/entry-control.js.map +1 -1
  6. package/lib/detail/edit/dtmpl-edit.d.ts.map +1 -1
  7. package/lib/detail/edit/dtmpl-edit.js +11 -1
  8. package/lib/detail/edit/dtmpl-edit.js.map +1 -1
  9. package/lib/detail/view/act-dtmpl-view.d.ts.map +1 -1
  10. package/lib/detail/view/act-dtmpl-view.js.map +1 -1
  11. package/lib/module/dtmpl-edit-card.d.ts.map +1 -1
  12. package/lib/module/dtmpl-edit-card.js +0 -1
  13. package/lib/module/dtmpl-edit-card.js.map +1 -1
  14. package/lib/module/dtmpl-edit-page.d.ts.map +1 -1
  15. package/lib/module/dtmpl-edit-page.js +12 -1
  16. package/lib/module/dtmpl-edit-page.js.map +1 -1
  17. package/lib/module/embed-dtmpl-edit-page.d.ts.map +1 -1
  18. package/lib/module/embed-dtmpl-edit-page.js +11 -1
  19. package/lib/module/embed-dtmpl-edit-page.js.map +1 -1
  20. package/lib/table/act-table.d.ts.map +1 -1
  21. package/lib/table/act-table.js +24 -19
  22. package/lib/table/act-table.js.map +1 -1
  23. package/lib/table/query-table.d.ts +3 -0
  24. package/lib/table/query-table.d.ts.map +1 -1
  25. package/lib/table/query-table.js +61 -26
  26. package/lib/table/query-table.js.map +1 -1
  27. package/lib/tmpl/interface.d.ts +5 -1
  28. package/lib/tmpl/interface.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/aldehyde/controls/entity-select/entity-select.tsx +1 -3
  31. package/src/aldehyde/controls/entry-control.tsx +3 -3
  32. package/src/aldehyde/detail/edit/dtmpl-edit.tsx +9 -1
  33. package/src/aldehyde/detail/view/act-dtmpl-view.tsx +1 -0
  34. package/src/aldehyde/module/dtmpl-edit-card.tsx +0 -1
  35. package/src/aldehyde/module/dtmpl-edit-page.tsx +10 -2
  36. package/src/aldehyde/module/embed-dtmpl-edit-page.tsx +11 -1
  37. package/src/aldehyde/table/act-table.tsx +66 -45
  38. package/src/aldehyde/table/query-table.tsx +1063 -1010
  39. package/src/aldehyde/tmpl/interface.tsx +16 -13
@@ -1,1097 +1,1150 @@
1
- import React, { Children } from "react";
2
- import { Card, Collapse, Descriptions, List } from "antd";
1
+ import React, {Children} from "react";
2
+ import {Card, Collapse, Descriptions, List} from "antd";
3
3
  import Table from "./control-table-x-axis-wrapper";
4
4
  import "./index.css";
5
5
  import {
6
- ActTableViewModel,
7
- ColumnConfig,
8
- DtmplData,
9
- FieldConfig,
10
- PageInfo,
11
- QueryData,
12
- QueryKey,
13
- SelectedRow,
6
+ ActTableViewModel,
7
+ ColumnConfig,
8
+ DtmplData,
9
+ FieldConfig,
10
+ PageInfo,
11
+ QueryData,
12
+ QueryKey,
13
+ SelectedRow,
14
14
  } from "../tmpl/interface";
15
15
  import HcserviceV3 from "../tmpl/hcservice-v3";
16
16
  import Pagination from "./pagination";
17
- import { TableRowSelection } from "antd/lib/table/interface";
18
- import { SortableContainer, SortableElement } from "react-sortable-hoc";
19
- import { arrayMoveImmutable } from "array-move";
17
+ import {TableRowSelection} from "antd/lib/table/interface";
18
+ import {SortableContainer, SortableElement} from "react-sortable-hoc";
19
+ import {arrayMoveImmutable} from "array-move";
20
20
  import ViewControl from "../controls/view-control";
21
21
  import Scrollbars from "react-custom-scrollbars";
22
- import { LocaleContext } from "../locale/LocaleProvider";
23
- import { BigNumber } from "bignumber.js";
22
+ import {LocaleContext} from "../locale/LocaleProvider";
23
+ import {BigNumber} from "bignumber.js";
24
24
  import Column from "antd/es/table/Column";
25
- import { ColumnsType } from "antd/es/table";
26
- const { Panel } = Collapse;
25
+ import {ColumnsType} from "antd/es/table";
26
+
27
+ const {Panel} = Collapse;
27
28
  const SortableItem = SortableElement((props) => <tr {...props} />);
28
29
  const SortableBody = SortableContainer((props) => <tbody {...props} />);
29
30
 
30
31
  interface CacheData {
31
- dataSource: object[];
32
- pageInfo: PageInfo;
32
+ dataSource: object[];
33
+ pageInfo: PageInfo;
33
34
  }
34
35
 
35
36
  interface QueryTableProps {
36
- viewModels?: ActTableViewModel[];
37
- // defaultPageSize?: number;
38
- pageInfo: {
39
- pageNo: number;
40
- pageSize: number;
41
- };
42
- tableProps?: {
43
- size?: "small" | "middle" | "large";
44
- clickDisplayTotal?: boolean;
45
- scrollY?: number;
46
- };
47
- primaryColumn?: ColumnConfig;
48
- columns: any[];
49
- serverKey?: string;
50
- queryKey: QueryKey;
51
- onChangePage: (pageNo: number, pageSize: number) => void;
52
- onChangeRowSelection?: (
53
- selectedRows: SelectedRow[],
54
- selectedDatas: DtmplData[],
55
- allRowKeys: string[]
56
- ) => void;
57
- maxSelectedRows?: number;
58
- selectedRows?: SelectedRow[];
59
- hiddenRowCodes?: string[];
60
- viewModel?: string;
61
- columnConfigs?: FieldConfig[];
62
- summaryConfigs?: { id: string; aggFunc: "sum" | "avg" |"groupIsum" |"groupIavg" }[];
63
- subtotalXColumn?: { id: string }[];
64
- subtotalYColumn?: { id: string }[];
37
+ viewModels?: ActTableViewModel[];
38
+ // defaultPageSize?: number;
39
+ pageInfo: {
40
+ pageNo: number;
41
+ pageSize: number;
42
+ };
43
+ tableProps?: {
44
+ size?: "small" | "middle" | "large";
45
+ clickDisplayTotal?: boolean;
46
+ scrollY?: number;
47
+ };
48
+ primaryColumn?: ColumnConfig;
49
+ columns: any[];
50
+ serverKey?: string;
51
+ queryKey: QueryKey;
52
+ onChangePage: (pageNo: number, pageSize: number) => void;
53
+ onChangeRowSelection?: (
54
+ selectedRows: SelectedRow[],
55
+ selectedDatas: DtmplData[],
56
+ allRowKeys: string[]
57
+ ) => void;
58
+ maxSelectedRows?: number;
59
+ selectedRows?: SelectedRow[];
60
+ hiddenRowCodes?: string[];
61
+ viewModel?: string;
62
+ columnConfigs?: FieldConfig[];
63
+ summaryConfigs?: {
64
+ id: string;
65
+ aggFunc: "sum" | "avg" | "groupIsum" | "groupIavg";
66
+ }[];
67
+ subtotalXColumn?: { id: string }[];
68
+ subtotalYColumn?: { id: string }[];
69
+ groupIColumns?: { id: string }[]; // 组间合计key
65
70
  }
66
71
 
67
72
  interface QueryTableStat {
68
- queryDataCache?: Map<string, CacheData>;
69
- virtualEndPageNo?: number;
70
- dataSource?: object[];
71
- loading?: boolean;
72
- touchEnd?: boolean;
73
- total?: number;
73
+ queryDataCache?: Map<string, CacheData>;
74
+ virtualEndPageNo?: number;
75
+ dataSource?: object[];
76
+ loading?: boolean;
77
+ touchEnd?: boolean;
78
+ total?: number;
74
79
  }
75
80
 
76
81
  class QueryTable extends React.PureComponent<QueryTableProps, QueryTableStat> {
77
- static defaultProps = {
78
- pageInfo: {
79
- pageNo: 1,
80
- pageSize: 10,
81
- virtualEndPageNo: undefined,
82
- },
83
- tableProps: {
84
- size: "small",
85
- clickDisplayTotal: false,
86
- scrollY: 500,
87
- },
88
- hiddenRowCodes: [],
89
- selectedRows: [],
90
- viewModels: ["table"],
91
- summaryConfigs: [],
92
- };
93
-
94
- state = {
95
- queryDataCache: undefined,
96
- virtualEndPageNo: undefined,
97
- dataSource: undefined,
98
- loading: true,
99
- touchEnd: undefined,
100
- total: undefined,
101
- };
102
-
103
- static contextType = LocaleContext;
104
- context: React.ContextType<typeof LocaleContext>;
105
-
106
- async componentDidMount() {
107
- const { queryKey, pageInfo } = this.props;
108
- // let pageInfo = {
109
- // pageNo: 1,
110
- // pageSize: defaultPageSize ? defaultPageSize : 10,
111
- // virtualEndPageNo: undefined,
112
- // }
113
- if (queryKey) {
114
- await this.loadData(queryKey.key, pageInfo);
115
- }
116
- }
117
-
118
- componentWillUnmount() {
119
- this.setState = () => false;
120
- }
121
-
122
- async componentDidUpdate(prevProps) {
123
- const { queryKey: preQueryKey, pageInfo: prePageInfo } = prevProps;
124
- const { queryKey, pageInfo } = this.props;
125
- const { total } = this.state;
126
- if (queryKey) {
127
- if (preQueryKey?.key != queryKey.key) {
128
- await this.loadData(queryKey.key, pageInfo, true);
129
- } else if (
130
- prePageInfo?.pageNo != pageInfo.pageNo ||
131
- prePageInfo?.pageSize != pageInfo.pageSize
132
- ) {
133
- await this.loadData(queryKey.key, pageInfo, false);
134
- }
135
- }
136
- }
137
-
138
- DraggableContainer = (props) => (
139
- <SortableBody
140
- useDragHandle
141
- disableAutoscroll
142
- helperClass="row-dragging"
143
- onSortEnd={this.onSortEnd}
144
- {...props}
145
- />
146
- );
147
-
148
- DraggableBodyRow = ({ className, style, ...restProps }) => {
149
- const { dataSource } = this.state;
150
- if (dataSource) {
151
- const index = dataSource.findIndex(
152
- (x) => x.key === restProps["data-row-key"]
153
- );
154
- return <SortableItem key={index} index={index} {...restProps} />;
155
- } else {
156
- return <></>;
157
- }
158
- };
159
-
160
- onSortEnd = ({ oldIndex, newIndex }) => {
161
- const { dataSource } = this.state;
162
- if (oldIndex !== newIndex) {
163
- const newData = arrayMoveImmutable(
164
- [].concat(dataSource),
165
- oldIndex,
166
- newIndex
167
- ).filter((el) => !!el);
168
- //console.log('Sorted items: ', newData);
169
- this.setState({ dataSource: newData });
170
- }
171
- };
172
-
173
- loadData = async (
174
- queryKey: string,
175
- pageInfo: PageInfo,
176
- cleanCache?: boolean
177
- ) => {
178
- this.setState({
179
- loading: true,
180
- });
181
- let { queryDataCache } = this.state;
182
-
183
- let { serverKey, tableProps } = this.props;
184
- let queryCache: Map<string, CacheData>;
185
- if (cleanCache || !queryDataCache) {
186
- queryCache = new Map<string, CacheData>();
187
- this.setState({ total: undefined });
188
- } else {
189
- queryCache = queryDataCache;
190
- }
191
- if (queryCache.has(pageInfo?.pageNo + "_" + pageInfo?.pageSize)) {
192
- let cacheData = queryCache.get(pageInfo?.pageNo + "_" + pageInfo?.pageSize);
193
- this.setState({
194
- dataSource: cacheData.dataSource,
195
- virtualEndPageNo: cacheData.pageInfo.virtualEndPageNo,
196
- loading: false,
197
- });
198
- } else {
199
- let queryData: QueryData = await HcserviceV3.requestQueryData(
200
- serverKey,
201
- queryKey,
202
- pageInfo
203
- );
204
- let dataSource: object[] = [];
205
- pageInfo = queryData.pageInfo;
206
- if(queryData.entities){
207
- queryData.entities.forEach((item, index) => {
208
- let row = {
209
- key: item.code,
210
- code: item.code, //增加code,为了删除操作
211
- ...item.fieldMap,
212
- index,
213
- };
214
- dataSource.push(row);
215
- });
216
- }
217
-
218
- let touchEnd = queryData.touchEnd;
219
- //缓存数据
220
- queryCache.set(pageInfo?.pageNo + "_" + pageInfo?.pageSize, {
221
- dataSource,
222
- pageInfo,
223
- });
224
- this.setState({
225
- dataSource,
226
- virtualEndPageNo: pageInfo.virtualEndPageNo,
227
- queryDataCache: queryCache,
228
- touchEnd,
229
- loading: false,
230
- });
231
-
232
- if (!tableProps.clickDisplayTotal) {
233
- await this.queryTotal();
234
- }
235
- // }
236
- }
237
- };
238
-
239
- pageTo = async (pageNo: number, pageSize: number) => {
240
- const { onChangePage } = this.props;
241
- const { virtualEndPageNo } = this.state;
242
- let pageInfo = {
243
- pageNo,
244
- pageSize: pageSize ? pageSize : 10,
245
- virtualEndPageNo,
82
+ static defaultProps = {
83
+ pageInfo: {
84
+ pageNo: 1,
85
+ pageSize: 10,
86
+ virtualEndPageNo: undefined,
87
+ },
88
+ tableProps: {
89
+ size: "small",
90
+ clickDisplayTotal: false,
91
+ scrollY: 500,
92
+ },
93
+ hiddenRowCodes: [],
94
+ selectedRows: [],
95
+ viewModels: ["table"],
96
+ summaryConfigs: [],
97
+ };
98
+
99
+ state = {
100
+ queryDataCache: undefined,
101
+ virtualEndPageNo: undefined,
102
+ dataSource: undefined,
103
+ loading: true,
104
+ touchEnd: undefined,
105
+ total: undefined,
246
106
  };
247
- const { queryKey } = this.props;
248
- await this.loadData(queryKey.key, pageInfo);
249
- onChangePage(pageNo, pageSize);
250
- };
251
-
252
- queryTotal = async () => {
253
- const { queryKey, serverKey } = this.props;
254
- let total = await HcserviceV3.requestQueryCount(serverKey, queryKey.key);
255
- this.setState({
256
- total,
257
- });
258
- };
259
-
260
- getRowSelection = () => {
261
- const {
262
- columns,
263
- onChangeRowSelection,
264
- selectedRows,
265
- maxSelectedRows,
266
- primaryColumn,
267
- } = this.props;
268
- let { dataSource } = this.state;
269
- let selectedRowKeys = [];
270
-
271
- for (let row of selectedRows) {
272
- selectedRowKeys.push(row.code);
107
+
108
+ static contextType = LocaleContext;
109
+ context: React.ContextType<typeof LocaleContext>;
110
+
111
+ async componentDidMount() {
112
+ const {queryKey, pageInfo} = this.props;
113
+ // let pageInfo = {
114
+ // pageNo: 1,
115
+ // pageSize: defaultPageSize ? defaultPageSize : 10,
116
+ // virtualEndPageNo: undefined,
117
+ // }
118
+ if (queryKey) {
119
+ await this.loadData(queryKey.key, pageInfo);
120
+ }
273
121
  }
274
- const allRowKeys: string[] = [];
275
- if (dataSource) {
276
- for (let d of dataSource) {
277
- allRowKeys.push(d.code);
278
- }
122
+
123
+ componentWillUnmount() {
124
+ this.setState = () => false;
279
125
  }
280
- if (maxSelectedRows == -1) {
281
- return null;
126
+
127
+ async componentDidUpdate(prevProps) {
128
+ const {queryKey: preQueryKey, pageInfo: prePageInfo} = prevProps;
129
+ const {queryKey, pageInfo} = this.props;
130
+ const {total} = this.state;
131
+ if (queryKey) {
132
+ if (preQueryKey?.key != queryKey.key) {
133
+ await this.loadData(queryKey.key, pageInfo, true);
134
+ } else if (
135
+ prePageInfo?.pageNo != pageInfo.pageNo ||
136
+ prePageInfo?.pageSize != pageInfo.pageSize
137
+ ) {
138
+ await this.loadData(queryKey.key, pageInfo, false);
139
+ }
140
+ }
282
141
  }
283
- const rowSelection: TableRowSelection<any> = {
284
- fixed: true,
285
- type: maxSelectedRows == 1 ? "radio" : "checkbox",
286
- selectedRowKeys,
287
- onChange: (selectedRowKeys, selectedRows) => {
288
- //console.log('selectedRowKeys:', selectedRowKeys);
289
- // console.log('selectedRows:', selectedRows);
290
- let selectedRows_: SelectedRow[] = [];
291
- let selectedDatas: DtmplData[] = [];
292
- let titleColId = primaryColumn?.id;
293
- if (!titleColId) {
294
- columns.forEach((col) => {
295
- if (col.title != "序号" && titleColId == null) {
296
- titleColId = col.dataIndex;
297
- return;
142
+
143
+ DraggableContainer = (props) => (
144
+ <SortableBody
145
+ useDragHandle
146
+ disableAutoscroll
147
+ helperClass="row-dragging"
148
+ onSortEnd={this.onSortEnd}
149
+ {...props}
150
+ />
151
+ );
152
+
153
+ DraggableBodyRow = ({className, style, ...restProps}) => {
154
+ const {dataSource} = this.state;
155
+ if (dataSource) {
156
+ const index = dataSource.findIndex(
157
+ (x) => x.key === restProps["data-row-key"]
158
+ );
159
+ return <SortableItem key={index} index={index} {...restProps} />;
160
+ } else {
161
+ return <></>;
162
+ }
163
+ };
164
+
165
+ onSortEnd = ({oldIndex, newIndex}) => {
166
+ const {dataSource} = this.state;
167
+ if (oldIndex !== newIndex) {
168
+ const newData = arrayMoveImmutable(
169
+ [].concat(dataSource),
170
+ oldIndex,
171
+ newIndex
172
+ ).filter((el) => !!el);
173
+ //console.log('Sorted items: ', newData);
174
+ this.setState({dataSource: newData});
175
+ }
176
+ };
177
+
178
+ loadData = async (
179
+ queryKey: string,
180
+ pageInfo: PageInfo,
181
+ cleanCache?: boolean
182
+ ) => {
183
+ this.setState({
184
+ loading: true,
185
+ });
186
+ let {queryDataCache} = this.state;
187
+
188
+ let {serverKey, tableProps} = this.props;
189
+ let queryCache: Map<string, CacheData>;
190
+ if (cleanCache || !queryDataCache) {
191
+ queryCache = new Map<string, CacheData>();
192
+ this.setState({total: undefined});
193
+ } else {
194
+ queryCache = queryDataCache;
195
+ }
196
+ if (queryCache.has(pageInfo?.pageNo + "_" + pageInfo?.pageSize)) {
197
+ let cacheData = queryCache.get(
198
+ pageInfo?.pageNo + "_" + pageInfo?.pageSize
199
+ );
200
+ this.setState({
201
+ dataSource: cacheData.dataSource,
202
+ virtualEndPageNo: cacheData.pageInfo.virtualEndPageNo,
203
+ loading: false,
204
+ });
205
+ } else {
206
+ let queryData: QueryData = await HcserviceV3.requestQueryData(
207
+ serverKey,
208
+ queryKey,
209
+ pageInfo
210
+ );
211
+ if (queryData.key != this.props.queryKey.key) {
212
+ return;
213
+ } else {
214
+ let dataSource: object[] = [];
215
+ pageInfo = queryData.pageInfo;
216
+ if (queryData.entities) {
217
+ queryData.entities.forEach((item, index) => {
218
+ let row = {
219
+ key: item.code,
220
+ code: item.code, //增加code,为了删除操作
221
+ ...item.fieldMap,
222
+ index,
223
+ };
224
+ dataSource.push(row);
225
+ });
226
+ }
227
+
228
+ let touchEnd = queryData.touchEnd;
229
+ //缓存数据
230
+ queryCache.set(pageInfo?.pageNo + "_" + pageInfo?.pageSize, {
231
+ dataSource,
232
+ pageInfo,
233
+ });
234
+ this.setState({
235
+ dataSource,
236
+ virtualEndPageNo: pageInfo.virtualEndPageNo,
237
+ queryDataCache: queryCache,
238
+ touchEnd,
239
+ loading: false,
240
+ });
241
+
242
+ if (!tableProps.clickDisplayTotal) {
243
+ await this.queryTotal();
244
+ }
298
245
  }
299
- });
246
+ // }
300
247
  }
301
- selectedRows.forEach((item) => {
302
- selectedRows_.push({ code: item["code"], title: item[titleColId] });
303
- selectedDatas.push(item);
248
+ };
249
+
250
+ pageTo = async (pageNo: number, pageSize: number) => {
251
+ const {onChangePage} = this.props;
252
+ const {virtualEndPageNo} = this.state;
253
+ let pageInfo = {
254
+ pageNo,
255
+ pageSize: pageSize ? pageSize : 10,
256
+ virtualEndPageNo,
257
+ };
258
+ const {queryKey} = this.props;
259
+ await this.loadData(queryKey.key, pageInfo);
260
+ onChangePage(pageNo, pageSize);
261
+ };
262
+
263
+ queryTotal = async () => {
264
+ const {queryKey, serverKey} = this.props;
265
+ let total = await HcserviceV3.requestQueryCount(serverKey, queryKey.key);
266
+ this.setState({
267
+ total,
304
268
  });
305
- if (onChangeRowSelection) {
306
- onChangeRowSelection(selectedRows_, selectedDatas, allRowKeys);
269
+ };
270
+
271
+ getRowSelection = () => {
272
+ const {
273
+ columns,
274
+ onChangeRowSelection,
275
+ selectedRows,
276
+ maxSelectedRows,
277
+ primaryColumn,
278
+ } = this.props;
279
+ let {dataSource} = this.state;
280
+ let selectedRowKeys = [];
281
+
282
+ for (let row of selectedRows) {
283
+ selectedRowKeys.push(row.code);
307
284
  }
308
- },
285
+ const allRowKeys: string[] = [];
286
+ if (dataSource) {
287
+ for (let d of dataSource) {
288
+ allRowKeys.push(d.code);
289
+ }
290
+ }
291
+ if (maxSelectedRows == -1) {
292
+ return null;
293
+ }
294
+ const rowSelection: TableRowSelection<any> = {
295
+ fixed: true,
296
+ type: maxSelectedRows == 1 ? "radio" : "checkbox",
297
+ selectedRowKeys,
298
+ onChange: (selectedRowKeys, selectedRows) => {
299
+ //console.log('selectedRowKeys:', selectedRowKeys);
300
+ // console.log('selectedRows:', selectedRows);
301
+ let selectedRows_: SelectedRow[] = [];
302
+ let selectedDatas: DtmplData[] = [];
303
+ let titleColId = primaryColumn?.id;
304
+ if (!titleColId) {
305
+ columns.forEach((col) => {
306
+ if (col.title != "序号" && titleColId == null) {
307
+ titleColId = col.dataIndex;
308
+ return;
309
+ }
310
+ });
311
+ }
312
+ selectedRows.forEach((item) => {
313
+ selectedRows_.push({code: item["code"], title: item[titleColId]});
314
+ selectedDatas.push(item);
315
+ });
316
+ if (onChangeRowSelection) {
317
+ onChangeRowSelection(selectedRows_, selectedDatas, allRowKeys);
318
+ }
319
+ },
320
+ };
321
+ return rowSelection;
309
322
  };
310
- return rowSelection;
311
- };
312
-
313
- getUnHidenDataSource = () => {
314
- const { dataSource } = this.state;
315
- const { hiddenRowCodes } = this.props;
316
- let ds: object[] = [];
317
- if (dataSource) {
318
- for (let d of dataSource) {
319
- if (!hiddenRowCodes.includes(d.code)) {
320
- ds.push(d);
323
+
324
+ getUnHidenDataSource = () => {
325
+ const {dataSource} = this.state;
326
+ const {hiddenRowCodes} = this.props;
327
+ let ds: object[] = [];
328
+ if (dataSource) {
329
+ for (let d of dataSource) {
330
+ if (!hiddenRowCodes.includes(d.code)) {
331
+ ds.push(d);
332
+ }
333
+ }
321
334
  }
322
- }
323
- }
324
- return ds;
325
- };
326
-
327
- initViewList = (data) => {
328
- //console.log("data:",data);
329
- const { translate } = this.context;
330
- const { columns, columnConfigs, serverKey } = this.props;
331
- const formItemList = [];
332
- if (columnConfigs.length > 0) {
333
- columnConfigs.forEach((item, index) => {
334
- if (item.id != "10000" && item.id != "20000" && item.title != "操作") {
335
- const title = item.title;
336
- let fieldValue = data ? data[item.id] : undefined;
337
- if (title == "序号") {
338
- fieldValue = data.index;
339
- }
340
- //fieldValue 没有值时不能为null 要为 undefined。antd input所限制
341
- fieldValue = fieldValue
342
- ? fieldValue
343
- : item.defaultValue
344
- ? item.defaultValue
345
- : undefined;
346
- const fieldKey = item.id + Math.random() * 100;
347
-
348
- const formItem = (
349
- <Descriptions.Item
350
- label={translate("${" + item.title + "}")}
351
- key={index}
352
- className="labelcss"
353
- >
354
- <ViewControl
355
- serverKey={serverKey}
356
- holderType={"table"}
357
- value={fieldValue}
358
- fieldConfig={item}
359
- />
360
- </Descriptions.Item>
361
- );
362
- formItemList.push(formItem);
335
+ return ds;
336
+ };
337
+
338
+ initViewList = (data) => {
339
+ //console.log("data:",data);
340
+ const {translate} = this.context;
341
+ const {columns, columnConfigs, serverKey} = this.props;
342
+ const formItemList = [];
343
+ if (columnConfigs.length > 0) {
344
+ columnConfigs.forEach((item, index) => {
345
+ if (item.id != "10000" && item.id != "20000" && item.title != "操作") {
346
+ const title = item.title;
347
+ let fieldValue = data ? data[item.id] : undefined;
348
+ if (title == "序号") {
349
+ fieldValue = data.index;
350
+ }
351
+ //fieldValue 没有值时不能为null 要为 undefined。antd input所限制
352
+ fieldValue = fieldValue
353
+ ? fieldValue
354
+ : item.defaultValue
355
+ ? item.defaultValue
356
+ : undefined;
357
+ const fieldKey = item.id + Math.random() * 100;
358
+
359
+ const formItem = (
360
+ <Descriptions.Item
361
+ label={translate("${" + item.title + "}")}
362
+ key={index}
363
+ className="labelcss"
364
+ >
365
+ <ViewControl
366
+ serverKey={serverKey}
367
+ holderType={"table"}
368
+ value={fieldValue}
369
+ fieldConfig={item}
370
+ />
371
+ </Descriptions.Item>
372
+ );
373
+ formItemList.push(formItem);
374
+ }
375
+ });
363
376
  }
364
- });
365
- }
366
- return formItemList;
367
- };
368
-
369
- getTableSummaryNumberValue(value: "" | string[]) {
370
- if (value === undefined || value === null) return 0;
371
- if (typeof value === "string") return Number(value);
372
- return Number(value[0].split("@R@")[1]);
373
- }
374
-
375
- deepClone(source, hash = new WeakMap()) {
376
- if (typeof source !== "object" || source === null) {
377
- return source;
378
- }
379
- if (hash.has(source)) {
380
- return hash.get(source);
381
- }
382
- const target = Array.isArray(source) ? [] : {};
383
- Reflect.ownKeys(source).forEach((key) => {
384
- const val = source[key];
385
- if (typeof val === "object" && val != null) {
386
- target[key] = this.deepClone(val, hash);
387
- } else {
388
- target[key] = val;
389
- }
390
- });
391
- return target;
392
- }
393
-
394
- buildKeys(keys: { title: string; dataKey: string }[]) {
395
- return keys.map((i) => i.title).join("-");
396
- }
397
-
398
- buildColTag(cols, keys = []) {
399
- for (const col of cols) {
400
- if (!col.children) {
401
- // if (col.dataIndex === undefined)
402
- col.dataIndex = this.buildKeys([
403
- ...keys,
404
- { dataKey: col._type ? col._type : col.title, title: col.title },
405
- ]);
406
- if (col.keys === undefined)
407
- col.keys = [
408
- ...keys,
409
- { dataKey: col._type ? col._type : col.title, title: col.title },
410
- ];
411
- } else {
412
- this.buildColTag(col.children, [
413
- ...keys,
414
- { dataKey: col._type ? col._type : col.title, title: col.title },
415
- ]);
416
- }
377
+ return formItemList;
378
+ };
379
+
380
+ getTableSummaryNumberValue(value: "" | string[]) {
381
+ if (value === undefined || value === null) return 0;
382
+ if (typeof value === "string") return Number(value);
383
+ return Number(value[0].split("@R@")[1]);
417
384
  }
418
- }
419
-
420
- getCurCalKeys(cols, keys = []) {
421
- for (const col of cols) {
422
- if (Array.isArray(col.children)) {
423
- this.getCurCalKeys(col.children, keys);
424
- } else {
425
- keys.push({
426
- factIndex: col.keys[col.keys.length - 1],
427
- dataIndex: col.dataIndex,
385
+
386
+ deepClone(source, hash = new WeakMap()) {
387
+ if (typeof source !== "object" || source === null) {
388
+ return source;
389
+ }
390
+ if (hash.has(source)) {
391
+ return hash.get(source);
392
+ }
393
+ const target = Array.isArray(source) ? [] : {};
394
+ Reflect.ownKeys(source).forEach((key) => {
395
+ const val = source[key];
396
+ if (typeof val === "object" && val != null) {
397
+ target[key] = this.deepClone(val, hash);
398
+ } else {
399
+ target[key] = val;
400
+ }
428
401
  });
429
- }
402
+ return target;
430
403
  }
431
404
 
432
- return keys;
433
- }
434
- setSumColKeys(sumCol, sumKeys) {
435
- if (sumKeys.length === 0) return;
436
- if (Array.isArray(sumCol.children)) {
437
- this.setSumColKeys(sumCol.children, sumKeys);
438
- } else {
439
- for (const col of sumCol) {
440
- const factKey = col.keys[col.keys.length - 1].dataKey;
441
- col.sumDataIndex = sumKeys.filter(
442
- ({ factIndex: { dataKey } }) => dataKey === factKey
443
- );
444
- col.keys[col.keys.length - 1].sumDataIndex = col.sumDataIndex.map(
445
- ({ dataIndex }) => dataIndex
446
- );
447
- }
405
+ buildKeys(keys: { title: string; dataKey: string }[]) {
406
+ return keys.map((i) => i.title).join("-");
448
407
  }
449
- }
450
408
 
451
- handleProSummaryTable(data: any[]) {
452
- const isProSumarryTable = Boolean(
453
- this.props.subtotalXColumn || this.props.subtotalYColumn
454
- );
455
- if (!isProSumarryTable)
456
- return { proSummaryTableColumns: [], proSummaryTableData: [] };
457
-
458
- const { translate } = this.context;
459
-
460
- const { subtotalXColumn, subtotalYColumn, columns: _columns } = this.props;
461
- const columns = _columns;
462
- for (const d of data) {
463
- for (const [k, v] of Object.entries(d)) {
464
- if (v == null || v == "null") {
465
- d[k] = "";
466
- } else if (typeof v === "string" && (v as string)?.includes("@R@")) {
467
- d[k] = (v as string).split("@R@")[1];
409
+ buildColTag(cols, keys = []) {
410
+ for (const col of cols) {
411
+ if (!col.children) {
412
+ // if (col.dataIndex === undefined)
413
+ col.dataIndex = this.buildKeys([
414
+ ...keys,
415
+ {dataKey: col._type ? col._type : col.title, title: col.title},
416
+ ]);
417
+ if (col.keys === undefined)
418
+ col.keys = [
419
+ ...keys,
420
+ {dataKey: col._type ? col._type : col.title, title: col.title},
421
+ ];
422
+ } else {
423
+ this.buildColTag(col.children, [
424
+ ...keys,
425
+ {dataKey: col._type ? col._type : col.title, title: col.title},
426
+ ]);
427
+ }
468
428
  }
469
- }
470
429
  }
471
430
 
472
- console.log("data", data);
473
- console.log("columns", columns);
474
-
475
- const colMp = { dimension: [], fact: [] };
476
- const colIdToNameMp = {};
477
- const colNameToIdMp = {};
478
- for (const col of columns) {
479
- colIdToNameMp[col["dataIndex"]] = col["title"];
480
- colNameToIdMp[col["title"]] = col["dataIndex"];
481
- if (col.statColType !== undefined)
482
- colMp[col.statColType].push(this.deepClone(col));
431
+ getCurCalKeys(cols, keys = []) {
432
+ for (const col of cols) {
433
+ if (Array.isArray(col.children)) {
434
+ this.getCurCalKeys(col.children, keys);
435
+ } else {
436
+ keys.push({
437
+ factIndex: col.keys[col.keys.length - 1],
438
+ dataIndex: col.dataIndex,
439
+ });
440
+ }
441
+ }
442
+
443
+ return keys;
483
444
  }
484
- console.log("colIdToNameMp", colIdToNameMp);
485
- console.log("colNameToIdMp", colNameToIdMp);
486
- console.log("colMp", colMp);
487
-
488
- // canReadData
489
- const canReadData = [];
490
- for (const d of data) {
491
- const item = {};
492
- for (const [k, v] of Object.entries(d)) {
493
- let _v = v;
494
- if (
495
- colMp.fact.findIndex(({ dataIndex }) => dataIndex === k) > -1 &&
496
- v === null
497
- )
498
- _v = 0;
499
- item[colIdToNameMp[k]] = _v;
500
- }
501
- canReadData.push(item);
445
+
446
+ setSumColKeys(sumCol, sumKeys) {
447
+ if (sumKeys.length === 0) return;
448
+ if (Array.isArray(sumCol.children)) {
449
+ this.setSumColKeys(sumCol.children, sumKeys);
450
+ } else {
451
+ for (const col of sumCol) {
452
+ const factKey = col.keys[col.keys.length - 1].dataKey;
453
+ col.sumDataIndex = sumKeys.filter(
454
+ ({factIndex: {dataKey}}) => dataKey === factKey
455
+ );
456
+ col.keys[col.keys.length - 1].sumDataIndex = col.sumDataIndex.map(
457
+ ({dataIndex}) => dataIndex
458
+ );
459
+ }
460
+ }
502
461
  }
503
- console.log("canReadData", canReadData);
504
462
 
505
- let proSummaryTableColumns = [...this.deepClone(colMp.dimension)],
506
- proSummaryTableData = [],
507
- excludeGroupSumData = [];
463
+ handleProSummaryTable(data: any[]) {
464
+ const isProSumarryTable = Boolean(
465
+ this.props.subtotalXColumn || this.props.subtotalYColumn
466
+ );
467
+ if (!isProSumarryTable)
468
+ return {proSummaryTableColumns: [], proSummaryTableData: []};
469
+
470
+ const {translate} = this.context;
471
+
472
+ const {subtotalXColumn, subtotalYColumn, columns: _columns} = this.props;
473
+ const columns = _columns;
474
+ for (const d of data) {
475
+ for (const [k, v] of Object.entries(d)) {
476
+ if (v == null || v == "null") {
477
+ d[k] = "";
478
+ } else if (typeof v === "string" && (v as string)?.includes("@R@")) {
479
+ d[k] = (v as string).split("@R@")[1];
480
+ }
481
+ }
482
+ }
508
483
 
509
- const cal = colMp.fact[0]?.cal;
510
- const calTxt = cal === "sum" ? translate("小计") : translate("均值");
484
+ console.log("data", data);
485
+ console.log("columns", columns);
486
+
487
+ const colMp = {dimension: [], fact: []};
488
+ const colIdToNameMp = {};
489
+ const colNameToIdMp = {};
490
+ for (const col of columns) {
491
+ colIdToNameMp[col["dataIndex"]] = col["title"];
492
+ colNameToIdMp[col["title"]] = col["dataIndex"];
493
+ if (col.statColType !== undefined)
494
+ colMp[col.statColType].push(this.deepClone(col));
495
+ }
496
+ console.log("colIdToNameMp", colIdToNameMp);
497
+ console.log("colNameToIdMp", colNameToIdMp);
498
+ console.log("colMp", colMp);
499
+
500
+ // canReadData
501
+ const canReadData = [];
502
+ for (const d of data) {
503
+ const item = {};
504
+ for (const [k, v] of Object.entries(d)) {
505
+ let _v = v;
506
+ if (
507
+ colMp.fact.findIndex(({dataIndex}) => dataIndex === k) > -1 &&
508
+ v === null
509
+ )
510
+ _v = 0;
511
+ item[colIdToNameMp[k]] = _v;
512
+ }
513
+ canReadData.push(item);
514
+ }
515
+ console.log("canReadData", canReadData);
511
516
 
512
- // 计算列
513
- if (
514
- subtotalYColumn &&
515
- Array.isArray(subtotalYColumn) &&
516
- subtotalYColumn.length
517
- ) {
518
- // col
519
- let tnodes = [];
520
-
521
- for (let i = 0; i < subtotalYColumn.length; i++) {
522
- const y = subtotalYColumn[i];
523
- const id = y.id;
524
- const mp = {};
525
- let _tnodes = [];
526
- for (const d of data) mp[d[id]] = colIdToNameMp[id];
527
- for (const [k, v] of Object.entries(mp)) {
528
- const tnode = {
529
- title: k,
530
- _type: v,
531
- children: [...this.deepClone(i === 0 ? colMp.fact : tnodes)],
532
- };
533
- _tnodes.push(tnode);
517
+ let proSummaryTableColumns = [...this.deepClone(colMp.dimension)],
518
+ proSummaryTableData = [],
519
+ excludeGroupSumData = [];
520
+
521
+ const cal = colMp.fact[0]?.cal;
522
+ const calTxt = cal === "sum" ? translate("小计") : translate("均值");
523
+
524
+ // 计算列
525
+ if (
526
+ subtotalYColumn &&
527
+ Array.isArray(subtotalYColumn) &&
528
+ subtotalYColumn.length
529
+ ) {
530
+ // col
531
+ let tnodes = [];
532
+
533
+ for (let i = 0; i < subtotalYColumn.length; i++) {
534
+ const y = subtotalYColumn[i];
535
+ const id = y.id;
536
+ const mp = {};
537
+ let _tnodes = [];
538
+ for (const d of data) mp[d[id]] = colIdToNameMp[id];
539
+ for (const [k, v] of Object.entries(mp)) {
540
+ const tnode = {
541
+ title: k,
542
+ _type: v,
543
+ children: [...this.deepClone(i === 0 ? colMp.fact : tnodes)],
544
+ };
545
+ _tnodes.push(tnode);
546
+ }
547
+
548
+ this.buildColTag(_tnodes);
549
+ console.log("_tnodes", JSON.parse(JSON.stringify(_tnodes)));
550
+
551
+ const sumCol = {
552
+ title: calTxt,
553
+ children: [...this.deepClone(colMp.fact)],
554
+ TYPE: cal,
555
+ };
556
+ this.buildColTag([sumCol]);
557
+ this.setSumColKeys(sumCol, this.getCurCalKeys(_tnodes));
558
+ _tnodes.unshift(sumCol);
559
+
560
+ tnodes = _tnodes;
561
+ proSummaryTableColumns.splice(
562
+ proSummaryTableColumns.findIndex((item) => item.dataIndex === id),
563
+ 1
564
+ );
565
+ }
566
+ proSummaryTableColumns.push(...tnodes);
567
+ } else {
568
+ proSummaryTableColumns.push(...colMp.fact);
534
569
  }
535
570
 
536
- this.buildColTag(_tnodes);
537
- console.log("_tnodes", JSON.parse(JSON.stringify(_tnodes)));
571
+ // buildData
572
+ this.buildColTag(proSummaryTableColumns);
538
573
 
539
- const sumCol = {
540
- title: calTxt,
541
- children: [...this.deepClone(colMp.fact)],
542
- TYPE: cal,
543
- };
544
- this.buildColTag([sumCol]);
545
- this.setSumColKeys(sumCol, this.getCurCalKeys(_tnodes));
546
- _tnodes.unshift(sumCol);
547
-
548
- tnodes = _tnodes;
549
- proSummaryTableColumns.splice(
550
- proSummaryTableColumns.findIndex((item) => item.dataIndex === id),
551
- 1
574
+ // 处理行
575
+ const rowMp = {};
576
+ const rowKey = [];
577
+ for (const col of proSummaryTableColumns) {
578
+ if (Array.isArray(col.keys) && col.keys.length === 1) rowKey.push(col);
579
+ }
580
+ console.log("rowKey", rowKey);
581
+
582
+ for (const d of canReadData) {
583
+ let t: any = rowMp;
584
+ for (let i = 0; i < rowKey.length; i++) {
585
+ const key = rowKey[i].title;
586
+ if (t[d[key]] === undefined) {
587
+ if (i !== rowKey.length - 1) t[d[key]] = {};
588
+ else t[d[key]] = [];
589
+ }
590
+ t = t[d[key]];
591
+ }
592
+ if (Array.isArray(t)) t.push(d);
593
+ }
594
+
595
+ // 行数据处理完毕
596
+ console.log("rowMp", rowMp);
597
+
598
+ // 处理列
599
+ const colKey = [];
600
+ const colKeyTitle = this.flatSummaryCol(proSummaryTableColumns);
601
+ for (const col of proSummaryTableColumns) {
602
+ if (
603
+ (col.statColType === "fact" || Array.isArray(col.children)) &&
604
+ col.TYPE === undefined
605
+ ) {
606
+ colKey.push(col);
607
+ }
608
+ }
609
+ const flatSummaryColTitle = this.flatSummaryCol(colKey);
610
+ const flatSummaryRowTitle = this.flatSummaryCol(rowKey);
611
+ const flatSummaryCalTitle = this.flatSummaryCol(
612
+ proSummaryTableColumns.filter(({TYPE}) => TYPE !== undefined)
613
+ );
614
+ console.log("colKey", colKey);
615
+ console.log("colKeyTitle", colKeyTitle);
616
+ console.log("flatSummaryColTitle", flatSummaryColTitle);
617
+ console.log("flatSummaryRowTitle", flatSummaryRowTitle);
618
+ console.log("flatSummaryCalTitle", flatSummaryCalTitle);
619
+
620
+ proSummaryTableData = this.handleColData(
621
+ rowMp,
622
+ flatSummaryRowTitle,
623
+ flatSummaryColTitle,
624
+ flatSummaryCalTitle,
625
+ cal
552
626
  );
553
- }
554
- proSummaryTableColumns.push(...tnodes);
555
- } else {
556
- proSummaryTableColumns.push(...colMp.fact);
557
- }
558
627
 
559
- // buildData
560
- this.buildColTag(proSummaryTableColumns);
628
+ excludeGroupSumData = this.deepClone(proSummaryTableData);
629
+ console.log("excludeGroupSumData", excludeGroupSumData);
561
630
 
562
- // 处理行
563
- const rowMp = {};
564
- const rowKey = [];
565
- for (const col of proSummaryTableColumns) {
566
- if (Array.isArray(col.keys) && col.keys.length === 1) rowKey.push(col);
567
- }
568
- console.log("rowKey", rowKey);
569
-
570
- for (const d of canReadData) {
571
- let t: any = rowMp;
572
- for (let i = 0; i < rowKey.length; i++) {
573
- const key = rowKey[i].title;
574
- if (t[d[key]] === undefined) {
575
- if (i !== rowKey.length - 1) t[d[key]] = {};
576
- else t[d[key]] = [];
631
+ if (
632
+ subtotalXColumn &&
633
+ Array.isArray(subtotalXColumn) &&
634
+ subtotalXColumn.length
635
+ ) {
636
+ const sortKeys = subtotalXColumn.map(({id}) => colIdToNameMp[id]);
637
+
638
+ const rowSumMp = this.buildRowMp(proSummaryTableData, sortKeys);
639
+ console.log("rowSumMp", rowSumMp);
640
+
641
+ const calRowKeys = [
642
+ ...flatSummaryCalTitle,
643
+ ...flatSummaryColTitle,
644
+ ].map((i) => this.buildKeys(i));
645
+ console.log("calRowKeys", calRowKeys);
646
+
647
+ proSummaryTableData = this.handleRowData(
648
+ rowSumMp,
649
+ calRowKeys,
650
+ cal,
651
+ calTxt,
652
+ sortKeys[0]
653
+ );
577
654
  }
578
- t = t[d[key]];
579
- }
580
- if (Array.isArray(t)) t.push(d);
581
- }
582
655
 
583
- // 行数据处理完毕
584
- console.log("rowMp", rowMp);
585
-
586
- // 处理列
587
- const colKey = [];
588
- const colKeyTitle = this.flatSummaryCol(proSummaryTableColumns);
589
- for (const col of proSummaryTableColumns) {
590
- if (
591
- (col.statColType === "fact" || Array.isArray(col.children)) &&
592
- col.TYPE === undefined
593
- ) {
594
- colKey.push(col);
595
- }
596
- }
597
- const flatSummaryColTitle = this.flatSummaryCol(colKey);
598
- const flatSummaryRowTitle = this.flatSummaryCol(rowKey);
599
- const flatSummaryCalTitle = this.flatSummaryCol(
600
- proSummaryTableColumns.filter(({ TYPE }) => TYPE !== undefined)
601
- );
602
- console.log("colKey", colKey);
603
- console.log("colKeyTitle", colKeyTitle);
604
- console.log("flatSummaryColTitle", flatSummaryColTitle);
605
- console.log("flatSummaryRowTitle", flatSummaryRowTitle);
606
- console.log("flatSummaryCalTitle", flatSummaryCalTitle);
607
-
608
- proSummaryTableData = this.handleColData(
609
- rowMp,
610
- flatSummaryRowTitle,
611
- flatSummaryColTitle,
612
- flatSummaryCalTitle,
613
- cal
614
- );
656
+ // 序号
657
+ if (columns[0].title === "序号") {
658
+ const col: any = {dataIndex: "序号", title: "序号", width: 160};
659
+ if (columns[0].colWidth) {
660
+ col.width = columns[0].colWidth;
661
+ }
662
+ proSummaryTableColumns.unshift(col);
663
+ proSummaryTableData.forEach((_, idx) => {
664
+ _["序号"] = idx + 1;
665
+ });
666
+ }
615
667
 
616
- excludeGroupSumData = this.deepClone(proSummaryTableData);
617
- console.log("excludeGroupSumData", excludeGroupSumData);
668
+ // 做总计
669
+ if (
670
+ this.props.summaryConfigs &&
671
+ this.props.summaryConfigs?.length !== 0 &&
672
+ flatSummaryRowTitle.length &&
673
+ proSummaryTableData.length
674
+ ) {
675
+ const calkeys = [
676
+ ...flatSummaryCalTitle,
677
+ ...flatSummaryColTitle,
678
+ ].map((i) => this.buildKeys(i));
679
+
680
+ const sumData = {
681
+ [proSummaryTableColumns[0]?.dataIndex]:
682
+ cal === "sum" ? translate("${合计}") : translate("${均值}"),
683
+ _type: cal,
684
+ _calRange: "all",
685
+ };
686
+
687
+ for (const key of calkeys) {
688
+ if (cal === "sum")
689
+ sumData[key] = excludeGroupSumData.reduce(
690
+ (last, d) => last.plus(BigNumber(d[key])),
691
+ BigNumber(0)
692
+ );
693
+ if (cal === "avg")
694
+ sumData[key] = excludeGroupSumData.reduce(
695
+ (last, d) =>
696
+ last.plus(BigNumber(d[key]).div(excludeGroupSumData.length)),
697
+ BigNumber(0)
698
+ );
699
+ sumData[key] = sumData[key]?.toString();
700
+ }
701
+ proSummaryTableData.push(sumData);
702
+ }
618
703
 
619
- if (
620
- subtotalXColumn &&
621
- Array.isArray(subtotalXColumn) &&
622
- subtotalXColumn.length
623
- ) {
624
- const sortKeys = subtotalXColumn.map(({ id }) => colIdToNameMp[id]);
704
+ // 给小计和总计染色
705
+ this.stain(proSummaryTableColumns);
625
706
 
626
- const rowSumMp = this.buildRowMp(proSummaryTableData, sortKeys);
627
- console.log("rowSumMp", rowSumMp);
707
+ // 排序
708
+ proSummaryTableColumns = proSummaryTableColumns.sort((a, b) => {
709
+ return a.order < b.order ? -1 : 1;
710
+ });
628
711
 
629
- const calRowKeys = [
630
- ...flatSummaryCalTitle,
631
- ...flatSummaryColTitle,
632
- ].map((i) => this.buildKeys(i));
633
- console.log("calRowKeys", calRowKeys);
712
+ console.log("proSummaryTableColumns", proSummaryTableColumns);
713
+ console.log("proSummaryTableData", proSummaryTableData);
634
714
 
635
- proSummaryTableData = this.handleRowData(
636
- rowSumMp,
637
- calRowKeys,
638
- cal,
639
- calTxt,
640
- sortKeys[0]
641
- );
715
+ return {proSummaryTableColumns, proSummaryTableData};
642
716
  }
643
717
 
644
- // 序号
645
- if (columns[0].title === "序号") {
646
- const col: any = { dataIndex: "序号", title: "序号", width: 160 };
647
- if (columns[0].colWidth) {
648
- col.width = columns[0].colWidth;
649
- }
650
- proSummaryTableColumns.unshift(col);
651
- proSummaryTableData.forEach((_, idx) => {
652
- _["序号"] = idx + 1;
653
- });
718
+ flatSummaryCol(arr, res = []) {
719
+ for (const i of arr) {
720
+ if (!i.children) res.push(i.keys);
721
+ else this.flatSummaryCol(i.children, res);
722
+ }
723
+
724
+ return res;
654
725
  }
655
726
 
656
- // 做总计
657
- if (
658
- this.props.summaryConfigs &&
659
- this.props.summaryConfigs?.length !== 0 &&
660
- flatSummaryRowTitle.length &&
661
- proSummaryTableData.length
727
+ handleColData(
728
+ rowMp,
729
+ flatSummaryRowTitle,
730
+ flatSummaryColTitle,
731
+ flatSummaryCalTitle,
732
+ cal,
733
+ idx = 0,
734
+ data = {},
735
+ list = []
662
736
  ) {
663
- const calkeys = [
664
- ...flatSummaryCalTitle,
665
- ...flatSummaryColTitle,
666
- ].map((i) => this.buildKeys(i));
667
-
668
- const sumData = {
669
- [proSummaryTableColumns[0]?.dataIndex]:
670
- cal === "sum" ? translate("${合计}") : translate("${均值}"),
671
- _type: cal,
672
- _calRange: "all",
673
- };
674
-
675
- for (const key of calkeys) {
676
- if (cal === "sum")
677
- sumData[key] = excludeGroupSumData.reduce(
678
- (last, d) => last.plus(BigNumber(d[key])),
679
- BigNumber(0)
680
- );
681
- if (cal === "avg")
682
- sumData[key] = excludeGroupSumData.reduce(
683
- (last, d) =>
684
- last.plus(BigNumber(d[key]).div(excludeGroupSumData.length)),
685
- BigNumber(0)
686
- );
687
- sumData[key] = sumData[key]?.toString();
688
- }
689
- proSummaryTableData.push(sumData);
690
- }
737
+ if (Array.isArray(rowMp)) {
738
+ for (const col of flatSummaryColTitle) {
739
+ const key = this.buildKeys(col);
740
+ const colTarget = [];
741
+ const preConditions = col.slice(0, col.length - 1);
742
+ const targetKey = col.slice(col.length - 1)[0].title;
743
+ for (const d of rowMp) {
744
+ if (
745
+ preConditions.every(({dataKey, title}) => d[dataKey] === title)
746
+ ) {
747
+ colTarget.push(d);
748
+ }
749
+ }
691
750
 
692
- // 给小计和总计染色
693
- this.stain(proSummaryTableColumns);
751
+ if (data[key] === undefined || data[key] == "") {
752
+ data[key] = BigNumber(0);
753
+ }
754
+ if (cal === "sum")
755
+ data[key] = colTarget.reduce(
756
+ (last, d) => last.plus(BigNumber(d[targetKey])),
757
+ BigNumber(0)
758
+ );
759
+ if (cal === "avg")
760
+ data[key] = colTarget.reduce(
761
+ (last, d) =>
762
+ last.plus(BigNumber(d[targetKey]).div(colTarget.length)),
763
+ BigNumber(0)
764
+ );
765
+ data[key] =
766
+ data[key]?.toString() == "NaN" ? "0" : data[key]?.toString();
767
+ }
694
768
 
695
- // 排序
696
- proSummaryTableColumns = proSummaryTableColumns.sort((a, b) => {
697
- return a.order < b.order ? -1 : 1;
698
- });
769
+ for (const calCol of flatSummaryCalTitle) {
770
+ const key = this.buildKeys(calCol);
771
+ const sumDataIndex = calCol[calCol.length - 1].sumDataIndex;
772
+
773
+ if (data[key] === undefined || data[key] == "")
774
+ data[key] = BigNumber(0);
775
+ if (cal === "sum")
776
+ data[key] = sumDataIndex.reduce(
777
+ (last, dataKey) => last.plus(BigNumber(data[dataKey])),
778
+ BigNumber(0)
779
+ );
780
+ if (cal === "avg")
781
+ data[key] = sumDataIndex.reduce(
782
+ (last, dataKey) =>
783
+ last.plus(BigNumber(data[dataKey]).div(sumDataIndex.length)),
784
+ BigNumber(0)
785
+ );
786
+ data[key] = data[key]?.toString();
787
+ }
788
+ // debugger
789
+ list.push(data);
790
+ } else {
791
+ for (const [k, v] of Object.entries(rowMp)) {
792
+ const dataKey = flatSummaryRowTitle[idx][0].dataKey;
793
+ data[dataKey] = k;
794
+ this.handleColData(
795
+ v,
796
+ flatSummaryRowTitle,
797
+ flatSummaryColTitle,
798
+ flatSummaryCalTitle,
799
+ cal,
800
+ idx + 1,
801
+ this.deepClone(data),
802
+ list
803
+ );
804
+ }
805
+ }
699
806
 
700
- console.log("proSummaryTableColumns", proSummaryTableColumns);
701
- console.log("proSummaryTableData", proSummaryTableData);
807
+ return list;
808
+ }
702
809
 
703
- return { proSummaryTableColumns, proSummaryTableData };
704
- }
810
+ buildRowMp(data, sortKeys, idx = 0, mp = {}) {
811
+ if (idx >= sortKeys.length) return data;
705
812
 
706
- flatSummaryCol(arr, res = []) {
707
- for (const i of arr) {
708
- if (!i.children) res.push(i.keys);
709
- else this.flatSummaryCol(i.children, res);
710
- }
813
+ const dataKey = sortKeys[idx];
711
814
 
712
- return res;
713
- }
714
-
715
- handleColData(
716
- rowMp,
717
- flatSummaryRowTitle,
718
- flatSummaryColTitle,
719
- flatSummaryCalTitle,
720
- cal,
721
- idx = 0,
722
- data = {},
723
- list = []
724
- ) {
725
- if (Array.isArray(rowMp)) {
726
- for (const col of flatSummaryColTitle) {
727
- const key = this.buildKeys(col);
728
- const colTarget = [];
729
- const preConditions = col.slice(0, col.length - 1);
730
- const targetKey = col.slice(col.length - 1)[0].title;
731
- for (const d of rowMp) {
732
- if (
733
- preConditions.every(({ dataKey, title }) => d[dataKey] === title)
734
- ) {
735
- colTarget.push(d);
736
- }
815
+ for (const d of data) {
816
+ if (mp[d[dataKey]] === undefined) mp[d[dataKey]] = [];
817
+ mp[d[dataKey]].push(d);
737
818
  }
738
819
 
739
- if (data[key] === undefined || data[key] == "") {
740
- data[key] = BigNumber(0);
820
+ for (const [k, v] of Object.entries(mp)) {
821
+ mp[k] = this.buildRowMp(v, sortKeys, idx + 1);
741
822
  }
742
- if (cal === "sum")
743
- data[key] = colTarget.reduce(
744
- (last, d) => last.plus(BigNumber(d[targetKey])),
745
- BigNumber(0)
746
- );
747
- if (cal === "avg")
748
- data[key] = colTarget.reduce(
749
- (last, d) =>
750
- last.plus(BigNumber(d[targetKey]).div(colTarget.length)),
751
- BigNumber(0)
752
- );
753
- data[key] =
754
- data[key]?.toString() == "NaN" ? "0" : data[key]?.toString();
755
- }
756
-
757
- for (const calCol of flatSummaryCalTitle) {
758
- const key = this.buildKeys(calCol);
759
- const sumDataIndex = calCol[calCol.length - 1].sumDataIndex;
760
-
761
- if (data[key] === undefined || data[key] == "")
762
- data[key] = BigNumber(0);
763
- if (cal === "sum")
764
- data[key] = sumDataIndex.reduce(
765
- (last, dataKey) => last.plus(BigNumber(data[dataKey])),
766
- BigNumber(0)
767
- );
768
- if (cal === "avg")
769
- data[key] = sumDataIndex.reduce(
770
- (last, dataKey) =>
771
- last.plus(BigNumber(data[dataKey]).div(sumDataIndex.length)),
772
- BigNumber(0)
773
- );
774
- data[key] = data[key]?.toString();
775
- }
776
- // debugger
777
- list.push(data);
778
- } else {
779
- for (const [k, v] of Object.entries(rowMp)) {
780
- const dataKey = flatSummaryRowTitle[idx][0].dataKey;
781
- data[dataKey] = k;
782
- this.handleColData(
783
- v,
784
- flatSummaryRowTitle,
785
- flatSummaryColTitle,
786
- flatSummaryCalTitle,
787
- cal,
788
- idx + 1,
789
- this.deepClone(data),
790
- list
791
- );
792
- }
793
- }
794
-
795
- return list;
796
- }
797
823
 
798
- buildRowMp(data, sortKeys, idx = 0, mp = {}) {
799
- if (idx >= sortKeys.length) return data;
824
+ return mp;
825
+ }
800
826
 
801
- const dataKey = sortKeys[idx];
827
+ handleRowData(data, calKeys, cal, calTxt, calTxtKey, res = []) {
828
+ for (const [k, v] of Object.entries(data)) {
829
+ if (Array.isArray(v)) {
830
+ const sumData = {
831
+ [calTxtKey]: calTxt,
832
+ _type: cal,
833
+ _calRange: "small",
834
+ };
835
+ for (const calKey of calKeys) {
836
+ if (cal === "sum")
837
+ sumData[calKey] = v.reduce(
838
+ (last, d) => last.plus(BigNumber(d[calKey])),
839
+ BigNumber(0)
840
+ );
841
+ if (cal === "avg")
842
+ sumData[calKey] = v.reduce(
843
+ (last, d) => last.plus(BigNumber(d[calKey]).div(v.length)),
844
+ BigNumber(0)
845
+ );
846
+ sumData[calKey] = sumData[calKey]?.toString();
847
+ }
802
848
 
803
- for (const d of data) {
804
- if (mp[d[dataKey]] === undefined) mp[d[dataKey]] = [];
805
- mp[d[dataKey]].push(d);
806
- }
849
+ res.push(...v, sumData);
850
+ } else {
851
+ this.handleRowData(v, calKeys, cal, calTxt, calTxtKey, res);
852
+ }
853
+ }
807
854
 
808
- for (const [k, v] of Object.entries(mp)) {
809
- mp[k] = this.buildRowMp(v, sortKeys, idx + 1);
855
+ return res;
810
856
  }
811
857
 
812
- return mp;
813
- }
814
-
815
- handleRowData(data, calKeys, cal, calTxt, calTxtKey, res = []) {
816
- for (const [k, v] of Object.entries(data)) {
817
- if (Array.isArray(v)) {
818
- const sumData = {
819
- [calTxtKey]: calTxt,
820
- _type: cal,
821
- _calRange: "small",
822
- };
823
- for (const calKey of calKeys) {
824
- if (cal === "sum")
825
- sumData[calKey] = v.reduce(
826
- (last, d) => last.plus(BigNumber(d[calKey])),
827
- BigNumber(0)
828
- );
829
- if (cal === "avg")
830
- sumData[calKey] = v.reduce(
831
- (last, d) => last.plus(BigNumber(d[calKey]).div(v.length)),
832
- BigNumber(0)
833
- );
834
- sumData[calKey] = sumData[calKey]?.toString();
858
+ stain(cols) {
859
+ for (const col of cols) {
860
+ if (Array.isArray(col.children)) {
861
+ this.stain(col.children);
862
+ } else {
863
+ col.render = function (text, record, index) {
864
+ let className = "";
865
+ if (record._type !== undefined) {
866
+ if (record._calRange === "small") className = "xiaoji";
867
+ else className = "zongji";
868
+ }
869
+ return <div className={className}>{text}</div>;
870
+ };
871
+ }
835
872
  }
836
-
837
- res.push(...v, sumData);
838
- } else {
839
- this.handleRowData(v, calKeys, cal, calTxt, calTxtKey, res);
840
- }
841
873
  }
842
874
 
843
- return res;
844
- }
845
-
846
- stain(cols) {
847
- for (const col of cols) {
848
- if (Array.isArray(col.children)) {
849
- this.stain(col.children);
850
- } else {
851
- col.render = function(text, record, index) {
852
- let className = "";
853
- if (record._type !== undefined) {
854
- if (record._calRange === "small") className = "xiaoji";
855
- else className = "zongji";
856
- }
857
- return <div className={className}>{text}</div>;
858
- };
859
- }
875
+ render() {
876
+ const {
877
+ pageInfo,
878
+ columns,
879
+ viewModels,
880
+ summaryConfigs,
881
+ subtotalXColumn,
882
+ subtotalYColumn,
883
+ tableProps,
884
+ groupIColumns,
885
+ } = this.props;
886
+ const {touchEnd, total, loading, virtualEndPageNo} = this.state;
887
+ const {translate} = this.context;
888
+
889
+ const isProSumarryTable = Boolean(subtotalXColumn || subtotalYColumn);
890
+
891
+ const {
892
+ proSummaryTableColumns,
893
+ proSummaryTableData,
894
+ } = this.handleProSummaryTable(this.getUnHidenDataSource());
895
+
896
+ let current_cols = isProSumarryTable
897
+ ? proSummaryTableColumns
898
+ : columns
899
+ ? columns
900
+ : [];
901
+ console.log(current_cols);
902
+ let table_x = 20;
903
+ current_cols.forEach((c) => {
904
+ table_x = table_x + (c.width ? c.width : 140);
905
+ });
906
+
907
+ return (
908
+ <>
909
+ {viewModels.includes("table") ? (
910
+ <Table
911
+ size={tableProps.size ? tableProps.size : undefined}
912
+ rowSelection={this.getRowSelection()}
913
+ columns={current_cols}
914
+ dataSource={
915
+ isProSumarryTable
916
+ ? proSummaryTableData
917
+ : this.getUnHidenDataSource()
918
+ }
919
+ //tableLayout={'fixed'}
920
+ //sticky
921
+ scroll={
922
+ tableProps.scrollY == -1
923
+ ? null
924
+ : {
925
+ y: tableProps.scrollY == 0 ? 420 : tableProps.scrollY,
926
+ x: table_x,
927
+ }
928
+ }
929
+ bordered
930
+ pagination={false}
931
+ style={{display: columns ? "block" : "none"}}
932
+ summary={(pageData) => {
933
+ if (
934
+ !summaryConfigs ||
935
+ summaryConfigs?.length === 0 ||
936
+ pageData.length === 0
937
+ )
938
+ return <></>;
939
+
940
+ const columns = isProSumarryTable
941
+ ? proSummaryTableColumns
942
+ : this.props.columns;
943
+
944
+ const sumConfigs: {
945
+ sum: { value: string; id: string; columnConfig?: any }[];
946
+ avg: { value: string; id: string; columnConfig?: any }[];
947
+ } = {sum: [], avg: []};
948
+
949
+ if (this.getRowSelection()) {
950
+ sumConfigs["avg"].push({
951
+ value: "",
952
+ id: "",
953
+ columnConfig: {align: "center"},
954
+ });
955
+ sumConfigs["sum"].push({
956
+ value: "",
957
+ id: "",
958
+ columnConfig: {align: "center"},
959
+ });
960
+ }
961
+
962
+ sumConfigs["sum"].push({
963
+ value: translate("${合计}"),
964
+ id: "title",
965
+ columnConfig: {align: "center"},
966
+ });
967
+ sumConfigs["avg"].push({
968
+ value: translate("${均值}"),
969
+ id: "title",
970
+ columnConfig: {align: "center"},
971
+ });
972
+
973
+ let sumLen = 0,
974
+ avgLen = 0;
975
+
976
+ for (let i = 0; i < columns.length; i++) {
977
+ const idx = i,
978
+ dataIndex = columns[i].dataIndex;
979
+ if (idx === 0) continue;
980
+ const sum = {value: "", id: "", columnConfig: columns[i]};
981
+ const sumConfigIdx = summaryConfigs.findIndex(
982
+ ({id}) => id === dataIndex
983
+ );
984
+ if (sumConfigIdx === -1) {
985
+ sumConfigs["sum"].push(sum);
986
+ sumConfigs["avg"].push(sum);
987
+ continue;
988
+ }
989
+ const argFun = summaryConfigs[sumConfigIdx].aggFunc;
990
+ if (argFun === "sum")
991
+ sum.value = pageData
992
+ .reduce(
993
+ (lastNum, item) =>
994
+ lastNum.plus(
995
+ new BigNumber(
996
+ this.getTableSummaryNumberValue(item[dataIndex])
997
+ )
998
+ ),
999
+ new BigNumber(0)
1000
+ )
1001
+ ?.toString();
1002
+ if (argFun === "avg")
1003
+ sum.value = pageData
1004
+ .reduce(
1005
+ (lastNum, item) =>
1006
+ lastNum.plus(
1007
+ new BigNumber(
1008
+ this.getTableSummaryNumberValue(item[dataIndex])
1009
+ ).div(pageData.length)
1010
+ ),
1011
+ new BigNumber(0)
1012
+ )
1013
+ ?.toString();
1014
+ if (argFun === "groupIsum") {
1015
+ const key = groupIColumns[0].id;
1016
+ const set = new Set();
1017
+ sum.value = pageData
1018
+ .reduce((lastNum, item) => {
1019
+ if (set.has(item[key])) return lastNum;
1020
+ set.add(item[key]);
1021
+ return lastNum.plus(
1022
+ new BigNumber(
1023
+ this.getTableSummaryNumberValue(item[dataIndex])
1024
+ )
1025
+ );
1026
+ }, new BigNumber(0))
1027
+ ?.toString();
1028
+ }
1029
+ if (argFun === "groupIavg") {
1030
+ const key = groupIColumns[0].id;
1031
+ const set = new Set();
1032
+ let nums = 0;
1033
+
1034
+ pageData.forEach((item) => {
1035
+ if (set.has(item[key])) return;
1036
+ set.add(item[key]);
1037
+
1038
+ nums++;
1039
+ });
1040
+
1041
+ set.clear();
1042
+
1043
+ sum.value = pageData
1044
+ .reduce((lastNum, item) => {
1045
+ if (set.has(item[key])) return lastNum;
1046
+ set.add(item[key]);
1047
+ return lastNum.plus(
1048
+ new BigNumber(
1049
+ this.getTableSummaryNumberValue(item[dataIndex])
1050
+ ).div(nums)
1051
+ );
1052
+ }, new BigNumber(0))
1053
+ ?.toString();
1054
+ }
1055
+
1056
+ sum.id = dataIndex;
1057
+ if (argFun === "avg" || argFun === "groupIavg") {
1058
+ sumConfigs["avg"].push(sum);
1059
+ avgLen++;
1060
+ } else sumConfigs["avg"].push({value: "", id: ""});
1061
+
1062
+ if (argFun === "sum" || argFun === "groupIsum") {
1063
+ sumConfigs["sum"].push(sum);
1064
+ sumLen++;
1065
+ } else sumConfigs["sum"].push({value: "", id: ""});
1066
+ }
1067
+
1068
+ console.log("sumConfigs", sumConfigs, sumLen, avgLen);
1069
+
1070
+ return (
1071
+ <>
1072
+ {sumLen === 0 ? (
1073
+ <></>
1074
+ ) : (
1075
+ <Table.Summary.Row>
1076
+ {sumConfigs["sum"].map(
1077
+ ({id, value, columnConfig}, idx) => (
1078
+ <Table.Summary.Cell
1079
+ align={columnConfig?.align}
1080
+ index={idx}
1081
+ className="zongji"
1082
+ >
1083
+ {value}
1084
+ </Table.Summary.Cell>
1085
+ )
1086
+ )}
1087
+ </Table.Summary.Row>
1088
+ )}
1089
+ {avgLen === 0 ? (
1090
+ <></>
1091
+ ) : (
1092
+ <Table.Summary.Row>
1093
+ {sumConfigs["avg"].map(
1094
+ ({id, value, columnConfig}, idx) => (
1095
+ <Table.Summary.Cell
1096
+ align={columnConfig?.align}
1097
+ index={idx}
1098
+ className="zongji"
1099
+ >
1100
+ {value}
1101
+ </Table.Summary.Cell>
1102
+ )
1103
+ )}
1104
+ </Table.Summary.Row>
1105
+ )}
1106
+ </>
1107
+ );
1108
+ }}
1109
+ loading={loading}
1110
+ components={{
1111
+ body: {
1112
+ wrapper: this.DraggableContainer,
1113
+ row: this.DraggableBodyRow,
1114
+ },
1115
+ }}
1116
+ ></Table>
1117
+ ) : (
1118
+ ""
1119
+ )}
1120
+ <Pagination
1121
+ touchEnd={touchEnd}
1122
+ pageInfo={{...pageInfo, virtualEndPageNo}}
1123
+ pageTo={this.pageTo}
1124
+ queryTotal={this.queryTotal}
1125
+ total={total}
1126
+ />
1127
+ {viewModels.includes("verticalList") ? (
1128
+ <Card style={{marginTop: "10px"}}>
1129
+ <List
1130
+ dataSource={this.getUnHidenDataSource()}
1131
+ renderItem={(item) => (
1132
+ <List.Item key={item["id"]}>
1133
+ <Card size={"small"} bodyStyle={{padding: "4px"}}>
1134
+ <Descriptions column={4}>
1135
+ {this.initViewList(item)}
1136
+ </Descriptions>
1137
+ </Card>
1138
+ </List.Item>
1139
+ )}
1140
+ />
1141
+ </Card>
1142
+ ) : (
1143
+ ""
1144
+ )}
1145
+ </>
1146
+ );
860
1147
  }
861
- }
862
-
863
- render() {
864
- const {
865
- pageInfo,
866
- columns,
867
- viewModels,
868
- summaryConfigs,
869
- subtotalXColumn,
870
- subtotalYColumn,
871
- tableProps,
872
- } = this.props;
873
- const { touchEnd, total, loading, virtualEndPageNo } = this.state;
874
- const { translate } = this.context;
875
-
876
- const isProSumarryTable = Boolean(subtotalXColumn || subtotalYColumn);
877
-
878
- const {
879
- proSummaryTableColumns,
880
- proSummaryTableData,
881
- } = this.handleProSummaryTable(this.getUnHidenDataSource());
882
-
883
- let current_cols = isProSumarryTable
884
- ? proSummaryTableColumns
885
- : columns
886
- ? columns
887
- : [];
888
- console.log(current_cols);
889
- let table_x = 20;
890
- current_cols.forEach((c) => {
891
- table_x = table_x + (c.width ? c.width : 140);
892
- });
893
-
894
- return (
895
- <>
896
- {viewModels.includes("table") ? (
897
- <Table
898
- size={tableProps.size ? tableProps.size : undefined}
899
- rowSelection={this.getRowSelection()}
900
- columns={current_cols}
901
- dataSource={
902
- isProSumarryTable
903
- ? proSummaryTableData
904
- : this.getUnHidenDataSource()
905
- }
906
- //tableLayout={'fixed'}
907
- //sticky
908
- scroll={
909
- tableProps.scrollY == -1
910
- ? null
911
- : {
912
- y: tableProps.scrollY == 0 ? 420 : tableProps.scrollY,
913
- x: table_x,
914
- }
915
- }
916
- bordered
917
- pagination={false}
918
- style={{ display: columns ? "block" : "none" }}
919
- summary={(pageData) => {
920
- if (
921
- !summaryConfigs ||
922
- summaryConfigs?.length === 0 ||
923
- pageData.length === 0
924
- )
925
- return <></>;
926
-
927
- const columns = isProSumarryTable
928
- ? proSummaryTableColumns
929
- : this.props.columns;
930
-
931
- const sumConfigs: {
932
- sum: { value: string; id: string; columnConfig?: any }[];
933
- avg: { value: string; id: string; columnConfig?: any }[];
934
- } = { sum: [], avg: [] };
935
-
936
- if (this.getRowSelection()) {
937
- sumConfigs["avg"].push({
938
- value: "",
939
- id: "",
940
- columnConfig: { align: "center" },
941
- });
942
- sumConfigs["sum"].push({
943
- value: "",
944
- id: "",
945
- columnConfig: { align: "center" },
946
- });
947
- }
948
-
949
- sumConfigs["sum"].push({
950
- value: translate("${合计}"),
951
- id: "title",
952
- columnConfig: { align: "center" },
953
- });
954
- sumConfigs["avg"].push({
955
- value: translate("${均值}"),
956
- id: "title",
957
- columnConfig: { align: "center" },
958
- });
959
-
960
- let sumLen = 0,
961
- avgLen = 0;
962
-
963
- for (let i = 0; i < columns.length; i++) {
964
- const idx = i,
965
- dataIndex = columns[i].dataIndex;
966
- if (idx === 0) continue;
967
- const sum = { value: "", id: "", columnConfig: columns[i] };
968
- const sumConfigIdx = summaryConfigs.findIndex(
969
- ({ id }) => id === dataIndex
970
- );
971
- if (sumConfigIdx === -1) {
972
- sumConfigs["sum"].push(sum);
973
- sumConfigs["avg"].push(sum);
974
- continue;
975
- }
976
- const argFun = summaryConfigs[sumConfigIdx].aggFunc;
977
-
978
- if (argFun === "sum")
979
- sum.value = pageData
980
- .reduce(
981
- (lastNum, item) =>
982
- lastNum.plus(
983
- new BigNumber(
984
- this.getTableSummaryNumberValue(item[dataIndex])
985
- )
986
- ),
987
- new BigNumber(0)
988
- )
989
- ?.toString();
990
- if (argFun === "avg")
991
- sum.value = pageData
992
- .reduce(
993
- (lastNum, item) =>
994
- lastNum.plus(
995
- new BigNumber(
996
- this.getTableSummaryNumberValue(item[dataIndex])
997
- ).div(pageData.length)
998
- ),
999
- new BigNumber(0)
1000
- )
1001
- ?.toString();
1002
-
1003
- sum.id = dataIndex;
1004
- if (argFun === "avg") {
1005
- sumConfigs["avg"].push(sum);
1006
- avgLen++;
1007
- } else sumConfigs["avg"].push({ value: "", id: "" });
1008
-
1009
- if (argFun === "sum") {
1010
- sumConfigs["sum"].push(sum);
1011
- sumLen++;
1012
- } else sumConfigs["sum"].push({ value: "", id: "" });
1013
- }
1014
-
1015
- console.log("sumConfigs", sumConfigs, sumLen, avgLen);
1016
-
1017
- return (
1018
- <>
1019
- {sumLen === 0 ? (
1020
- <></>
1021
- ) : (
1022
- <Table.Summary.Row>
1023
- {sumConfigs["sum"].map(
1024
- ({ id, value, columnConfig }, idx) => (
1025
- <Table.Summary.Cell
1026
- align={columnConfig?.align}
1027
- index={idx}
1028
- className="zongji"
1029
- >
1030
- {value}
1031
- </Table.Summary.Cell>
1032
- )
1033
- )}
1034
- </Table.Summary.Row>
1035
- )}
1036
- {avgLen === 0 ? (
1037
- <></>
1038
- ) : (
1039
- <Table.Summary.Row>
1040
- {sumConfigs["avg"].map(
1041
- ({ id, value, columnConfig }, idx) => (
1042
- <Table.Summary.Cell
1043
- align={columnConfig?.align}
1044
- index={idx}
1045
- className="zongji"
1046
- >
1047
- {value}
1048
- </Table.Summary.Cell>
1049
- )
1050
- )}
1051
- </Table.Summary.Row>
1052
- )}
1053
- </>
1054
- );
1055
- }}
1056
- loading={loading}
1057
- components={{
1058
- body: {
1059
- wrapper: this.DraggableContainer,
1060
- row: this.DraggableBodyRow,
1061
- },
1062
- }}
1063
- ></Table>
1064
- ) : (
1065
- ""
1066
- )}
1067
- <Pagination
1068
- touchEnd={touchEnd}
1069
- pageInfo={{ ...pageInfo, virtualEndPageNo }}
1070
- pageTo={this.pageTo}
1071
- queryTotal={this.queryTotal}
1072
- total={total}
1073
- />
1074
- {viewModels.includes("verticalList") ? (
1075
- <Card style={{ marginTop: "10px" }}>
1076
- <List
1077
- dataSource={this.getUnHidenDataSource()}
1078
- renderItem={(item) => (
1079
- <List.Item key={item["id"]}>
1080
- <Card size={"small"} bodyStyle={{ padding: "4px" }}>
1081
- <Descriptions column={4}>
1082
- {this.initViewList(item)}
1083
- </Descriptions>
1084
- </Card>
1085
- </List.Item>
1086
- )}
1087
- />
1088
- </Card>
1089
- ) : (
1090
- ""
1091
- )}
1092
- </>
1093
- );
1094
- }
1095
1148
  }
1096
1149
 
1097
1150
  export default QueryTable;