@lemon-fe/components 1.1.2 → 1.1.3-alpha.0

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.
@@ -19,6 +19,7 @@ export default class DataGrid<TData extends Record<string, any>> extends Compone
19
19
  private searchRef;
20
20
  private prevFocusedCell;
21
21
  private fields;
22
+ private fieldSuffix;
22
23
  static contextType?: React.Context<any> | undefined;
23
24
  static defaultProps: Partial<DataGridProps<any>>;
24
25
  static SummaryFlag: symbol;
@@ -150,6 +150,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
150
150
  _defineProperty(_assertThisInitialized(_this), "searchRef", /*#__PURE__*/createRef());
151
151
  _defineProperty(_assertThisInitialized(_this), "prevFocusedCell", null);
152
152
  _defineProperty(_assertThisInitialized(_this), "fields", []);
153
+ _defineProperty(_assertThisInitialized(_this), "fieldSuffix", /(%)$/);
153
154
  _defineProperty(_assertThisInitialized(_this), "getFieldsSummary", memoizeOne(function (dataSource, fields) {
154
155
  var summaryField = fields.filter(function (field) {
155
156
  return field.summary;
@@ -188,7 +189,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
188
189
  if (summary[field.id] === undefined) {
189
190
  summary[field.id] = new BigNumber(0);
190
191
  }
191
- summary[field.id] = summary[field.id].plus(value);
192
+ summary[field.id] = summary[field.id].plus(typeof value === 'string' ? value.replace(_this.fieldSuffix, '') : value);
192
193
  });
193
194
  });
194
195
  return summary;
@@ -991,12 +992,14 @@ var DataGrid = /*#__PURE__*/function (_Component) {
991
992
  if (suppressFieldValueGetter) {
992
993
  fieldCol.field = field.id;
993
994
  } else {
995
+ var _this5$fieldSuffix$ex;
994
996
  /**
995
997
  * 预校验是否可以进行四则运算,可能会有边界情况没考虑到
996
998
  */
997
999
  var scopeMap = {};
998
1000
  var reg = /\$\{([^{}]+)\}/g;
999
- var expression = field.expression.replace(reg, function (match, p1) {
1001
+ var expressionSuffix = ((_this5$fieldSuffix$ex = _this5.fieldSuffix.exec(field.expression)) === null || _this5$fieldSuffix$ex === void 0 ? void 0 : _this5$fieldSuffix$ex[1]) || '';
1002
+ var expression = field.expression.replace(_this5.fieldSuffix, '').replace(reg, function (match, p1) {
1000
1003
  if (p1) {
1001
1004
  var mapKey = "a".concat(Object.keys(scopeMap).length);
1002
1005
  scopeMap[mapKey] = p1;
@@ -1066,7 +1069,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1066
1069
  return null;
1067
1070
  }
1068
1071
  } else {
1069
- return field.expression.replace(reg, function (match, p1) {
1072
+ return field.expression.replace(_this5.fieldSuffix, '').replace(reg, function (match, p1) {
1070
1073
  if (p1) {
1071
1074
  return getValue(p1) || '';
1072
1075
  }
@@ -1077,9 +1080,16 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1077
1080
  return null;
1078
1081
  };
1079
1082
  fieldCol.valueFormatter = function (params) {
1080
- if (Number.isNaN(params.value) || typeof params.value === 'number' && !Number.isFinite(params.value) || BigNumber.isBigNumber(params.value) && (params.value.isNaN() || !params.value.isFinite())) {
1083
+ if (typeof params.value === 'number' && (Number.isNaN(params.value) || !Number.isFinite(params.value)) || BigNumber.isBigNumber(params.value) && (params.value.isNaN() || !params.value.isFinite())) {
1081
1084
  return '-';
1082
1085
  }
1086
+ if (params.value !== undefined && params.value !== null) {
1087
+ var val = params.value;
1088
+ if (typeof val === 'number' || BigNumber.isBigNumber(val)) {
1089
+ val = new BigNumber(val).dp(2);
1090
+ }
1091
+ return "".concat(val).concat(expressionSuffix);
1092
+ }
1083
1093
  return params.value;
1084
1094
  };
1085
1095
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/components",
3
- "version": "1.1.2",
3
+ "version": "1.1.3-alpha.0",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "",
6
6
  "license": "ISC",
@@ -62,5 +62,5 @@
62
62
  "publishConfig": {
63
63
  "registry": "https://registry.npmjs.org"
64
64
  },
65
- "gitHead": "37ad5368a2c745b0bea0bfe9e5ad2c4aeffe1635"
65
+ "gitHead": "53c287f2fc2ebd1251b38ac587eab8f648f73c85"
66
66
  }