aldehyde 0.2.151 → 0.2.152

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.
@@ -1,1150 +1,1159 @@
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";
25
+ import { ColumnsType } from "antd/es/table";
26
26
 
27
- const {Panel} = Collapse;
27
+ const { Panel } = Collapse;
28
28
  const SortableItem = SortableElement((props) => <tr {...props} />);
29
29
  const SortableBody = SortableContainer((props) => <tbody {...props} />);
30
30
 
31
31
  interface CacheData {
32
- dataSource: object[];
33
- pageInfo: PageInfo;
32
+ dataSource: object[];
33
+ pageInfo: PageInfo;
34
34
  }
35
35
 
36
36
  interface QueryTableProps {
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
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
70
70
  }
71
71
 
72
72
  interface QueryTableStat {
73
- queryDataCache?: Map<string, CacheData>;
74
- virtualEndPageNo?: number;
75
- dataSource?: object[];
76
- loading?: boolean;
77
- touchEnd?: boolean;
78
- total?: number;
73
+ queryDataCache?: Map<string, CacheData>;
74
+ virtualEndPageNo?: number;
75
+ dataSource?: object[];
76
+ loading?: boolean;
77
+ touchEnd?: boolean;
78
+ total?: number;
79
79
  }
80
80
 
81
81
  class QueryTable extends React.PureComponent<QueryTableProps, QueryTableStat> {
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,
106
- };
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
- }
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,
106
+ };
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);
121
120
  }
122
-
123
- componentWillUnmount() {
124
- this.setState = () => false;
121
+ }
122
+
123
+ componentWillUnmount() {
124
+ this.setState = () => false;
125
+ }
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
+ }
125
140
  }
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
- }
141
+ }
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 <></>;
141
162
  }
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});
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
+ });
175
226
  }
176
- };
177
227
 
178
- loadData = async (
179
- queryKey: string,
180
- pageInfo: PageInfo,
181
- cleanCache?: boolean
182
- ) => {
183
- this.setState({
184
- loading: true,
228
+ let touchEnd = queryData.touchEnd;
229
+ //缓存数据
230
+ queryCache.set(pageInfo?.pageNo + "_" + pageInfo?.pageSize, {
231
+ dataSource,
232
+ pageInfo,
185
233
  });
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
- }
245
- }
246
- // }
247
- }
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
234
  this.setState({
267
- total,
235
+ dataSource,
236
+ virtualEndPageNo: pageInfo.virtualEndPageNo,
237
+ queryDataCache: queryCache,
238
+ touchEnd,
239
+ loading: false,
268
240
  });
269
- };
270
241
 
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);
284
- }
285
- const allRowKeys: string[] = [];
286
- if (dataSource) {
287
- for (let d of dataSource) {
288
- allRowKeys.push(d.code);
289
- }
242
+ if (!tableProps.clickDisplayTotal) {
243
+ await this.queryTotal();
290
244
  }
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;
245
+ }
246
+ // }
247
+ }
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,
322
257
  };
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
- }
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,
268
+ });
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);
284
+ }
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;
333
309
  }
310
+ });
334
311
  }
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
- });
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);
376
318
  }
377
- return formItemList;
319
+ },
378
320
  };
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]);
384
- }
385
-
386
- deepClone(source, hash = new WeakMap()) {
387
- if (typeof source !== "object" || source === null) {
388
- return source;
321
+ return rowSelection;
322
+ };
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);
389
332
  }
390
- if (hash.has(source)) {
391
- return hash.get(source);
333
+ }
334
+ }
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);
392
374
  }
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
- }
401
- });
402
- return target;
375
+ });
403
376
  }
404
-
405
- buildKeys(keys: { title: string; dataKey: string }[]) {
406
- return keys.map((i) => i.title).join("-");
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]);
384
+ }
385
+
386
+ deepClone(source, hash = new WeakMap()) {
387
+ if (typeof source !== "object" || source === null) {
388
+ return source;
407
389
  }
408
-
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
- }
428
- }
390
+ if (hash.has(source)) {
391
+ return hash.get(source);
429
392
  }
430
-
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;
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
+ }
401
+ });
402
+ return target;
403
+ }
404
+
405
+ buildKeys(keys: { title: string; dataKey: string }[]) {
406
+ return keys.map((i) => i.title).join("-");
407
+ }
408
+
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
+ }
444
428
  }
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
- }
429
+ }
430
+
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
+ }
461
441
  }
462
442
 
463
- handleProSummaryTable(data: any[]) {
464
- const isProSumarryTable = Boolean(
465
- this.props.subtotalXColumn || this.props.subtotalYColumn
443
+ return keys;
444
+ }
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
466
455
  );
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
- }
456
+ col.keys[col.keys.length - 1].sumDataIndex = col.sumDataIndex.map(
457
+ ({ dataIndex }) => dataIndex
458
+ );
459
+ }
460
+ }
461
+ }
483
462
 
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);
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];
514
480
  }
515
- console.log("canReadData", canReadData);
516
-
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("均值");
481
+ }
482
+ }
523
483
 
524
- // 计算列
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;
525
506
  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
- }
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);
547
516
 
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);
569
- }
517
+ let proSummaryTableColumns = [...this.deepClone(colMp.dimension)],
518
+ proSummaryTableData = [],
519
+ excludeGroupSumData = [];
570
520
 
571
- // buildData
572
- this.buildColTag(proSummaryTableColumns);
521
+ const cal = colMp.fact[0]?.cal;
522
+ const calTxt = cal === "sum" ? translate("小计") : translate("均值");
573
523
 
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);
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);
593
546
  }
594
547
 
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
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
626
564
  );
565
+ }
566
+ proSummaryTableColumns.push(...tnodes);
567
+ } else {
568
+ proSummaryTableColumns.push(...colMp.fact);
569
+ }
627
570
 
628
- excludeGroupSumData = this.deepClone(proSummaryTableData);
629
- console.log("excludeGroupSumData", excludeGroupSumData);
571
+ // buildData
572
+ this.buildColTag(proSummaryTableColumns);
630
573
 
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
- );
654
- }
655
-
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
- });
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]] = [];
666
589
  }
590
+ t = t[d[key]];
591
+ }
592
+ if (Array.isArray(t)) t.push(d);
593
+ }
667
594
 
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
- };
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
626
+ );
686
627
 
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
- }
628
+ excludeGroupSumData = this.deepClone(proSummaryTableData);
629
+ console.log("excludeGroupSumData", excludeGroupSumData);
703
630
 
704
- // 给小计和总计染色
705
- this.stain(proSummaryTableColumns);
631
+ if (
632
+ subtotalXColumn &&
633
+ Array.isArray(subtotalXColumn) &&
634
+ subtotalXColumn.length
635
+ ) {
636
+ const sortKeys = subtotalXColumn.map(({ id }) => colIdToNameMp[id]);
706
637
 
707
- // 排序
708
- proSummaryTableColumns = proSummaryTableColumns.sort((a, b) => {
709
- return a.order < b.order ? -1 : 1;
710
- });
638
+ const rowSumMp = this.buildRowMp(proSummaryTableData, sortKeys);
639
+ console.log("rowSumMp", rowSumMp);
711
640
 
712
- console.log("proSummaryTableColumns", proSummaryTableColumns);
713
- console.log("proSummaryTableData", proSummaryTableData);
641
+ const calRowKeys = [
642
+ ...flatSummaryCalTitle,
643
+ ...flatSummaryColTitle,
644
+ ].map((i) => this.buildKeys(i));
645
+ console.log("calRowKeys", calRowKeys);
714
646
 
715
- return {proSummaryTableColumns, proSummaryTableData};
647
+ proSummaryTableData = this.handleRowData(
648
+ rowSumMp,
649
+ calRowKeys,
650
+ cal,
651
+ calTxt,
652
+ sortKeys[0]
653
+ );
716
654
  }
717
655
 
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;
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
+ });
725
666
  }
726
667
 
727
- handleColData(
728
- rowMp,
729
- flatSummaryRowTitle,
730
- flatSummaryColTitle,
731
- flatSummaryCalTitle,
732
- cal,
733
- idx = 0,
734
- data = {},
735
- list = []
668
+ // 做总计
669
+ if (
670
+ this.props.summaryConfigs &&
671
+ this.props.summaryConfigs?.length !== 0 &&
672
+ flatSummaryRowTitle.length &&
673
+ proSummaryTableData.length
736
674
  ) {
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
- }
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
+ }
750
703
 
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
- }
704
+ // 给小计和总计染色
705
+ this.stain(proSummaryTableColumns);
768
706
 
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
- }
707
+ // 排序
708
+ proSummaryTableColumns = proSummaryTableColumns.sort((a, b) => {
709
+ return a.order < b.order ? -1 : 1;
710
+ });
806
711
 
807
- return list;
808
- }
712
+ console.log("proSummaryTableColumns", proSummaryTableColumns);
713
+ console.log("proSummaryTableData", proSummaryTableData);
809
714
 
810
- buildRowMp(data, sortKeys, idx = 0, mp = {}) {
811
- if (idx >= sortKeys.length) return data;
715
+ return { proSummaryTableColumns, proSummaryTableData };
716
+ }
812
717
 
813
- const dataKey = sortKeys[idx];
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
+ }
814
723
 
815
- for (const d of data) {
816
- if (mp[d[dataKey]] === undefined) mp[d[dataKey]] = [];
817
- mp[d[dataKey]].push(d);
724
+ return res;
725
+ }
726
+
727
+ handleColData(
728
+ rowMp,
729
+ flatSummaryRowTitle,
730
+ flatSummaryColTitle,
731
+ flatSummaryCalTitle,
732
+ cal,
733
+ idx = 0,
734
+ data = {},
735
+ list = []
736
+ ) {
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
+ }
818
749
  }
819
750
 
820
- for (const [k, v] of Object.entries(mp)) {
821
- mp[k] = this.buildRowMp(v, sortKeys, idx + 1);
751
+ if (data[key] === undefined || data[key] == "") {
752
+ data[key] = BigNumber(0);
822
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
+ }
768
+
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
+ }
823
806
 
824
- return mp;
807
+ return list;
808
+ }
809
+
810
+ buildRowMp(data, sortKeys, idx = 0, mp = {}) {
811
+ if (idx >= sortKeys.length) return data;
812
+
813
+ const dataKey = sortKeys[idx];
814
+
815
+ for (const d of data) {
816
+ if (mp[d[dataKey]] === undefined) mp[d[dataKey]] = [];
817
+ mp[d[dataKey]].push(d);
825
818
  }
826
819
 
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
- }
820
+ for (const [k, v] of Object.entries(mp)) {
821
+ mp[k] = this.buildRowMp(v, sortKeys, idx + 1);
822
+ }
848
823
 
849
- res.push(...v, sumData);
850
- } else {
851
- this.handleRowData(v, calKeys, cal, calTxt, calTxtKey, res);
852
- }
824
+ return mp;
825
+ }
826
+
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();
853
847
  }
854
848
 
855
- return res;
849
+ res.push(...v, sumData);
850
+ } else {
851
+ this.handleRowData(v, calKeys, cal, calTxt, calTxtKey, res);
852
+ }
856
853
  }
857
854
 
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
- }
872
- }
855
+ return res;
856
+ }
857
+
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
+ }
873
872
  }
873
+ }
874
+
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
+
1015
+ const hash = (...args) => args.join("-");
1016
+ const hashKey = (data, keys) =>
1017
+ hash(...keys.map((key) => data[key]));
1018
+
1019
+ if (argFun === "groupIsum") {
1020
+ const allKeys = groupIColumns?.map(({ id }) => id);
1021
+ const set = new Set();
1022
+
1023
+ console.log(columns + "组件加和: ", [...set]);
1024
+
1025
+ sum.value = pageData
1026
+ .reduce((lastNum, item) => {
1027
+ if (set.has(hashKey(item, allKeys))) return lastNum;
1028
+ set.add(hashKey(item, allKeys));
1029
+ return lastNum.plus(
1030
+ new BigNumber(
1031
+ this.getTableSummaryNumberValue(item[dataIndex])
1032
+ )
1033
+ );
1034
+ }, new BigNumber(0))
1035
+ ?.toString();
1036
+ }
874
1037
 
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
- });
1038
+ if (argFun === "groupIavg") {
1039
+ const set = new Set();
1040
+ let nums = 0;
1041
+ const allKeys = groupIColumns?.map(({ id }) => id);
1042
+
1043
+ pageData.forEach((item) => {
1044
+ if (set.has(hashKey(item, allKeys))) return;
1045
+ set.add(hashKey(item, allKeys));
1046
+
1047
+ nums++;
1048
+ });
1049
+
1050
+ set.clear();
1051
+
1052
+ sum.value = pageData
1053
+ .reduce((lastNum, item) => {
1054
+ if (set.has(hashKey(item, allKeys))) return lastNum;
1055
+ set.add(hashKey(item, allKeys));
1056
+ return lastNum.plus(
1057
+ new BigNumber(
1058
+ this.getTableSummaryNumberValue(item[dataIndex])
1059
+ ).div(nums)
1060
+ );
1061
+ }, new BigNumber(0))
1062
+ ?.toString();
1063
+ }
906
1064
 
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
- );
1147
- }
1065
+ sum.id = dataIndex;
1066
+ if (argFun === "avg" || argFun === "groupIavg") {
1067
+ sumConfigs["avg"].push(sum);
1068
+ avgLen++;
1069
+ } else sumConfigs["avg"].push({ value: "", id: "" });
1070
+
1071
+ if (argFun === "sum" || argFun === "groupIsum") {
1072
+ sumConfigs["sum"].push(sum);
1073
+ sumLen++;
1074
+ } else sumConfigs["sum"].push({ value: "", id: "" });
1075
+ }
1076
+
1077
+ console.log("sumConfigs", sumConfigs, sumLen, avgLen);
1078
+
1079
+ return (
1080
+ <>
1081
+ {sumLen === 0 ? (
1082
+ <></>
1083
+ ) : (
1084
+ <Table.Summary.Row>
1085
+ {sumConfigs["sum"].map(
1086
+ ({ id, value, columnConfig }, idx) => (
1087
+ <Table.Summary.Cell
1088
+ align={columnConfig?.align}
1089
+ index={idx}
1090
+ className="zongji"
1091
+ >
1092
+ {value}
1093
+ </Table.Summary.Cell>
1094
+ )
1095
+ )}
1096
+ </Table.Summary.Row>
1097
+ )}
1098
+ {avgLen === 0 ? (
1099
+ <></>
1100
+ ) : (
1101
+ <Table.Summary.Row>
1102
+ {sumConfigs["avg"].map(
1103
+ ({ id, value, columnConfig }, idx) => (
1104
+ <Table.Summary.Cell
1105
+ align={columnConfig?.align}
1106
+ index={idx}
1107
+ className="zongji"
1108
+ >
1109
+ {value}
1110
+ </Table.Summary.Cell>
1111
+ )
1112
+ )}
1113
+ </Table.Summary.Row>
1114
+ )}
1115
+ </>
1116
+ );
1117
+ }}
1118
+ loading={loading}
1119
+ components={{
1120
+ body: {
1121
+ wrapper: this.DraggableContainer,
1122
+ row: this.DraggableBodyRow,
1123
+ },
1124
+ }}
1125
+ ></Table>
1126
+ ) : (
1127
+ ""
1128
+ )}
1129
+ <Pagination
1130
+ touchEnd={touchEnd}
1131
+ pageInfo={{ ...pageInfo, virtualEndPageNo }}
1132
+ pageTo={this.pageTo}
1133
+ queryTotal={this.queryTotal}
1134
+ total={total}
1135
+ />
1136
+ {viewModels.includes("verticalList") ? (
1137
+ <Card style={{ marginTop: "10px" }}>
1138
+ <List
1139
+ dataSource={this.getUnHidenDataSource()}
1140
+ renderItem={(item) => (
1141
+ <List.Item key={item["id"]}>
1142
+ <Card size={"small"} bodyStyle={{ padding: "4px" }}>
1143
+ <Descriptions column={4}>
1144
+ {this.initViewList(item)}
1145
+ </Descriptions>
1146
+ </Card>
1147
+ </List.Item>
1148
+ )}
1149
+ />
1150
+ </Card>
1151
+ ) : (
1152
+ ""
1153
+ )}
1154
+ </>
1155
+ );
1156
+ }
1148
1157
  }
1149
1158
 
1150
1159
  export default QueryTable;