linkmore-design 1.1.27-beta.2 → 1.1.27-beta.4
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.
- package/dist/LmTable/expression.d.ts +1 -1
- package/dist/index.umd.js +67 -26
- package/dist/index.umd.min.js +5 -5
- package/es/LmTable/Table.js +2 -1
- package/es/LmTable/components/CalcExpression.js +35 -10
- package/es/LmTable/expression.d.ts +1 -1
- package/es/LmTable/expression.js +30 -15
- package/lib/LmTable/Table.js +2 -1
- package/lib/LmTable/components/CalcExpression.js +35 -10
- package/lib/LmTable/expression.d.ts +1 -1
- package/lib/LmTable/expression.js +30 -15
- package/package.json +1 -1
package/es/LmTable/Table.js
CHANGED
|
@@ -914,7 +914,8 @@ var ResetTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
914
914
|
return {
|
|
915
915
|
record: record,
|
|
916
916
|
col: col,
|
|
917
|
-
onChangeRecord: function onChangeRecord() {
|
|
917
|
+
onChangeRecord: function onChangeRecord(dfs, dataIndex, value) {
|
|
918
|
+
dfs(dataSource, dataIndex, value);
|
|
918
919
|
update();
|
|
919
920
|
}
|
|
920
921
|
};
|
|
@@ -12,18 +12,37 @@ import React from 'react';
|
|
|
12
12
|
import calc, { reset } from '../expression';
|
|
13
13
|
import Select from '../../Select';
|
|
14
14
|
var Option = Select.Option;
|
|
15
|
-
var dfs = function dfs(
|
|
15
|
+
var dfs = function dfs(dataSource, dataIndex, expression) {
|
|
16
16
|
var average = function average(arr) {
|
|
17
|
+
var history = [];
|
|
17
18
|
arr === null || arr === void 0 ? void 0 : arr.forEach(function (item) {
|
|
18
19
|
if (item === null || item === void 0 ? void 0 : item.children) {
|
|
19
20
|
average(item === null || item === void 0 ? void 0 : item.children);
|
|
20
21
|
}
|
|
21
|
-
calc(item, [[dataIndex, expression]]);
|
|
22
|
+
calc(item, [[dataIndex, expression]], history);
|
|
22
23
|
});
|
|
24
|
+
if (history && history.length) {
|
|
25
|
+
var sum = 0;
|
|
26
|
+
history.forEach(function (h) {
|
|
27
|
+
sum += h.sum;
|
|
28
|
+
});
|
|
29
|
+
history.forEach(function (h) {
|
|
30
|
+
if (sum < 0.000001) {
|
|
31
|
+
sum = 0;
|
|
32
|
+
h.item[h.dataIndex] = '0%';
|
|
33
|
+
} else {
|
|
34
|
+
h.item[h.dataIndex] = (h.sum / sum * 100).toFixed(2) + '%';
|
|
35
|
+
}
|
|
36
|
+
h.item["".concat(h.dataIndex, "_sum")] = sum;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
23
39
|
};
|
|
24
|
-
average(
|
|
40
|
+
average(dataSource);
|
|
25
41
|
};
|
|
26
42
|
var strategy = [{
|
|
43
|
+
value: 'percent',
|
|
44
|
+
label: '百分比'
|
|
45
|
+
}, {
|
|
27
46
|
value: 'average',
|
|
28
47
|
label: '平均值'
|
|
29
48
|
}, {
|
|
@@ -39,11 +58,12 @@ var strategy = [{
|
|
|
39
58
|
var CalcExpression = function CalcExpression(props) {
|
|
40
59
|
var record = props.record,
|
|
41
60
|
col = props.col,
|
|
61
|
+
columns = props.columns,
|
|
42
62
|
children = props.children,
|
|
43
63
|
onChangeRecord = props.onChangeRecord,
|
|
44
64
|
rest = __rest(props
|
|
45
65
|
// 列参数
|
|
46
|
-
, ["record", "col", "children", "onChangeRecord"]);
|
|
66
|
+
, ["record", "col", "columns", "children", "onChangeRecord"]);
|
|
47
67
|
// 列参数
|
|
48
68
|
var isShowSelect = false;
|
|
49
69
|
var currentStrategy = [];
|
|
@@ -63,14 +83,18 @@ var CalcExpression = function CalcExpression(props) {
|
|
|
63
83
|
throw Error('no parameter dataIndex');
|
|
64
84
|
}
|
|
65
85
|
if (value) {
|
|
66
|
-
dfs
|
|
86
|
+
onChangeRecord(dfs, col.dataIndex, value);
|
|
67
87
|
} else {
|
|
68
|
-
reset
|
|
88
|
+
onChangeRecord(reset, col.dataIndex, value);
|
|
69
89
|
}
|
|
70
|
-
onChangeRecord(record);
|
|
71
90
|
};
|
|
72
91
|
if (record && record._group && isShowSelect && (col === null || col === void 0 ? void 0 : col.dataIndex)) {
|
|
73
|
-
return /*#__PURE__*/React.createElement("td", Object.assign({}, rest),
|
|
92
|
+
return /*#__PURE__*/React.createElement("td", Object.assign({}, rest), /*#__PURE__*/React.createElement("div", {
|
|
93
|
+
style: {
|
|
94
|
+
display: 'flex',
|
|
95
|
+
alignItems: 'center'
|
|
96
|
+
}
|
|
97
|
+
}, /*#__PURE__*/React.createElement("span", null, record[col.dataIndex]), /*#__PURE__*/React.createElement(Select, {
|
|
74
98
|
className: "calc-select",
|
|
75
99
|
value: record["".concat(col.dataIndex, "_exp")],
|
|
76
100
|
size: "small",
|
|
@@ -81,9 +105,10 @@ var CalcExpression = function CalcExpression(props) {
|
|
|
81
105
|
}, currentStrategy.map(function (item) {
|
|
82
106
|
return /*#__PURE__*/React.createElement(Option, {
|
|
83
107
|
className: "calc-option",
|
|
84
|
-
value: item.value
|
|
108
|
+
value: item.value,
|
|
109
|
+
key: item.value
|
|
85
110
|
}, item.label);
|
|
86
|
-
})));
|
|
111
|
+
}))));
|
|
87
112
|
}
|
|
88
113
|
return /*#__PURE__*/React.createElement("td", Object.assign({}, rest), children);
|
|
89
114
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export default function calc(item: any, needCalcKeys: string[][]): void;
|
|
1
|
+
export default function calc(item: any, needCalcKeys: string[][], history: any): void;
|
|
2
2
|
export declare const reset: (arr: any, dataIndex: any) => void;
|
package/es/LmTable/expression.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
function getSum(item, dataIndex) {
|
|
3
|
+
var sum = 0;
|
|
4
|
+
item.children.forEach(function (subItem) {
|
|
5
|
+
var value;
|
|
6
|
+
if (/\%/.test("".concat(subItem[dataIndex]))) {
|
|
7
|
+
value = Number(subItem["".concat(dataIndex, "_sum")]);
|
|
8
|
+
} else {
|
|
9
|
+
value = Number(subItem[dataIndex]);
|
|
10
|
+
}
|
|
11
|
+
if (Number.isNaN(value)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
sum += value;
|
|
15
|
+
});
|
|
16
|
+
return sum;
|
|
17
|
+
}
|
|
2
18
|
// 分组求和计算
|
|
3
|
-
export default function calc(item, needCalcKeys) {
|
|
19
|
+
export default function calc(item, needCalcKeys, history) {
|
|
4
20
|
var _a;
|
|
5
21
|
if ((_a = item === null || item === void 0 ? void 0 : item.children) === null || _a === void 0 ? void 0 : _a.length) {
|
|
6
22
|
needCalcKeys.forEach(function (dkey) {
|
|
@@ -11,20 +27,12 @@ export default function calc(item, needCalcKeys) {
|
|
|
11
27
|
dataIndex = _dkey[0],
|
|
12
28
|
expression = _dkey[1];
|
|
13
29
|
item["".concat(dataIndex, "_exp")] = expression;
|
|
14
|
-
if (expression === 'sum'
|
|
15
|
-
var sum =
|
|
16
|
-
item
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
sum += value;
|
|
22
|
-
});
|
|
23
|
-
if (expression === 'sum') {
|
|
24
|
-
item[dataIndex] = sum;
|
|
25
|
-
} else if (expression === 'average') {
|
|
26
|
-
item[dataIndex] = (sum / item.children.length).toFixed(2);
|
|
27
|
-
}
|
|
30
|
+
if (expression === 'sum') {
|
|
31
|
+
var sum = getSum(item, dataIndex);
|
|
32
|
+
item[dataIndex] = sum;
|
|
33
|
+
} else if (expression === 'average') {
|
|
34
|
+
var _sum = getSum(item, dataIndex);
|
|
35
|
+
item[dataIndex] = (_sum / item.children.length).toFixed(2);
|
|
28
36
|
} else if (expression === 'max') {
|
|
29
37
|
var max = -Number.MAX_VALUE;
|
|
30
38
|
item.children.forEach(function (subItem) {
|
|
@@ -55,6 +63,13 @@ export default function calc(item, needCalcKeys) {
|
|
|
55
63
|
min = 0;
|
|
56
64
|
}
|
|
57
65
|
item[dataIndex] = min;
|
|
66
|
+
} else if (expression === 'percent') {
|
|
67
|
+
var _sum2 = getSum(item, dataIndex);
|
|
68
|
+
history.push({
|
|
69
|
+
item: item,
|
|
70
|
+
dataIndex: dataIndex,
|
|
71
|
+
sum: _sum2
|
|
72
|
+
});
|
|
58
73
|
}
|
|
59
74
|
});
|
|
60
75
|
}
|
package/lib/LmTable/Table.js
CHANGED
|
@@ -914,7 +914,8 @@ var ResetTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
914
914
|
return {
|
|
915
915
|
record: record,
|
|
916
916
|
col: col,
|
|
917
|
-
onChangeRecord: function onChangeRecord() {
|
|
917
|
+
onChangeRecord: function onChangeRecord(dfs, dataIndex, value) {
|
|
918
|
+
dfs(dataSource, dataIndex, value);
|
|
918
919
|
update();
|
|
919
920
|
}
|
|
920
921
|
};
|
|
@@ -20,18 +20,37 @@ var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
var Option = _Select.default.Option;
|
|
23
|
-
var dfs = function dfs(
|
|
23
|
+
var dfs = function dfs(dataSource, dataIndex, expression) {
|
|
24
24
|
var average = function average(arr) {
|
|
25
|
+
var history = [];
|
|
25
26
|
arr === null || arr === void 0 ? void 0 : arr.forEach(function (item) {
|
|
26
27
|
if (item === null || item === void 0 ? void 0 : item.children) {
|
|
27
28
|
average(item === null || item === void 0 ? void 0 : item.children);
|
|
28
29
|
}
|
|
29
|
-
(0, _expression.default)(item, [[dataIndex, expression]]);
|
|
30
|
+
(0, _expression.default)(item, [[dataIndex, expression]], history);
|
|
30
31
|
});
|
|
32
|
+
if (history && history.length) {
|
|
33
|
+
var sum = 0;
|
|
34
|
+
history.forEach(function (h) {
|
|
35
|
+
sum += h.sum;
|
|
36
|
+
});
|
|
37
|
+
history.forEach(function (h) {
|
|
38
|
+
if (sum < 0.000001) {
|
|
39
|
+
sum = 0;
|
|
40
|
+
h.item[h.dataIndex] = '0%';
|
|
41
|
+
} else {
|
|
42
|
+
h.item[h.dataIndex] = (h.sum / sum * 100).toFixed(2) + '%';
|
|
43
|
+
}
|
|
44
|
+
h.item["".concat(h.dataIndex, "_sum")] = sum;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
31
47
|
};
|
|
32
|
-
average(
|
|
48
|
+
average(dataSource);
|
|
33
49
|
};
|
|
34
50
|
var strategy = [{
|
|
51
|
+
value: 'percent',
|
|
52
|
+
label: '百分比'
|
|
53
|
+
}, {
|
|
35
54
|
value: 'average',
|
|
36
55
|
label: '平均值'
|
|
37
56
|
}, {
|
|
@@ -47,11 +66,12 @@ var strategy = [{
|
|
|
47
66
|
var CalcExpression = function CalcExpression(props) {
|
|
48
67
|
var record = props.record,
|
|
49
68
|
col = props.col,
|
|
69
|
+
columns = props.columns,
|
|
50
70
|
children = props.children,
|
|
51
71
|
onChangeRecord = props.onChangeRecord,
|
|
52
72
|
rest = __rest(props
|
|
53
73
|
// 列参数
|
|
54
|
-
, ["record", "col", "children", "onChangeRecord"]);
|
|
74
|
+
, ["record", "col", "columns", "children", "onChangeRecord"]);
|
|
55
75
|
// 列参数
|
|
56
76
|
var isShowSelect = false;
|
|
57
77
|
var currentStrategy = [];
|
|
@@ -71,14 +91,18 @@ var CalcExpression = function CalcExpression(props) {
|
|
|
71
91
|
throw Error('no parameter dataIndex');
|
|
72
92
|
}
|
|
73
93
|
if (value) {
|
|
74
|
-
dfs
|
|
94
|
+
onChangeRecord(dfs, col.dataIndex, value);
|
|
75
95
|
} else {
|
|
76
|
-
(
|
|
96
|
+
onChangeRecord(_expression.reset, col.dataIndex, value);
|
|
77
97
|
}
|
|
78
|
-
onChangeRecord(record);
|
|
79
98
|
};
|
|
80
99
|
if (record && record._group && isShowSelect && (col === null || col === void 0 ? void 0 : col.dataIndex)) {
|
|
81
|
-
return /*#__PURE__*/_react.default.createElement("td", Object.assign({}, rest),
|
|
100
|
+
return /*#__PURE__*/_react.default.createElement("td", Object.assign({}, rest), /*#__PURE__*/_react.default.createElement("div", {
|
|
101
|
+
style: {
|
|
102
|
+
display: 'flex',
|
|
103
|
+
alignItems: 'center'
|
|
104
|
+
}
|
|
105
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, record[col.dataIndex]), /*#__PURE__*/_react.default.createElement(_Select.default, {
|
|
82
106
|
className: "calc-select",
|
|
83
107
|
value: record["".concat(col.dataIndex, "_exp")],
|
|
84
108
|
size: "small",
|
|
@@ -89,9 +113,10 @@ var CalcExpression = function CalcExpression(props) {
|
|
|
89
113
|
}, currentStrategy.map(function (item) {
|
|
90
114
|
return /*#__PURE__*/_react.default.createElement(Option, {
|
|
91
115
|
className: "calc-option",
|
|
92
|
-
value: item.value
|
|
116
|
+
value: item.value,
|
|
117
|
+
key: item.value
|
|
93
118
|
}, item.label);
|
|
94
|
-
})));
|
|
119
|
+
}))));
|
|
95
120
|
}
|
|
96
121
|
return /*#__PURE__*/_react.default.createElement("td", Object.assign({}, rest), children);
|
|
97
122
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export default function calc(item: any, needCalcKeys: string[][]): void;
|
|
1
|
+
export default function calc(item: any, needCalcKeys: string[][], history: any): void;
|
|
2
2
|
export declare const reset: (arr: any, dataIndex: any) => void;
|
|
@@ -7,8 +7,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = calc;
|
|
8
8
|
exports.reset = void 0;
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
function getSum(item, dataIndex) {
|
|
11
|
+
var sum = 0;
|
|
12
|
+
item.children.forEach(function (subItem) {
|
|
13
|
+
var value;
|
|
14
|
+
if (/\%/.test("".concat(subItem[dataIndex]))) {
|
|
15
|
+
value = Number(subItem["".concat(dataIndex, "_sum")]);
|
|
16
|
+
} else {
|
|
17
|
+
value = Number(subItem[dataIndex]);
|
|
18
|
+
}
|
|
19
|
+
if (Number.isNaN(value)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
sum += value;
|
|
23
|
+
});
|
|
24
|
+
return sum;
|
|
25
|
+
}
|
|
10
26
|
// 分组求和计算
|
|
11
|
-
function calc(item, needCalcKeys) {
|
|
27
|
+
function calc(item, needCalcKeys, history) {
|
|
12
28
|
var _a;
|
|
13
29
|
if ((_a = item === null || item === void 0 ? void 0 : item.children) === null || _a === void 0 ? void 0 : _a.length) {
|
|
14
30
|
needCalcKeys.forEach(function (dkey) {
|
|
@@ -19,20 +35,12 @@ function calc(item, needCalcKeys) {
|
|
|
19
35
|
dataIndex = _dkey[0],
|
|
20
36
|
expression = _dkey[1];
|
|
21
37
|
item["".concat(dataIndex, "_exp")] = expression;
|
|
22
|
-
if (expression === 'sum'
|
|
23
|
-
var sum =
|
|
24
|
-
item
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
sum += value;
|
|
30
|
-
});
|
|
31
|
-
if (expression === 'sum') {
|
|
32
|
-
item[dataIndex] = sum;
|
|
33
|
-
} else if (expression === 'average') {
|
|
34
|
-
item[dataIndex] = (sum / item.children.length).toFixed(2);
|
|
35
|
-
}
|
|
38
|
+
if (expression === 'sum') {
|
|
39
|
+
var sum = getSum(item, dataIndex);
|
|
40
|
+
item[dataIndex] = sum;
|
|
41
|
+
} else if (expression === 'average') {
|
|
42
|
+
var _sum = getSum(item, dataIndex);
|
|
43
|
+
item[dataIndex] = (_sum / item.children.length).toFixed(2);
|
|
36
44
|
} else if (expression === 'max') {
|
|
37
45
|
var max = -Number.MAX_VALUE;
|
|
38
46
|
item.children.forEach(function (subItem) {
|
|
@@ -63,6 +71,13 @@ function calc(item, needCalcKeys) {
|
|
|
63
71
|
min = 0;
|
|
64
72
|
}
|
|
65
73
|
item[dataIndex] = min;
|
|
74
|
+
} else if (expression === 'percent') {
|
|
75
|
+
var _sum2 = getSum(item, dataIndex);
|
|
76
|
+
history.push({
|
|
77
|
+
item: item,
|
|
78
|
+
dataIndex: dataIndex,
|
|
79
|
+
sum: _sum2
|
|
80
|
+
});
|
|
66
81
|
}
|
|
67
82
|
});
|
|
68
83
|
}
|