linkmore-design 1.1.27-beta.1 → 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.
@@ -3,8 +3,6 @@ export interface IProps {
3
3
  record: Record<string, any>;
4
4
  rowKey: string;
5
5
  col: any;
6
- rowIndex: number;
7
- colIndex: number;
8
6
  [key: string]: any;
9
7
  }
10
8
  declare const CalcExpression: React.FC<IProps>;
@@ -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
@@ -223260,12 +223260,13 @@
223260
223260
  };
223261
223261
  }, [items]);
223262
223262
  var isOk = function isOk(active, over) {
223263
+ var _items$row, _items$col;
223263
223264
  var item = filterColumns.find(function (item) {
223264
223265
  return item.title === active.id;
223265
223266
  });
223266
- if (over.id === 'row' || items.row.includes(over.id)) {
223267
+ if (over.id === 'row' || (items === null || items === void 0 ? void 0 : (_items$row = items.row) === null || _items$row === void 0 ? void 0 : _items$row.includes(over.id))) {
223267
223268
  return item && item.rowGroup;
223268
- } else if (over.id === 'col' || items.col.includes(over.id)) {
223269
+ } else if (over.id === 'col' || (items === null || items === void 0 ? void 0 : (_items$col = items.col) === null || _items$col === void 0 ? void 0 : _items$col.includes(over.id))) {
223269
223270
  return item && item.colGroup;
223270
223271
  }
223271
223272
  return true;
@@ -223758,8 +223759,24 @@
223758
223759
  }));
223759
223760
  };
223760
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
+ }
223761
223778
  // 分组求和计算
223762
- function calc(item, needCalcKeys) {
223779
+ function calc(item, needCalcKeys, history) {
223763
223780
  var _item$children;
223764
223781
  if (item === null || item === void 0 ? void 0 : (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) {
223765
223782
  needCalcKeys.forEach(function (dkey) {
@@ -223770,20 +223787,12 @@
223770
223787
  dataIndex = _dkey[0],
223771
223788
  expression = _dkey[1];
223772
223789
  item["".concat(dataIndex, "_exp")] = expression;
223773
- if (expression === 'sum' || expression === 'average') {
223774
- var sum = 0;
223775
- item.children.forEach(function (subItem) {
223776
- var value = Number(subItem[dataIndex]);
223777
- if (Number.isNaN(value)) {
223778
- return;
223779
- }
223780
- sum += value;
223781
- });
223782
- if (expression === 'sum') {
223783
- item[dataIndex] = sum;
223784
- } else if (expression === 'average') {
223785
- item[dataIndex] = (sum / item.children.length).toFixed(2);
223786
- }
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);
223787
223796
  } else if (expression === 'max') {
223788
223797
  var max = -Number.MAX_VALUE;
223789
223798
  item.children.forEach(function (subItem) {
@@ -223814,6 +223823,13 @@
223814
223823
  min = 0;
223815
223824
  }
223816
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
+ });
223817
223833
  }
223818
223834
  });
223819
223835
  }
@@ -223912,20 +223928,35 @@
223912
223928
  LMSelect.Option = Select$1.Option;
223913
223929
  LMSelect.OptGroup = Select$1.OptGroup;
223914
223930
 
223915
- var _excluded$1Z = ["record", "col", "children", "onChangeRecord"];
223931
+ var _excluded$1Z = ["record", "col", "columns", "children", "onChangeRecord"];
223916
223932
  var Option$3 = LMSelect.Option;
223917
- var dfs = function dfs(record, dataIndex, expression) {
223933
+ var dfs = function dfs(dataSource, dataIndex, expression) {
223918
223934
  var average = function average(arr) {
223935
+ var history = [];
223919
223936
  arr === null || arr === void 0 ? void 0 : arr.forEach(function (item) {
223920
223937
  if (item === null || item === void 0 ? void 0 : item.children) {
223921
223938
  average(item === null || item === void 0 ? void 0 : item.children);
223922
223939
  }
223923
- calc(item, [[dataIndex, expression]]);
223940
+ calc(item, [[dataIndex, expression]], history);
223924
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
+ }
223925
223953
  };
223926
- average([record]);
223954
+ average(dataSource);
223927
223955
  };
223928
223956
  var strategy = [{
223957
+ value: 'percent',
223958
+ label: '百分比'
223959
+ }, {
223929
223960
  value: 'average',
223930
223961
  label: '平均值'
223931
223962
  }, {
@@ -223941,6 +223972,7 @@
223941
223972
  var CalcExpression = function CalcExpression(props) {
223942
223973
  var record = props.record,
223943
223974
  col = props.col,
223975
+ columns = props.columns,
223944
223976
  children = props.children,
223945
223977
  onChangeRecord = props.onChangeRecord,
223946
223978
  rest = _objectWithoutProperties$1(props, _excluded$1Z);
@@ -223963,14 +223995,18 @@
223963
223995
  throw Error('no parameter dataIndex');
223964
223996
  }
223965
223997
  if (value) {
223966
- dfs(record, col.dataIndex, value);
223998
+ onChangeRecord(dfs, col.dataIndex, value);
223967
223999
  } else {
223968
- reset([record], col.dataIndex);
224000
+ onChangeRecord(reset, col.dataIndex, value);
223969
224001
  }
223970
- onChangeRecord(record);
223971
224002
  };
223972
224003
  if (record && record._group && isShowSelect && (col === null || col === void 0 ? void 0 : col.dataIndex)) {
223973
- 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, {
223974
224010
  className: "calc-select",
223975
224011
  value: record["".concat(col.dataIndex, "_exp")],
223976
224012
  size: "small",
@@ -223981,7 +224017,8 @@
223981
224017
  }, currentStrategy.map(function (item) {
223982
224018
  return /*#__PURE__*/React__default['default'].createElement(Option$3, {
223983
224019
  className: "calc-option",
223984
- value: item.value
224020
+ value: item.value,
224021
+ key: item.value
223985
224022
  }, item.label);
223986
224023
  })));
223987
224024
  }
@@ -224078,6 +224115,7 @@
224078
224115
  * @param {Array<string>} oGroup 数组,列分组的keys值
224079
224116
  * @param {string} markStr
224080
224117
  * @returns
224118
+ * 2万条数据 393ms
224081
224119
  */
224082
224120
  var groupBy = function groupBy(source, columns, oGroup, markStr) {
224083
224121
  if (!(oGroup === null || oGroup === void 0 ? void 0 : oGroup.length)) {
@@ -224701,7 +224739,13 @@
224701
224739
  function getSortDndColumns(value, _ref2) {
224702
224740
  var columns = _ref2.columns;
224703
224741
  var tableHeader = value.tableHeader;
224704
- var hiddenArr = [].concat(_toConsumableArray$1(value.row), _toConsumableArray$1(value.col)) || [];
224742
+ var hiddenArr = [];
224743
+ if (value.row) {
224744
+ hiddenArr = [].concat(_toConsumableArray$1(hiddenArr), _toConsumableArray$1(value.row));
224745
+ }
224746
+ if (value.col) {
224747
+ hiddenArr = [].concat(_toConsumableArray$1(hiddenArr), _toConsumableArray$1(value.col));
224748
+ }
224705
224749
  if (!tableHeader || !tableHeader.length) {
224706
224750
  return [];
224707
224751
  }
@@ -224775,16 +224819,20 @@
224775
224819
  }, [customizeGroupRowKeys, customizeGroupColKeys]);
224776
224820
  // 初始化
224777
224821
  var defaultItems = {
224778
- row: [],
224779
- col: [],
224780
224822
  tableHeader: []
224781
224823
  };
224824
+ if (openRowGroup) {
224825
+ defaultItems.row = [];
224826
+ }
224827
+ if (openColGroup) {
224828
+ defaultItems.col = [];
224829
+ }
224782
224830
  if (openColGroup || openRowGroup || colSortOpen) {
224783
224831
  treeFind(columns, function (node) {
224784
- if (groupRowKeys.includes(node.dataIndex)) {
224785
- defaultItems.row.push(node.title);
224832
+ if (openRowGroup && groupRowKeys.includes(node.dataIndex)) {
224833
+ defaultItems.row && defaultItems.row.push(node.title);
224786
224834
  } else if (groupColKeys.includes(node.dataIndex)) {
224787
- defaultItems.col.push(node.title);
224835
+ defaultItems.col && defaultItems.col.push(node.title);
224788
224836
  } else {
224789
224837
  defaultItems.tableHeader.push(node.title);
224790
224838
  }
@@ -224808,8 +224856,13 @@
224808
224856
  }, [columns]);
224809
224857
  // 更新
224810
224858
  var updateItems = function updateItems(value, resume) {
224811
- value.row = value.row.filter(Boolean);
224812
- value.col = value.col.filter(Boolean);
224859
+ var _value$col;
224860
+ if (value.row) {
224861
+ value.row = value === null || value === void 0 ? void 0 : value.row.filter(Boolean);
224862
+ }
224863
+ if (value.col) {
224864
+ value.col = value.col.filter(Boolean);
224865
+ }
224813
224866
  if (resume) {
224814
224867
  // 删除
224815
224868
  del$1(value.row, resume);
@@ -224819,7 +224872,7 @@
224819
224872
  });
224820
224873
  }
224821
224874
  // 列分组进行覆盖,只允许存在一个
224822
- if (value.col.length >= 2) {
224875
+ if ((value === null || value === void 0 ? void 0 : (_value$col = value.col) === null || _value$col === void 0 ? void 0 : _value$col.length) >= 2) {
224823
224876
  value.tableHeader = getSortInsert(value.tableHeader, items.col[0], {
224824
224877
  columns: columns
224825
224878
  });
@@ -225763,13 +225816,13 @@
225763
225816
  };
225764
225817
  };
225765
225818
  } else if (openRowGroup) {
225766
- col.onCell = function (record, rowIndex) {
225819
+ col.onCell = function (record) {
225767
225820
  i = _i;
225768
225821
  return {
225769
225822
  record: record,
225770
- rowIndex: rowIndex,
225771
225823
  col: col,
225772
- onChangeRecord: function onChangeRecord() {
225824
+ onChangeRecord: function onChangeRecord(dfs, dataIndex, value) {
225825
+ dfs(dataSource, dataIndex, value);
225773
225826
  update();
225774
225827
  }
225775
225828
  };