zmdms-webui 2.6.8 → 2.6.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.
|
@@ -5,7 +5,7 @@ import 'lodash/isEqual';
|
|
|
5
5
|
import 'ahooks';
|
|
6
6
|
import '../../node_modules/immutability-helper/index.js';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
|
-
import { exactRound, addThousedSeparator
|
|
8
|
+
import { plus, exactRound, addThousedSeparator } from 'zmdms-utils';
|
|
9
9
|
import '../../node_modules/exceljs/dist/exceljs.min.js';
|
|
10
10
|
import 'dayjs';
|
|
11
11
|
import { getAllLeafColumns } from '../utils/columnHelpers.js';
|
|
@@ -22,61 +22,40 @@ var useSummaryRow = function (params) {
|
|
|
22
22
|
if (!hasSummary)
|
|
23
23
|
return null;
|
|
24
24
|
var summaryRecord = {};
|
|
25
|
+
// 原始值,为转为千分符的
|
|
26
|
+
var summaryOriginalValues = {};
|
|
25
27
|
// 找到第一个列(包括序号列、选择框列)
|
|
26
28
|
var firstColIndex = leafColumns.length > 0 ? 0 : -1;
|
|
27
29
|
leafColumns.forEach(function (column, colIndex) {
|
|
28
30
|
var dataIndex = column.dataIndex || column.key;
|
|
29
31
|
if (column.isSummary) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// 第二个参数:所有数据(可用于复杂计算)
|
|
42
|
-
var calculatedValue = column.totalCalcCallback(columnValues_1, dataSource);
|
|
43
|
-
var formattedValue = calculatedValue;
|
|
44
|
-
// 应用格式化
|
|
45
|
-
if (typeof calculatedValue === "number") {
|
|
46
|
-
if (column.precision !== undefined) {
|
|
47
|
-
formattedValue = exactRound(calculatedValue, column.precision);
|
|
48
|
-
}
|
|
49
|
-
if (column.thousand) {
|
|
50
|
-
formattedValue = addThousedSeparator(formattedValue);
|
|
51
|
-
}
|
|
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);
|
|
52
43
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
sum_1 = plus(sum_1, num);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
// 应用格式化
|
|
69
|
-
var formattedSum = sum_1;
|
|
70
|
-
if (typeof sum_1 === "number") {
|
|
71
|
-
if (column.precision !== undefined) {
|
|
72
|
-
formattedSum = exactRound(sum_1, column.precision);
|
|
73
|
-
}
|
|
74
|
-
if (column.thousand) {
|
|
75
|
-
formattedSum = addThousedSeparator(formattedSum);
|
|
76
|
-
}
|
|
44
|
+
});
|
|
45
|
+
calculatedSum = sum_1;
|
|
46
|
+
// 应用格式化(仅在没有自定义回调或回调返回数值时)
|
|
47
|
+
var formattedSum = calculatedSum;
|
|
48
|
+
summaryOriginalValues[dataIndex] = calculatedSum;
|
|
49
|
+
if (typeof calculatedSum === "number") {
|
|
50
|
+
if (column.precision !== undefined) {
|
|
51
|
+
formattedSum = exactRound(calculatedSum, column.precision);
|
|
52
|
+
summaryOriginalValues[dataIndex] = calculatedSum;
|
|
53
|
+
}
|
|
54
|
+
if (column.thousand) {
|
|
55
|
+
formattedSum = addThousedSeparator(formattedSum);
|
|
77
56
|
}
|
|
78
|
-
summaryRecord[dataIndex] = formattedSum;
|
|
79
57
|
}
|
|
58
|
+
summaryRecord[dataIndex] = formattedSum;
|
|
80
59
|
}
|
|
81
60
|
else if (colIndex === firstColIndex) {
|
|
82
61
|
// 第一列显示"合计"(可以是序号列、选择框列或数据列)
|
|
@@ -86,6 +65,12 @@ var useSummaryRow = function (params) {
|
|
|
86
65
|
summaryRecord[dataIndex] = "";
|
|
87
66
|
}
|
|
88
67
|
});
|
|
68
|
+
leafColumns.forEach(function (column) {
|
|
69
|
+
if (column.totalCalcCallback) {
|
|
70
|
+
var dataIndex = column.dataIndex || column.key;
|
|
71
|
+
summaryRecord[dataIndex] = column.totalCalcCallback(summaryOriginalValues[dataIndex], summaryOriginalValues);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
89
74
|
summaryRecord[IS_SUMMARY] = true;
|
|
90
75
|
return summaryRecord;
|
|
91
76
|
}, [columns, dataSource]);
|
package/dist/es/table/excel.js
CHANGED
|
@@ -3,7 +3,7 @@ import ExcelJS from '../node_modules/exceljs/dist/exceljs.min.js';
|
|
|
3
3
|
import { useMergeKeys, useNumKeys, useDateKeys } from './hooks.js';
|
|
4
4
|
import { useMemoizedFn } from 'ahooks';
|
|
5
5
|
import { IS_SUMMARY, MERGE_ROW_SPANS } from './constant.js';
|
|
6
|
-
import { exactRound } from 'zmdms-utils';
|
|
6
|
+
import { plus, exactRound } from 'zmdms-utils';
|
|
7
7
|
import dayjs from 'dayjs';
|
|
8
8
|
|
|
9
9
|
// 内部常量,用于标记父数据
|
|
@@ -73,34 +73,17 @@ function exportToExcelWithMergeAndComments(records, columns, mergeKeys, numKeys,
|
|
|
73
73
|
excelData.leafColumns.forEach(function (col, colIndex) {
|
|
74
74
|
var key = col.dataIndex;
|
|
75
75
|
if (col.isSummary) {
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// 调用自定义计算回调
|
|
86
|
-
// 第一个参数:该列所有值数组
|
|
87
|
-
// 第二个参数:所有数据(可用于复杂计算)
|
|
88
|
-
var calculatedValue = col.totalCalcCallback(columnValues, processedData);
|
|
89
|
-
sumsByKey_1[key] = calculatedValue;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
// 默认计算逻辑:数值求和
|
|
93
|
-
var total = 0;
|
|
94
|
-
for (var i = 0; i < processedData.length; i++) {
|
|
95
|
-
if (processedData[i][IS_SUMMARY])
|
|
96
|
-
continue;
|
|
97
|
-
var v = processedData[i][key];
|
|
98
|
-
var n = typeof v === "number" ? v : Number(v);
|
|
99
|
-
if (!isNaN(n))
|
|
100
|
-
total += n;
|
|
101
|
-
}
|
|
102
|
-
sumsByKey_1[key] = total;
|
|
76
|
+
// 默认计算逻辑:数值求和
|
|
77
|
+
var total = 0;
|
|
78
|
+
for (var i = 0; i < processedData.length; i++) {
|
|
79
|
+
if (processedData[i][IS_SUMMARY])
|
|
80
|
+
continue;
|
|
81
|
+
var v = processedData[i][key];
|
|
82
|
+
var n = typeof v === "number" ? v : Number(v);
|
|
83
|
+
if (!isNaN(n))
|
|
84
|
+
total = plus(total, n);
|
|
103
85
|
}
|
|
86
|
+
sumsByKey_1[key] = total;
|
|
104
87
|
}
|
|
105
88
|
});
|
|
106
89
|
summaryRow = excelData.leafColumns.map(function (col, index) {
|
|
@@ -108,6 +91,9 @@ function exportToExcelWithMergeAndComments(records, columns, mergeKeys, numKeys,
|
|
|
108
91
|
return "合计";
|
|
109
92
|
var key = col.dataIndex;
|
|
110
93
|
if (col.isSummary && sumsByKey_1[key] !== undefined) {
|
|
94
|
+
if (col.totalCalcCallback) {
|
|
95
|
+
return col.totalCalcCallback(sumsByKey_1, processedData);
|
|
96
|
+
}
|
|
111
97
|
return sumsByKey_1[key];
|
|
112
98
|
}
|
|
113
99
|
return "";
|