zmdms-webui 2.8.8 → 2.8.9

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.
@@ -30,19 +30,25 @@ var useSummaryRow = function (params) {
30
30
  var dataIndex = column.dataIndex || column.key;
31
31
  if (column.isSummary) {
32
32
  var calculatedSum = void 0;
33
- // 默认计算逻辑:数值求和
34
- var sum_1 = 0;
35
- dataSource.forEach(function (record) {
36
- var value = record[dataIndex];
37
- var num = typeof value === "string" ? parseFloat(value) : value;
38
- if (!isNaN(num) &&
39
- num !== null &&
40
- num !== undefined &&
41
- !record[IS_SUMMARY]) {
42
- sum_1 = plus(sum_1, num);
43
- }
44
- });
45
- calculatedSum = sum_1;
33
+ // 如果有自定义计算函数,使用自定义逻辑
34
+ if (column.summaryCalc) {
35
+ calculatedSum = column.summaryCalc(dataSource.filter(function (record) { return !record[IS_SUMMARY]; }), dataIndex);
36
+ }
37
+ else {
38
+ // 默认计算逻辑:数值求和
39
+ var sum_1 = 0;
40
+ dataSource.forEach(function (record) {
41
+ var value = record[dataIndex];
42
+ var num = typeof value === "string" ? parseFloat(value) : value;
43
+ if (!isNaN(num) &&
44
+ num !== null &&
45
+ num !== undefined &&
46
+ !record[IS_SUMMARY]) {
47
+ sum_1 = plus(sum_1, num);
48
+ }
49
+ });
50
+ calculatedSum = sum_1;
51
+ }
46
52
  // 应用格式化(仅在没有自定义回调或回调返回数值时)
47
53
  var formattedSum = calculatedSum;
48
54
  summaryOriginalValues[dataIndex] = calculatedSum;
@@ -138,12 +138,19 @@ interface ICanvasColumnType<RecordType = any> {
138
138
  */
139
139
  isSummary?: boolean;
140
140
  /**
141
- * 合计自定义计算回调函数
141
+ * 合计自定义计算回调函数(用于格式化或二次处理已计算的合计值)
142
142
  * @param value 当前值
143
143
  * @param values 所有值的数组
144
144
  * @returns 计算后的合计值
145
145
  */
146
146
  totalCalcCallback?: (value: string | number | undefined, values: Record<string, any>) => any;
147
+ /**
148
+ * 自定义合计计算方式(替代默认的求和逻辑)
149
+ * @param dataSource 数据源
150
+ * @param dataIndex 当前列的字段名
151
+ * @returns 计算后的值
152
+ */
153
+ summaryCalc?: (dataSource: RecordType[], dataIndex: string) => number | string;
147
154
  /**
148
155
  * 开启合并的字段,按其他字段维度合并
149
156
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-webui",
3
- "version": "2.8.8",
3
+ "version": "2.8.9",
4
4
  "private": false,
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",