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.
@@ -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/dist/index.umd.js CHANGED
@@ -223759,8 +223759,24 @@
223759
223759
  }));
223760
223760
  };
223761
223761
 
223762
+ function getSum(item, dataIndex) {
223763
+ var sum = 0;
223764
+ item.children.forEach(function (subItem) {
223765
+ var value;
223766
+ if (/\%/.test("".concat(subItem[dataIndex]))) {
223767
+ value = Number(subItem["".concat(dataIndex, "_sum")]);
223768
+ } else {
223769
+ value = Number(subItem[dataIndex]);
223770
+ }
223771
+ if (Number.isNaN(value)) {
223772
+ return;
223773
+ }
223774
+ sum += value;
223775
+ });
223776
+ return sum;
223777
+ }
223762
223778
  // 分组求和计算
223763
- function calc(item, needCalcKeys) {
223779
+ function calc(item, needCalcKeys, history) {
223764
223780
  var _item$children;
223765
223781
  if (item === null || item === void 0 ? void 0 : (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) {
223766
223782
  needCalcKeys.forEach(function (dkey) {
@@ -223771,20 +223787,12 @@
223771
223787
  dataIndex = _dkey[0],
223772
223788
  expression = _dkey[1];
223773
223789
  item["".concat(dataIndex, "_exp")] = expression;
223774
- if (expression === 'sum' || expression === 'average') {
223775
- var sum = 0;
223776
- item.children.forEach(function (subItem) {
223777
- var value = Number(subItem[dataIndex]);
223778
- if (Number.isNaN(value)) {
223779
- return;
223780
- }
223781
- sum += value;
223782
- });
223783
- if (expression === 'sum') {
223784
- item[dataIndex] = sum;
223785
- } else if (expression === 'average') {
223786
- item[dataIndex] = (sum / item.children.length).toFixed(2);
223787
- }
223790
+ if (expression === 'sum') {
223791
+ var sum = getSum(item, dataIndex);
223792
+ item[dataIndex] = sum;
223793
+ } else if (expression === 'average') {
223794
+ var _sum = getSum(item, dataIndex);
223795
+ item[dataIndex] = (_sum / item.children.length).toFixed(2);
223788
223796
  } else if (expression === 'max') {
223789
223797
  var max = -Number.MAX_VALUE;
223790
223798
  item.children.forEach(function (subItem) {
@@ -223815,6 +223823,13 @@
223815
223823
  min = 0;
223816
223824
  }
223817
223825
  item[dataIndex] = min;
223826
+ } else if (expression === 'percent') {
223827
+ var _sum2 = getSum(item, dataIndex);
223828
+ history.push({
223829
+ item: item,
223830
+ dataIndex: dataIndex,
223831
+ sum: _sum2
223832
+ });
223818
223833
  }
223819
223834
  });
223820
223835
  }
@@ -223913,20 +223928,35 @@
223913
223928
  LMSelect.Option = Select$1.Option;
223914
223929
  LMSelect.OptGroup = Select$1.OptGroup;
223915
223930
 
223916
- var _excluded$1Z = ["record", "col", "children", "onChangeRecord"];
223931
+ var _excluded$1Z = ["record", "col", "columns", "children", "onChangeRecord"];
223917
223932
  var Option$3 = LMSelect.Option;
223918
- var dfs = function dfs(record, dataIndex, expression) {
223933
+ var dfs = function dfs(dataSource, dataIndex, expression) {
223919
223934
  var average = function average(arr) {
223935
+ var history = [];
223920
223936
  arr === null || arr === void 0 ? void 0 : arr.forEach(function (item) {
223921
223937
  if (item === null || item === void 0 ? void 0 : item.children) {
223922
223938
  average(item === null || item === void 0 ? void 0 : item.children);
223923
223939
  }
223924
- calc(item, [[dataIndex, expression]]);
223940
+ calc(item, [[dataIndex, expression]], history);
223925
223941
  });
223942
+ console.log(history);
223943
+ if (history && history.length) {
223944
+ var sum = 0;
223945
+ history.forEach(function (h) {
223946
+ sum += h.sum;
223947
+ });
223948
+ history.forEach(function (h) {
223949
+ h.item[h.dataIndex] = (h.sum / sum * 100).toFixed(2) + '%';
223950
+ h.item["".concat(h.dataIndex, "_sum")] = sum;
223951
+ });
223952
+ }
223926
223953
  };
223927
- average([record]);
223954
+ average(dataSource);
223928
223955
  };
223929
223956
  var strategy = [{
223957
+ value: 'percent',
223958
+ label: '百分比'
223959
+ }, {
223930
223960
  value: 'average',
223931
223961
  label: '平均值'
223932
223962
  }, {
@@ -223942,6 +223972,7 @@
223942
223972
  var CalcExpression = function CalcExpression(props) {
223943
223973
  var record = props.record,
223944
223974
  col = props.col,
223975
+ columns = props.columns,
223945
223976
  children = props.children,
223946
223977
  onChangeRecord = props.onChangeRecord,
223947
223978
  rest = _objectWithoutProperties$1(props, _excluded$1Z);
@@ -223964,14 +223995,18 @@
223964
223995
  throw Error('no parameter dataIndex');
223965
223996
  }
223966
223997
  if (value) {
223967
- dfs(record, col.dataIndex, value);
223998
+ onChangeRecord(dfs, col.dataIndex, value);
223968
223999
  } else {
223969
- reset([record], col.dataIndex);
224000
+ onChangeRecord(reset, col.dataIndex, value);
223970
224001
  }
223971
- onChangeRecord(record);
223972
224002
  };
223973
224003
  if (record && record._group && isShowSelect && (col === null || col === void 0 ? void 0 : col.dataIndex)) {
223974
- return /*#__PURE__*/React__default['default'].createElement("td", _objectSpread({}, rest), record[col.dataIndex], /*#__PURE__*/React__default['default'].createElement(LMSelect, {
224004
+ return /*#__PURE__*/React__default['default'].createElement("td", _objectSpread(_objectSpread({}, rest), {}, {
224005
+ style: {
224006
+ display: 'flex',
224007
+ alignItems: 'center'
224008
+ }
224009
+ }), /*#__PURE__*/React__default['default'].createElement("span", null, record[col.dataIndex]), /*#__PURE__*/React__default['default'].createElement(LMSelect, {
223975
224010
  className: "calc-select",
223976
224011
  value: record["".concat(col.dataIndex, "_exp")],
223977
224012
  size: "small",
@@ -223982,7 +224017,8 @@
223982
224017
  }, currentStrategy.map(function (item) {
223983
224018
  return /*#__PURE__*/React__default['default'].createElement(Option$3, {
223984
224019
  className: "calc-option",
223985
- value: item.value
224020
+ value: item.value,
224021
+ key: item.value
223986
224022
  }, item.label);
223987
224023
  })));
223988
224024
  }
@@ -225785,7 +225821,8 @@
225785
225821
  return {
225786
225822
  record: record,
225787
225823
  col: col,
225788
- onChangeRecord: function onChangeRecord() {
225824
+ onChangeRecord: function onChangeRecord(dfs, dataIndex, value) {
225825
+ dfs(dataSource, dataIndex, value);
225789
225826
  update();
225790
225827
  }
225791
225828
  };