linkmore-design 1.1.27-beta.2 → 1.1.27-beta.3

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.
@@ -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,33 @@ 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(record, dataIndex, expression) {
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
+ console.log(history);
25
+ if (history && history.length) {
26
+ var sum = 0;
27
+ history.forEach(function (h) {
28
+ sum += h.sum;
29
+ });
30
+ history.forEach(function (h) {
31
+ h.item[h.dataIndex] = (h.sum / sum * 100).toFixed(2) + '%';
32
+ h.item["".concat(h.dataIndex, "_sum")] = sum;
33
+ });
34
+ }
23
35
  };
24
- average([record]);
36
+ average(dataSource);
25
37
  };
26
38
  var strategy = [{
39
+ value: 'percent',
40
+ label: '百分比'
41
+ }, {
27
42
  value: 'average',
28
43
  label: '平均值'
29
44
  }, {
@@ -39,11 +54,12 @@ var strategy = [{
39
54
  var CalcExpression = function CalcExpression(props) {
40
55
  var record = props.record,
41
56
  col = props.col,
57
+ columns = props.columns,
42
58
  children = props.children,
43
59
  onChangeRecord = props.onChangeRecord,
44
60
  rest = __rest(props
45
61
  // 列参数
46
- , ["record", "col", "children", "onChangeRecord"]);
62
+ , ["record", "col", "columns", "children", "onChangeRecord"]);
47
63
  // 列参数
48
64
  var isShowSelect = false;
49
65
  var currentStrategy = [];
@@ -63,14 +79,18 @@ var CalcExpression = function CalcExpression(props) {
63
79
  throw Error('no parameter dataIndex');
64
80
  }
65
81
  if (value) {
66
- dfs(record, col.dataIndex, value);
82
+ onChangeRecord(dfs, col.dataIndex, value);
67
83
  } else {
68
- reset([record], col.dataIndex);
84
+ onChangeRecord(reset, col.dataIndex, value);
69
85
  }
70
- onChangeRecord(record);
71
86
  };
72
87
  if (record && record._group && isShowSelect && (col === null || col === void 0 ? void 0 : col.dataIndex)) {
73
- return /*#__PURE__*/React.createElement("td", Object.assign({}, rest), record[col.dataIndex], /*#__PURE__*/React.createElement(Select, {
88
+ return /*#__PURE__*/React.createElement("td", Object.assign({}, rest, {
89
+ style: {
90
+ display: 'flex',
91
+ alignItems: 'center'
92
+ }
93
+ }), /*#__PURE__*/React.createElement("span", null, record[col.dataIndex]), /*#__PURE__*/React.createElement(Select, {
74
94
  className: "calc-select",
75
95
  value: record["".concat(col.dataIndex, "_exp")],
76
96
  size: "small",
@@ -81,7 +101,8 @@ var CalcExpression = function CalcExpression(props) {
81
101
  }, currentStrategy.map(function (item) {
82
102
  return /*#__PURE__*/React.createElement(Option, {
83
103
  className: "calc-option",
84
- value: item.value
104
+ value: item.value,
105
+ key: item.value
85
106
  }, item.label);
86
107
  })));
87
108
  }
@@ -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;
@@ -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' || expression === 'average') {
15
- var sum = 0;
16
- item.children.forEach(function (subItem) {
17
- var value = Number(subItem[dataIndex]);
18
- if (Number.isNaN(value)) {
19
- return;
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
  }
@@ -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,33 @@ 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(record, dataIndex, expression) {
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
+ console.log(history);
33
+ if (history && history.length) {
34
+ var sum = 0;
35
+ history.forEach(function (h) {
36
+ sum += h.sum;
37
+ });
38
+ history.forEach(function (h) {
39
+ h.item[h.dataIndex] = (h.sum / sum * 100).toFixed(2) + '%';
40
+ h.item["".concat(h.dataIndex, "_sum")] = sum;
41
+ });
42
+ }
31
43
  };
32
- average([record]);
44
+ average(dataSource);
33
45
  };
34
46
  var strategy = [{
47
+ value: 'percent',
48
+ label: '百分比'
49
+ }, {
35
50
  value: 'average',
36
51
  label: '平均值'
37
52
  }, {
@@ -47,11 +62,12 @@ var strategy = [{
47
62
  var CalcExpression = function CalcExpression(props) {
48
63
  var record = props.record,
49
64
  col = props.col,
65
+ columns = props.columns,
50
66
  children = props.children,
51
67
  onChangeRecord = props.onChangeRecord,
52
68
  rest = __rest(props
53
69
  // 列参数
54
- , ["record", "col", "children", "onChangeRecord"]);
70
+ , ["record", "col", "columns", "children", "onChangeRecord"]);
55
71
  // 列参数
56
72
  var isShowSelect = false;
57
73
  var currentStrategy = [];
@@ -71,14 +87,18 @@ var CalcExpression = function CalcExpression(props) {
71
87
  throw Error('no parameter dataIndex');
72
88
  }
73
89
  if (value) {
74
- dfs(record, col.dataIndex, value);
90
+ onChangeRecord(dfs, col.dataIndex, value);
75
91
  } else {
76
- (0, _expression.reset)([record], col.dataIndex);
92
+ onChangeRecord(_expression.reset, col.dataIndex, value);
77
93
  }
78
- onChangeRecord(record);
79
94
  };
80
95
  if (record && record._group && isShowSelect && (col === null || col === void 0 ? void 0 : col.dataIndex)) {
81
- return /*#__PURE__*/_react.default.createElement("td", Object.assign({}, rest), record[col.dataIndex], /*#__PURE__*/_react.default.createElement(_Select.default, {
96
+ return /*#__PURE__*/_react.default.createElement("td", Object.assign({}, rest, {
97
+ style: {
98
+ display: 'flex',
99
+ alignItems: 'center'
100
+ }
101
+ }), /*#__PURE__*/_react.default.createElement("span", null, record[col.dataIndex]), /*#__PURE__*/_react.default.createElement(_Select.default, {
82
102
  className: "calc-select",
83
103
  value: record["".concat(col.dataIndex, "_exp")],
84
104
  size: "small",
@@ -89,7 +109,8 @@ var CalcExpression = function CalcExpression(props) {
89
109
  }, currentStrategy.map(function (item) {
90
110
  return /*#__PURE__*/_react.default.createElement(Option, {
91
111
  className: "calc-option",
92
- value: item.value
112
+ value: item.value,
113
+ key: item.value
93
114
  }, item.label);
94
115
  })));
95
116
  }
@@ -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' || expression === 'average') {
23
- var sum = 0;
24
- item.children.forEach(function (subItem) {
25
- var value = Number(subItem[dataIndex]);
26
- if (Number.isNaN(value)) {
27
- return;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkmore-design",
3
- "version": "1.1.27-beta.2",
3
+ "version": "1.1.27-beta.3",
4
4
  "author": {
5
5
  "name": "nowthen",
6
6
  "email": "rnlvwyx@gmail.com"