@lemon-fe/components 1.2.8 → 1.2.9-alpha.1

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.
@@ -50,16 +50,11 @@ export function useDataGrid() {
50
50
  }
51
51
  if (ref.current !== null) {
52
52
  var grid = ref.current;
53
- var delay = function delay() {
53
+ grid.afterReady(function () {
54
54
  if (mounted.current) {
55
- if (grid.ready()) {
56
- cb(grid);
57
- } else {
58
- requestAnimationFrame(delay);
59
- }
55
+ cb(grid);
60
56
  }
61
- };
62
- delay();
57
+ });
63
58
  }
64
59
  };
65
60
  return useMemo(function () {
@@ -45,6 +45,7 @@ declare class InternalDataGrid<TData extends Record<string, any>> extends Compon
45
45
  private prevFocusedCell;
46
46
  private fields;
47
47
  private fieldSuffix;
48
+ private customColumnData;
48
49
  constructor(props: InternaleDataGridProps<TData>);
49
50
  setField(field: FieldCol): void;
50
51
  getField(id: string): FieldCol | undefined;
@@ -69,6 +70,13 @@ declare class InternalDataGrid<TData extends Record<string, any>> extends Compon
69
70
  private isPreserveSelected;
70
71
  private updateRowData;
71
72
  private getSummaryRowData;
73
+ private loadingTiming;
74
+ /**
75
+ *
76
+ * @param flag
77
+ * @param ignoreClientMode 为了解决明细页面出现2个loading动画的问题,非远程模式加载列定制数据的时候暂定出现表格内部加载动画
78
+ */
79
+ private loadingChange;
72
80
  private getDataFromServer;
73
81
  private pagination;
74
82
  private init;
@@ -161,6 +161,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
161
161
  _inherits(InternalDataGrid, _Component);
162
162
  var _super = _createSuper(InternalDataGrid);
163
163
  function InternalDataGrid(props) {
164
+ var _props$customColumnPa, _props$customColumnPa2;
164
165
  var _this;
165
166
  _classCallCheck(this, InternalDataGrid);
166
167
  _this = _super.call(this, props);
@@ -191,6 +192,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
191
192
  _defineProperty(_assertThisInitialized(_this), "prevFocusedCell", null);
192
193
  _defineProperty(_assertThisInitialized(_this), "fields", []);
193
194
  _defineProperty(_assertThisInitialized(_this), "fieldSuffix", /(%)$/);
195
+ _defineProperty(_assertThisInitialized(_this), "customColumnData", null);
194
196
  _defineProperty(_assertThisInitialized(_this), "getFieldsSummary", memoizeOne(function (dataSource, fields) {
195
197
  var summaryField = fields.filter(function (field) {
196
198
  return field.summary;
@@ -238,21 +240,46 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
238
240
  });
239
241
  return summary;
240
242
  }));
243
+ _defineProperty(_assertThisInitialized(_this), "loadingTiming", null);
241
244
  _defineProperty(_assertThisInitialized(_this), "init", /*#__PURE__*/function () {
242
245
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(args) {
243
- var api, columnApi, onGridReady;
246
+ var api, columnApi, _this$props, onGridReady, autoLoad, customColumnData, state, data;
244
247
  return _regeneratorRuntime().wrap(function _callee$(_context) {
245
248
  while (1) switch (_context.prev = _context.next) {
246
249
  case 0:
247
250
  api = args.api, columnApi = args.columnApi;
248
251
  _this.api = api;
249
252
  _this.columnApi = columnApi;
250
- _this.isReady = true;
251
- _this.clearReadyQueue();
252
- onGridReady = _this.props.onGridReady;
253
+ _this$props = _this.props, onGridReady = _this$props.onGridReady, autoLoad = _this$props.autoLoad;
253
254
  if (onGridReady !== undefined) {
254
255
  onGridReady(args);
255
256
  }
257
+ _context.next = 7;
258
+ return _this.customColumnData;
259
+ case 7:
260
+ customColumnData = _context.sent;
261
+ if (customColumnData) {
262
+ try {
263
+ data = customColumnData;
264
+ if (data) {
265
+ _this.fields = data.fields;
266
+ state = data.columState;
267
+ }
268
+ } catch (err) {
269
+ console.log('获取列定制失败', err.message);
270
+ }
271
+ _this.updateColumnDefs(state, true);
272
+ } else {
273
+ _this.updateColumnDefs();
274
+ }
275
+ _this.isReady = true;
276
+ _this.syncColRender();
277
+ _this.syncSelection();
278
+ if (_this.isClientMode()) {
279
+ _this.syncRowData();
280
+ } else if (autoLoad) {
281
+ _this.getDataFromServer();
282
+ }
256
283
  api.addEventListener('sortChanged', function () {
257
284
  if (!_this.isClientMode()) {
258
285
  _this.getDataFromServer();
@@ -280,9 +307,10 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
280
307
  });
281
308
  api.addEventListener('selectionChanged', function () {
282
309
  var rowSelection = _this.props.rowSelection;
283
- if (_this.selected.isDirty() && rowSelection !== undefined && rowSelection.onChange !== undefined) {
310
+ if (_this.selected.isDirty()) {
311
+ var _rowSelection$onChang;
284
312
  var result = _this.selected.flush();
285
- rowSelection.onChange(result[0], result[1].filter(Boolean));
313
+ rowSelection === null || rowSelection === void 0 || (_rowSelection$onChang = rowSelection.onChange) === null || _rowSelection$onChang === void 0 || _rowSelection$onChang.call(rowSelection, result[0], result[1].filter(Boolean));
286
314
  }
287
315
  });
288
316
  api.addEventListener('paginationChanged', function () {
@@ -292,7 +320,8 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
292
320
  });
293
321
  }
294
322
  });
295
- case 11:
323
+ _this.clearReadyQueue();
324
+ case 18:
296
325
  case "end":
297
326
  return _context.stop();
298
327
  }
@@ -313,9 +342,9 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
313
342
  return String(result !== null && result !== void 0 ? result : '').toString();
314
343
  });
315
344
  _defineProperty(_assertThisInitialized(_this), "cellValueChanged", function (evt) {
316
- var _this$props = _this.props,
317
- onDataSourceChange = _this$props.onDataSourceChange,
318
- onCellValueChanged = _this$props.onCellValueChanged;
345
+ var _this$props2 = _this.props,
346
+ onDataSourceChange = _this$props2.onDataSourceChange,
347
+ onCellValueChanged = _this$props2.onCellValueChanged;
319
348
  if (onCellValueChanged) {
320
349
  onCellValueChanged(evt);
321
350
  }
@@ -333,9 +362,9 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
333
362
  if (!_this.isReady) {
334
363
  return;
335
364
  }
336
- var _this$props2 = _this.props,
337
- onDataSourceChange = _this$props2.onDataSourceChange,
338
- onRowDataUpdated = _this$props2.onRowDataUpdated;
365
+ var _this$props3 = _this.props,
366
+ onDataSourceChange = _this$props3.onDataSourceChange,
367
+ onRowDataUpdated = _this$props3.onRowDataUpdated;
339
368
  var data = [];
340
369
  if (onRowDataUpdated !== undefined) {
341
370
  onRowDataUpdated(evt);
@@ -478,12 +507,8 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
478
507
  context: props.context,
479
508
  grid: _assertThisInitialized(_this)
480
509
  });
481
- var _props$rowSelection = props.rowSelection,
482
- _props$rowSelection2 = _props$rowSelection === void 0 ? {} : _props$rowSelection,
483
- _props$rowSelection2$ = _props$rowSelection2.selectedRowKeys,
484
- selectedRowKeys = _props$rowSelection2$ === void 0 ? [] : _props$rowSelection2$;
485
- _this.selected = new Selection(selectedRowKeys);
486
- _this.syncColRender();
510
+ _this.selected = new Selection([]);
511
+ _this.customColumnData = ((_props$customColumnPa = props.customColumnPanelStorage) === null || _props$customColumnPa === void 0 || (_props$customColumnPa2 = _props$customColumnPa.get) === null || _props$customColumnPa2 === void 0 ? void 0 : _props$customColumnPa2.call(_props$customColumnPa)) || null;
487
512
  return _this;
488
513
  }
489
514
  _createClass(InternalDataGrid, [{
@@ -566,9 +591,9 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
566
591
  }, {
567
592
  key: "getPagination",
568
593
  value: function getPagination() {
569
- var _this$props3 = this.props,
570
- pagination = _this$props3.pagination,
571
- fetch = _this$props3.fetch;
594
+ var _this$props4 = this.props,
595
+ pagination = _this$props4.pagination,
596
+ fetch = _this$props4.fetch;
572
597
  var page = 1;
573
598
  var pageSize = 50;
574
599
  var total = 0;
@@ -597,25 +622,30 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
597
622
  }, {
598
623
  key: "componentDidUpdate",
599
624
  value: function componentDidUpdate(prevProps) {
600
- var _this2 = this,
601
- _prevProps$rowSelecti;
602
- var _this$props4 = this.props,
603
- columns = _this$props4.columns,
604
- rowSelection = _this$props4.rowSelection,
605
- dataSource = _this$props4.dataSource,
606
- context = _this$props4.context;
625
+ var _prevProps$rowSelecti;
626
+ var _this$props5 = this.props,
627
+ columns = _this$props5.columns,
628
+ rowSelection = _this$props5.rowSelection,
629
+ dataSource = _this$props5.dataSource,
630
+ context = _this$props5.context;
631
+ if (!shallowEqual(context, prevProps.context)) {
632
+ this.store.setState({
633
+ context: context
634
+ });
635
+ }
636
+ if (!this.isReady) {
637
+ return;
638
+ }
607
639
  if (columns !== prevProps.columns) {
608
640
  this.syncColRender();
609
- this.afterReady(function () {
610
- _this2.updateColumnDefs(_this2.columnApi.getColumnState());
611
- if (_this2.fields.length > 0) {
612
- _this2.api.refreshCells({
613
- columns: _this2.fields.map(function (item) {
614
- return item.id;
615
- })
616
- });
617
- }
618
- });
641
+ this.updateColumnDefs(this.columnApi.getColumnState());
642
+ if (this.fields.length > 0) {
643
+ this.api.refreshCells({
644
+ columns: this.fields.map(function (item) {
645
+ return item.id;
646
+ })
647
+ });
648
+ }
619
649
  }
620
650
  if ((rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys) !== ((_prevProps$rowSelecti = prevProps.rowSelection) === null || _prevProps$rowSelecti === void 0 ? void 0 : _prevProps$rowSelecti.selectedRowKeys)) {
621
651
  this.syncSelection();
@@ -623,11 +653,6 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
623
653
  if (dataSource !== prevProps.dataSource) {
624
654
  this.syncRowData();
625
655
  }
626
- if (!shallowEqual(context, prevProps.context)) {
627
- this.store.setState({
628
- context: context
629
- });
630
- }
631
656
  }
632
657
  }, {
633
658
  key: "componentWillUnmount",
@@ -639,50 +664,22 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
639
664
  key: "componentDidMount",
640
665
  value: function () {
641
666
  var _componentDidMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
642
- var _this$props5, customColumnPanelStorage, autoLoad, state, data;
643
667
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
644
668
  while (1) switch (_context3.prev = _context3.next) {
645
669
  case 0:
646
670
  window.addEventListener('blur', this.handleFocus);
671
+ this.loadingChange(true, true);
647
672
 
648
- /** 加载定制列数据如果接口很慢的话,可能会存在列更新的时序问题,尝试过阻塞其他操作,但在明细页面依旧会出现2个加载动画的情况。未来尝试解决 */
649
- _this$props5 = this.props, customColumnPanelStorage = _this$props5.customColumnPanelStorage, autoLoad = _this$props5.autoLoad;
650
- if (!customColumnPanelStorage) {
651
- _context3.next = 16;
652
- break;
653
- }
654
- _context3.prev = 3;
655
- _context3.next = 6;
656
- return customColumnPanelStorage.get();
657
- case 6:
658
- data = _context3.sent;
659
- if (data) {
660
- this.fields = data.fields;
661
- state = data.columState;
662
- }
663
- _context3.next = 13;
664
- break;
665
- case 10:
666
- _context3.prev = 10;
667
- _context3.t0 = _context3["catch"](3);
668
- console.log('获取列定制失败', _context3.t0.message);
669
- case 13:
670
- this.updateColumnDefs(state, true);
671
- _context3.next = 17;
672
- break;
673
- case 16:
674
- this.updateColumnDefs();
675
- case 17:
676
- if (this.isClientMode()) {
677
- this.syncRowData();
678
- } else if (autoLoad) {
679
- this.getDataFromServer();
680
- }
681
- case 18:
673
+ // 放在componentDidMount 执行时间比onGridReady早
674
+ _context3.next = 4;
675
+ return this.customColumnData;
676
+ case 4:
677
+ this.loadingChange(false, true);
678
+ case 5:
682
679
  case "end":
683
680
  return _context3.stop();
684
681
  }
685
- }, _callee3, this, [[3, 10]]);
682
+ }, _callee3, this);
686
683
  }));
687
684
  function componentDidMount() {
688
685
  return _componentDidMount.apply(this, arguments);
@@ -736,34 +733,32 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
736
733
  }, {
737
734
  key: "syncSelection",
738
735
  value: function syncSelection() {
739
- var _this3 = this;
740
- this.afterReady(function () {
741
- var _this3$props$rowSelec = _this3.props.rowSelection,
742
- _this3$props$rowSelec2 = _this3$props$rowSelec === void 0 ? {} : _this3$props$rowSelec,
743
- selectedRowKeys = _this3$props$rowSelec2.selectedRowKeys;
744
- if (selectedRowKeys !== undefined && !_this3.selected.isSameKeys(selectedRowKeys)) {
745
- var newSelected = new Map();
746
- _this3.selected.forEach(function (id) {
747
- var node = _this3.api.getRowNode(id);
748
- if (node !== undefined) {
749
- node.setSelected(false, false, true);
750
- }
751
- });
752
- selectedRowKeys.forEach(function (id) {
753
- var node = _this3.api.getRowNode(id);
754
- var data;
755
- if (node !== undefined) {
756
- node.setSelected(true, false, true);
757
- data = node.data;
758
- }
759
- newSelected.set(id, data || _this3.selected.get(id) || null);
760
- });
761
- _this3.selected.clone(newSelected);
762
- _this3.api.dispatchEvent({
763
- type: 'selectionChanged'
764
- });
765
- }
766
- });
736
+ var _this2 = this;
737
+ var _this$props$rowSelect = this.props.rowSelection,
738
+ _this$props$rowSelect2 = _this$props$rowSelect === void 0 ? {} : _this$props$rowSelect,
739
+ selectedRowKeys = _this$props$rowSelect2.selectedRowKeys;
740
+ if (selectedRowKeys !== undefined && !this.selected.isSameKeys(selectedRowKeys)) {
741
+ var newSelected = new Map();
742
+ this.selected.forEach(function (id) {
743
+ var node = _this2.api.getRowNode(id);
744
+ if (node !== undefined) {
745
+ node.setSelected(false, false, true);
746
+ }
747
+ });
748
+ selectedRowKeys.forEach(function (id) {
749
+ var node = _this2.api.getRowNode(id);
750
+ var data;
751
+ if (node !== undefined) {
752
+ node.setSelected(true, false, true);
753
+ data = node.data;
754
+ }
755
+ newSelected.set(id, data || _this2.selected.get(id) || null);
756
+ });
757
+ this.selected.clone(newSelected);
758
+ this.api.dispatchEvent({
759
+ type: 'selectionChanged'
760
+ });
761
+ }
767
762
  }
768
763
  }, {
769
764
  key: "syncRowData",
@@ -776,48 +771,45 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
776
771
  }, {
777
772
  key: "updateColumnDefs",
778
773
  value: function updateColumnDefs(state) {
779
- var _this4 = this;
780
774
  var allState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
781
- this.afterReady(function () {
782
- var _this4$getColumnDefs = _this4.getColumnDefs(),
783
- _this4$getColumnDefs2 = _slicedToArray(_this4$getColumnDefs, 2),
784
- defs = _this4$getColumnDefs2[0],
785
- leafColIds = _this4$getColumnDefs2[1];
786
- _this4.api.setColumnDefs(defs);
787
- if (state) {
788
- /**
789
- * 表格初始化列抖动问题:先调用setColumnDefs,后applyColumnState,会产生列移动动画,所以先禁用列移动的动画
790
- */
791
- _this4.api.__setProperty('suppressColumnMoveAnimation', true);
792
- var newState = _toConsumableArray(state);
793
- leafColIds.forEach(function (colId, index) {
794
- if (!colId) {
795
- return;
796
- }
797
- var idx = state.findIndex(function (item) {
798
- return item.colId === colId;
799
- });
800
- if (idx < 0) {
801
- newState.splice(index, 0, {
802
- colId: colId
803
- });
804
- }
775
+ var _this$getColumnDefs3 = this.getColumnDefs(),
776
+ _this$getColumnDefs4 = _slicedToArray(_this$getColumnDefs3, 2),
777
+ defs = _this$getColumnDefs4[0],
778
+ leafColIds = _this$getColumnDefs4[1];
779
+ this.api.setColumnDefs(defs);
780
+ if (state) {
781
+ /**
782
+ * 表格初始化列抖动问题:先调用setColumnDefs,后applyColumnState,会产生列移动动画,所以先禁用列移动的动画
783
+ */
784
+ this.api.__setProperty('suppressColumnMoveAnimation', true);
785
+ var newState = _toConsumableArray(state);
786
+ leafColIds.forEach(function (colId, index) {
787
+ if (!colId) {
788
+ return;
789
+ }
790
+ var idx = state.findIndex(function (item) {
791
+ return item.colId === colId;
805
792
  });
793
+ if (idx < 0) {
794
+ newState.splice(index, 0, {
795
+ colId: colId
796
+ });
797
+ }
798
+ });
806
799
 
807
- /**
808
- * 初始化的时候,需要使用存储的columnState,不仅仅是顺序,其他情况由于在defs里已经有列的状态控制了
809
- */
810
- _this4.columnApi.applyColumnState({
811
- state: allState ? newState : newState.map(function (item) {
812
- return {
813
- colId: item.colId
814
- };
815
- }),
816
- applyOrder: true
817
- });
818
- _this4.api.__setProperty('suppressColumnMoveAnimation', !!_this4.props.suppressColumnMoveAnimation);
819
- }
820
- });
800
+ /**
801
+ * 初始化的时候,需要使用存储的columnState,不仅仅是顺序,其他情况由于在defs里已经有列的状态控制了
802
+ */
803
+ this.columnApi.applyColumnState({
804
+ state: allState ? newState : newState.map(function (item) {
805
+ return {
806
+ colId: item.colId
807
+ };
808
+ }),
809
+ applyOrder: true
810
+ });
811
+ this.api.__setProperty('suppressColumnMoveAnimation', !!this.props.suppressColumnMoveAnimation);
812
+ }
821
813
  }
822
814
  }, {
823
815
  key: "getFullColumnDef",
@@ -848,7 +840,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
848
840
  }, {
849
841
  key: "getColumnDefs",
850
842
  value: function getColumnDefs() {
851
- var _this5 = this,
843
+ var _this3 = this,
852
844
  _this$props$customCol;
853
845
  var _this$props7 = this.props,
854
846
  _this$props7$columns = _this$props7.columns,
@@ -874,7 +866,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
874
866
  if (field !== undefined) {
875
867
  opts.field = getColField(item);
876
868
  }
877
- var def = _this5.getFullColumnDef(opts);
869
+ var def = _this3.getFullColumnDef(opts);
878
870
 
879
871
  /** 部分列由于使用type 可能存在colId以及field都不存在, maintainColumnOrder下updateColumnDefs有问题,故从merge后的def中提取field或者colId */
880
872
  opts.colId = def.colId || def.field;
@@ -1033,14 +1025,14 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1033
1025
  if (suppressFieldValueGetter) {
1034
1026
  fieldCol.field = field.id;
1035
1027
  } else {
1036
- var _this5$fieldSuffix$ex;
1028
+ var _this3$fieldSuffix$ex;
1037
1029
  /**
1038
1030
  * 预校验是否可以进行四则运算,可能会有边界情况没考虑到
1039
1031
  */
1040
1032
  var scopeMap = {};
1041
1033
  var reg = /\$\{([^{}]+)\}/g;
1042
- var expressionSuffix = ((_this5$fieldSuffix$ex = _this5.fieldSuffix.exec(field.expression)) === null || _this5$fieldSuffix$ex === void 0 ? void 0 : _this5$fieldSuffix$ex[1]) || '';
1043
- var expression = field.expression.replace(_this5.fieldSuffix, '').replace(reg, function (match, p1) {
1034
+ var expressionSuffix = ((_this3$fieldSuffix$ex = _this3.fieldSuffix.exec(field.expression)) === null || _this3$fieldSuffix$ex === void 0 ? void 0 : _this3$fieldSuffix$ex[1]) || '';
1035
+ var expression = field.expression.replace(_this3.fieldSuffix, '').replace(reg, function (match, p1) {
1044
1036
  if (p1) {
1045
1037
  var mapKey = "a".concat(Object.keys(scopeMap).length);
1046
1038
  scopeMap[mapKey] = p1;
@@ -1077,7 +1069,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1077
1069
  if (isSummaryRow({
1078
1070
  node: node
1079
1071
  }) && field.summaryType === 1) {
1080
- var summary = _this5.getFieldsSummary(_this5.dataSource, _this5.fields);
1072
+ var summary = _this3.getFieldsSummary(_this3.dataSource, _this3.fields);
1081
1073
  return get(summary, field.id);
1082
1074
  }
1083
1075
  var getValue = function getValue(colId) {
@@ -1110,7 +1102,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1110
1102
  return null;
1111
1103
  }
1112
1104
  } else {
1113
- return field.expression.replace(_this5.fieldSuffix, '').replace(reg, function (match, p1) {
1105
+ return field.expression.replace(_this3.fieldSuffix, '').replace(reg, function (match, p1) {
1114
1106
  if (p1) {
1115
1107
  return getValue(p1) || '';
1116
1108
  }
@@ -1217,51 +1209,49 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1217
1209
  }, {
1218
1210
  key: "updateRowData",
1219
1211
  value: function updateRowData() {
1220
- var _this6 = this;
1212
+ var _this4 = this;
1221
1213
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1222
- this.afterReady(function () {
1223
- _this6.dataSource = data;
1224
- _this6.api.setRowData(data);
1225
- if (_this6.isPreserveSelected()) {
1226
- _this6.api.forEachNode(function (node) {
1227
- if (node.id && _this6.selected.has(node.id)) {
1228
- var rowData = _this6.selected.get(node.id);
1229
- if (node.data !== undefined && rowData !== node.data) {
1230
- _this6.selected.set(node.id, node.data);
1214
+ this.dataSource = data;
1215
+ this.api.setRowData(data);
1216
+ if (this.isPreserveSelected()) {
1217
+ this.api.forEachNode(function (node) {
1218
+ if (node.id && _this4.selected.has(node.id)) {
1219
+ var rowData = _this4.selected.get(node.id);
1220
+ if (node.data !== undefined && rowData !== node.data) {
1221
+ _this4.selected.set(node.id, node.data);
1222
+ }
1223
+ if (!node.isSelected()) {
1224
+ node.setSelected(true, false, true);
1225
+ }
1226
+ }
1227
+ });
1228
+ } else {
1229
+ var keys = new Map(data.map(function (item) {
1230
+ return [_this4.getRowId({
1231
+ data: item
1232
+ }), item];
1233
+ }));
1234
+ this.selected.forEach(function (id) {
1235
+ if (!keys.has(id)) {
1236
+ _this4.selected.delete(id);
1237
+ } else {
1238
+ var node = _this4.api.getRowNode(id);
1239
+ if (node !== undefined) {
1240
+ if (node.data !== undefined && _this4.selected.get(id) !== node.data) {
1241
+ _this4.selected.set(id, node.data);
1231
1242
  }
1232
1243
  if (!node.isSelected()) {
1233
1244
  node.setSelected(true, false, true);
1234
1245
  }
1235
1246
  }
1236
- });
1237
- } else {
1238
- var keys = new Map(data.map(function (item) {
1239
- return [_this6.getRowId({
1240
- data: item
1241
- }), item];
1242
- }));
1243
- _this6.selected.forEach(function (id) {
1244
- if (!keys.has(id)) {
1245
- _this6.selected.delete(id);
1246
- } else {
1247
- var node = _this6.api.getRowNode(id);
1248
- if (node !== undefined) {
1249
- if (node.data !== undefined && _this6.selected.get(id) !== node.data) {
1250
- _this6.selected.set(id, node.data);
1251
- }
1252
- if (!node.isSelected()) {
1253
- node.setSelected(true, false, true);
1254
- }
1255
- }
1256
- }
1257
- });
1258
- }
1259
- if (_this6.selected.isDirty()) {
1260
- _this6.api.dispatchEvent({
1261
- type: 'selectionChanged'
1262
- });
1263
- }
1264
- });
1247
+ }
1248
+ });
1249
+ }
1250
+ if (this.selected.isDirty()) {
1251
+ this.api.dispatchEvent({
1252
+ type: 'selectionChanged'
1253
+ });
1254
+ }
1265
1255
  }
1266
1256
  }, {
1267
1257
  key: "getSummaryRowData",
@@ -1285,102 +1275,121 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1285
1275
  });
1286
1276
  }
1287
1277
  }, {
1288
- key: "getDataFromServer",
1289
- value: function getDataFromServer() {
1290
- var _this7 = this;
1291
- var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1292
- this.afterReady(function () {
1293
- var _this7$props = _this7.props,
1294
- fetch = _this7$props.fetch,
1295
- onLoading = _this7$props.onLoading,
1296
- onLoad = _this7$props.onLoad;
1297
- var loadingChange = function loadingChange(flag) {
1298
- if (onLoading) {
1299
- onLoading(flag);
1278
+ key: "loadingChange",
1279
+ value:
1280
+ /**
1281
+ *
1282
+ * @param flag
1283
+ * @param ignoreClientMode 为了解决明细页面出现2个loading动画的问题,非远程模式加载列定制数据的时候暂定出现表格内部加载动画
1284
+ */
1285
+ function loadingChange(flag) {
1286
+ var _this5 = this;
1287
+ var ignoreClientMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1288
+ if (this.loadingTiming) {
1289
+ clearTimeout(this.loadingTiming);
1290
+ this.loadingTiming = null;
1291
+ }
1292
+ this.loadingTiming = setTimeout(function () {
1293
+ var onLoading = _this5.props.onLoading;
1294
+ if (onLoading) {
1295
+ onLoading(flag);
1296
+ } else {
1297
+ if (_this5.isClientMode() && ignoreClientMode) {
1298
+ // noop
1300
1299
  } else {
1301
- _this7.setState({
1300
+ _this5.setState({
1302
1301
  loading: flag
1303
1302
  });
1304
1303
  }
1305
- };
1306
- if (typeof fetch === 'function') {
1307
- if (_this7.requestId < Number.MAX_SAFE_INTEGER) {
1308
- _this7.requestId += 1;
1304
+ }
1305
+ _this5.loadingTiming = null;
1306
+ }, 16);
1307
+ }
1308
+ }, {
1309
+ key: "getDataFromServer",
1310
+ value: function getDataFromServer() {
1311
+ var _this6 = this;
1312
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1313
+ var _this$props8 = this.props,
1314
+ fetch = _this$props8.fetch,
1315
+ onLoad = _this$props8.onLoad;
1316
+ if (typeof fetch === 'function') {
1317
+ if (this.requestId < Number.MAX_SAFE_INTEGER) {
1318
+ this.requestId += 1;
1319
+ }
1320
+ var _this$state2 = this.state,
1321
+ page = _this$state2.page,
1322
+ pageSize = _this$state2.pageSize;
1323
+ var columnState = this.columnApi.getColumnState();
1324
+ var id = this.requestId;
1325
+ this.loadingChange(true);
1326
+ fetch({
1327
+ current: page,
1328
+ pageSize: pageSize,
1329
+ sort: columnState.filter(function (item) {
1330
+ return item.sort !== undefined && item.sort !== null;
1331
+ }).map(function (item) {
1332
+ return {
1333
+ field: item.colId,
1334
+ order: item.sort
1335
+ };
1336
+ })
1337
+ }).then(function (res) {
1338
+ if (id !== _this6.requestId) {
1339
+ return;
1309
1340
  }
1310
- var _this7$state = _this7.state,
1311
- page = _this7$state.page,
1312
- pageSize = _this7$state.pageSize;
1313
- var columnState = _this7.columnApi.getColumnState();
1314
- var id = _this7.requestId;
1315
- loadingChange(true);
1316
- fetch({
1317
- current: page,
1318
- pageSize: pageSize,
1319
- sort: columnState.filter(function (item) {
1320
- return item.sort !== undefined && item.sort !== null;
1321
- }).map(function (item) {
1322
- return {
1323
- field: item.colId,
1324
- order: item.sort
1325
- };
1326
- })
1327
- }).then(function (res) {
1328
- if (id !== _this7.requestId) {
1329
- return;
1330
- }
1331
- loadingChange(false);
1332
- if (res.total !== undefined) {
1333
- _this7.setState({
1334
- page: page,
1335
- pageSize: pageSize,
1336
- total: res.total
1337
- });
1338
- }
1339
- var summary = _this7.props.summary;
1340
- _this7.updateRowData(res.data);
1341
- _this7.api.setPinnedBottomRowData(_this7.getSummaryRowData(summary, res.summary));
1342
- if (res.data.length > 0 && !params.refresh) {
1343
- _this7.api.ensureIndexVisible(0);
1344
- }
1345
- if (onLoad) {
1346
- onLoad(res.extra);
1347
- }
1348
- _this7.store.setState({
1349
- fetchError: undefined
1341
+ _this6.loadingChange(false);
1342
+ if (res.total !== undefined) {
1343
+ _this6.setState({
1344
+ page: page,
1345
+ pageSize: pageSize,
1346
+ total: res.total
1350
1347
  });
1351
- }).catch(function (err) {
1352
- _this7.store.setState({
1353
- fetchError: err
1354
- });
1355
- loadingChange(false);
1348
+ }
1349
+ var summary = _this6.props.summary;
1350
+ _this6.updateRowData(res.data);
1351
+ _this6.api.setPinnedBottomRowData(_this6.getSummaryRowData(summary, res.summary));
1352
+ if (res.data.length > 0 && !params.refresh) {
1353
+ _this6.api.ensureIndexVisible(0);
1354
+ }
1355
+ if (onLoad) {
1356
+ onLoad(res.extra);
1357
+ }
1358
+ _this6.store.setState({
1359
+ fetchError: undefined
1360
+ });
1361
+ }).catch(function (err) {
1362
+ _this6.store.setState({
1363
+ fetchError: err
1364
+ });
1365
+ _this6.loadingChange(false);
1356
1366
 
1357
- /** 如果当前是在第一页说明根本没有数据,会误杀其他情况,但不重要 */
1358
- _this7.setState(function (prev) {
1359
- return {
1360
- total: prev.page === 1 ? 0 : prev.total
1361
- };
1362
- });
1363
- _this7.updateRowData([]);
1364
- _this7.api.setPinnedBottomRowData([]);
1367
+ /** 如果当前是在第一页说明根本没有数据,会误杀其他情况,但不重要 */
1368
+ _this6.setState(function (prev) {
1369
+ return {
1370
+ total: prev.page === 1 ? 0 : prev.total
1371
+ };
1365
1372
  });
1366
- }
1367
- });
1373
+ _this6.updateRowData([]);
1374
+ _this6.api.setPinnedBottomRowData([]);
1375
+ });
1376
+ }
1368
1377
  }
1369
1378
  }, {
1370
1379
  key: "pagination",
1371
1380
  value: function pagination(page, pageSize) {
1372
- var _this8 = this;
1381
+ var _this7 = this;
1373
1382
  this.setState({
1374
1383
  page: page,
1375
1384
  pageSize: pageSize
1376
1385
  }, function () {
1377
- if (_this8.isClientMode()) {
1386
+ if (_this7.isClientMode()) {
1378
1387
  withSyncRender(function () {
1379
- _this8.api.paginationGoToPage(page - 1);
1380
- _this8.api.paginationSetPageSize(pageSize);
1388
+ _this7.api.paginationGoToPage(page - 1);
1389
+ _this7.api.paginationSetPageSize(pageSize);
1381
1390
  });
1382
1391
  } else {
1383
- _this8.getDataFromServer();
1392
+ _this7.getDataFromServer();
1384
1393
  }
1385
1394
  });
1386
1395
  }
@@ -1403,7 +1412,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1403
1412
  }, {
1404
1413
  key: "validateRecord",
1405
1414
  value: function validateRecord(record) {
1406
- var _this9 = this;
1415
+ var _this8 = this;
1407
1416
  if (this.validator === null) {
1408
1417
  return;
1409
1418
  }
@@ -1411,26 +1420,26 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1411
1420
  data: record
1412
1421
  });
1413
1422
  return this.validator.validate(record).then(function () {
1414
- var errors = new Map(_this9.store.getState().errors);
1423
+ var errors = new Map(_this8.store.getState().errors);
1415
1424
  var error = errors.get(rowId);
1416
1425
  if (error === undefined) {
1417
1426
  return;
1418
1427
  }
1419
1428
  errors.delete(rowId);
1420
- _this9.store.setState({
1429
+ _this8.store.setState({
1421
1430
  errors: errors
1422
1431
  });
1423
1432
  }).catch(function (res) {
1424
1433
  var fields = res.fields;
1425
- var errors = new Map(_this9.store.getState().errors);
1434
+ var errors = new Map(_this8.store.getState().errors);
1426
1435
  var error = new Map();
1427
1436
  Object.entries(fields).forEach(function (item) {
1428
1437
  error.set(item[0], item[1].map(function (err) {
1429
- return _this9.getFieldErrMessage(err, item[0]);
1438
+ return _this8.getFieldErrMessage(err, item[0]);
1430
1439
  }));
1431
1440
  });
1432
1441
  errors.set(rowId, error);
1433
- _this9.store.setState({
1442
+ _this8.store.setState({
1434
1443
  errors: errors
1435
1444
  });
1436
1445
  });
@@ -1439,7 +1448,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1439
1448
  key: "validate",
1440
1449
  value: function () {
1441
1450
  var _validate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
1442
- var _this10 = this;
1451
+ var _this9 = this;
1443
1452
  var promises, result, flag, errors, failed;
1444
1453
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1445
1454
  while (1) switch (_context4.prev = _context4.next) {
@@ -1450,13 +1459,13 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1450
1459
  if (record === undefined) {
1451
1460
  return;
1452
1461
  }
1453
- var rowId = _this10.getRowId({
1462
+ var rowId = _this9.getRowId({
1454
1463
  data: record
1455
1464
  });
1456
- if (_this10.validator === null) {
1465
+ if (_this9.validator === null) {
1457
1466
  promises.push(Promise.resolve(true));
1458
1467
  } else {
1459
- promises.push(_this10.validator.validate(record).catch(function (_ref8) {
1468
+ promises.push(_this9.validator.validate(record).catch(function (_ref8) {
1460
1469
  var fields = _ref8.fields;
1461
1470
  return Promise.reject({
1462
1471
  id: rowId,
@@ -1486,7 +1495,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1486
1495
  field = _ref11[0],
1487
1496
  errs = _ref11[1];
1488
1497
  error.set(field, errs.map(function (err) {
1489
- return _this10.getFieldErrMessage(err, field);
1498
+ return _this9.getFieldErrMessage(err, field);
1490
1499
  }));
1491
1500
  });
1492
1501
  errors.set(id, error);
@@ -1518,12 +1527,14 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1518
1527
  }, {
1519
1528
  key: "fetch",
1520
1529
  value: function fetch(page) {
1521
- var _this11 = this;
1530
+ var _this10 = this;
1522
1531
  var curr = page || 1;
1523
1532
  this.setState({
1524
1533
  page: curr
1525
1534
  }, function () {
1526
- _this11.getDataFromServer();
1535
+ _this10.afterReady(function () {
1536
+ _this10.getDataFromServer();
1537
+ });
1527
1538
  });
1528
1539
  }
1529
1540
  }, {
@@ -1567,35 +1578,35 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1567
1578
  }, {
1568
1579
  key: "render",
1569
1580
  value: function render() {
1570
- var _this12 = this;
1571
- var _this$props8 = this.props,
1572
- rowKey = _this$props8.rowKey,
1573
- fetch = _this$props8.fetch,
1574
- dataSource = _this$props8.dataSource,
1575
- rowActions = _this$props8.rowActions,
1576
- columns = _this$props8.columns,
1577
- autoLoad = _this$props8.autoLoad,
1578
- loadingProp = _this$props8.loading,
1579
- summary = _this$props8.summary,
1580
- detailCell = _this$props8.detailCell,
1581
- pagination = _this$props8.pagination,
1582
- rowSelection = _this$props8.rowSelection,
1583
- columnTypesProp = _this$props8.columnTypes,
1584
- defaultColDefProp = _this$props8.defaultColDef,
1585
- componentsProp = _this$props8.components,
1586
- sideBarProp = _this$props8.sideBar,
1587
- detailCellRendererParams = _this$props8.detailCellRendererParams,
1588
- context = _this$props8.context,
1589
- showSearch = _this$props8.showSearch,
1590
- cellDisplayFlex = _this$props8.cellDisplayFlex,
1591
- locale = _this$props8.locale,
1592
- restProps = _objectWithoutProperties(_this$props8, _excluded4);
1593
- var _this$state2 = this.state,
1594
- enablePagination = _this$state2.pagination,
1595
- page = _this$state2.page,
1596
- pageSize = _this$state2.pageSize,
1597
- total = _this$state2.total,
1598
- loading = _this$state2.loading;
1581
+ var _this11 = this;
1582
+ var _this$props9 = this.props,
1583
+ rowKey = _this$props9.rowKey,
1584
+ fetch = _this$props9.fetch,
1585
+ dataSource = _this$props9.dataSource,
1586
+ rowActions = _this$props9.rowActions,
1587
+ columns = _this$props9.columns,
1588
+ autoLoad = _this$props9.autoLoad,
1589
+ loadingProp = _this$props9.loading,
1590
+ summary = _this$props9.summary,
1591
+ detailCell = _this$props9.detailCell,
1592
+ pagination = _this$props9.pagination,
1593
+ rowSelection = _this$props9.rowSelection,
1594
+ columnTypesProp = _this$props9.columnTypes,
1595
+ defaultColDefProp = _this$props9.defaultColDef,
1596
+ componentsProp = _this$props9.components,
1597
+ sideBarProp = _this$props9.sideBar,
1598
+ detailCellRendererParams = _this$props9.detailCellRendererParams,
1599
+ context = _this$props9.context,
1600
+ showSearch = _this$props9.showSearch,
1601
+ cellDisplayFlex = _this$props9.cellDisplayFlex,
1602
+ locale = _this$props9.locale,
1603
+ restProps = _objectWithoutProperties(_this$props9, _excluded4);
1604
+ var _this$state3 = this.state,
1605
+ enablePagination = _this$state3.pagination,
1606
+ page = _this$state3.page,
1607
+ pageSize = _this$state3.pageSize,
1608
+ total = _this$state3.total,
1609
+ loading = _this$state3.loading;
1599
1610
  var mPage = _typeof(pagination) === 'object' ? pagination : {};
1600
1611
  var footer = [];
1601
1612
  var gridRowSelection;
@@ -1639,7 +1650,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1639
1650
  current: page,
1640
1651
  total: total,
1641
1652
  onChange: function onChange(curr, limit) {
1642
- _this12.pagination(curr, limit);
1653
+ _this11.pagination(curr, limit);
1643
1654
  if (mPage.onChange) {
1644
1655
  mPage.onChange(curr, limit);
1645
1656
  }
@@ -1657,7 +1668,7 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
1657
1668
  if (e.currentTarget.contains(e.relatedTarget)) {
1658
1669
  return;
1659
1670
  }
1660
- _this12.handleBlur();
1671
+ _this11.handleBlur();
1661
1672
  },
1662
1673
  onFocus: this.handleFocus
1663
1674
  }, /*#__PURE__*/React.createElement(AgGridReact, _extends({
@@ -320,7 +320,6 @@
320
320
  &-bottom {
321
321
  display: flex;
322
322
  align-items: center;
323
- justify-content: space-between;
324
323
  margin-top: @space-v;
325
324
  background-color: var(--ag-background-color);
326
325
 
@@ -330,6 +329,7 @@
330
329
  }
331
330
 
332
331
  &-selected {
332
+ margin-right: @padding-md;
333
333
  color: #333;
334
334
 
335
335
  a {
@@ -276,7 +276,8 @@ export var columnTypes = {
276
276
  suppressColumnsToolPanel: true,
277
277
  spanHeaderHeight: true,
278
278
  sortable: false,
279
- lockPinned: true
279
+ lockPinned: true,
280
+ pinned: 'left'
280
281
  },
281
282
  delete: {
282
283
  colId: '$$delete',
@@ -170,7 +170,9 @@ export default function SiderTree(props) {
170
170
  className: prefix('header')
171
171
  }, mHeader), heightProp === 'auto' ? /*#__PURE__*/React.createElement(ResizeObserver, {
172
172
  onResize: function onResize(e) {
173
- return setHeight(e.height);
173
+ if (e.height) {
174
+ setHeight(e.height);
175
+ }
174
176
  }
175
177
  }, /*#__PURE__*/React.createElement("div", {
176
178
  className: prefix('body'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/components",
3
- "version": "1.2.8",
3
+ "version": "1.2.9-alpha.1",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "",
6
6
  "license": "ISC",
@@ -67,5 +67,5 @@
67
67
  "publishConfig": {
68
68
  "registry": "https://registry.npmjs.org"
69
69
  },
70
- "gitHead": "6cda44ae5c46b758e48a544a0a40a41420263817"
70
+ "gitHead": "ae4063a85960a12bbbc469fa46eaba09184d7638"
71
71
  }