@lemon-fe/kits 1.0.5-0 → 1.0.5-2

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.
@@ -391,6 +391,22 @@ var DataGrid = /*#__PURE__*/function (_Component) {
391
391
  data.push(rowNode.data);
392
392
  }
393
393
  });
394
+
395
+ if (_this.isClientMode()) {
396
+ var _this$state = _this.state,
397
+ page = _this$state.page,
398
+ pageSize = _this$state.pageSize;
399
+ var totalPages = Math.ceil(data.length / pageSize) || 1;
400
+ var newPage = page > totalPages ? totalPages : page;
401
+
402
+ if (newPage !== page) {
403
+ _this.api.paginationGoToPage(newPage - 1);
404
+ }
405
+
406
+ _this.setState({
407
+ total: data.length
408
+ });
409
+ }
394
410
  /**
395
411
  * 浅比较是为了防止通过设置props.dataSource触发onDataSourceChange
396
412
  */
@@ -874,48 +890,31 @@ var DataGrid = /*#__PURE__*/function (_Component) {
874
890
  }, {
875
891
  key: "syncRowData",
876
892
  value: function syncRowData() {
877
- var _this4 = this;
878
-
879
893
  var dataSource = this.props.dataSource;
880
894
 
881
895
  if (dataSource !== undefined && dataSource !== this.dataSource) {
882
896
  this.updateRowData(dataSource);
883
- var _this$state = this.state,
884
- page = _this$state.page,
885
- pageSize = _this$state.pageSize;
886
- var totalPages = Math.ceil(dataSource.length / pageSize) || 1;
887
- var newPage = page > totalPages ? totalPages : page;
888
-
889
- if (newPage !== page && this.isClientMode()) {
890
- this.afterReady(function () {
891
- _this4.api.paginationGoToPage(newPage - 1);
892
- });
893
- }
894
-
895
- this.setState({
896
- total: dataSource.length
897
- });
898
897
  }
899
898
  }
900
899
  }, {
901
900
  key: "updateColumnDefs",
902
901
  value: function updateColumnDefs(state) {
903
- var _this5 = this;
902
+ var _this4 = this;
904
903
 
905
904
  var allState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
906
905
  this.afterReady(function () {
907
- var _this5$getColumnDefs = _this5.getColumnDefs(),
908
- _this5$getColumnDefs2 = _slicedToArray(_this5$getColumnDefs, 2),
909
- defs = _this5$getColumnDefs2[0],
910
- leafColIds = _this5$getColumnDefs2[1];
906
+ var _this4$getColumnDefs = _this4.getColumnDefs(),
907
+ _this4$getColumnDefs2 = _slicedToArray(_this4$getColumnDefs, 2),
908
+ defs = _this4$getColumnDefs2[0],
909
+ leafColIds = _this4$getColumnDefs2[1];
911
910
 
912
- _this5.api.setColumnDefs(defs);
911
+ _this4.api.setColumnDefs(defs);
913
912
 
914
913
  if (state) {
915
914
  /**
916
915
  * 表格初始化列抖动问题:先调用setColumnDefs,后applyColumnState,会产生列移动动画,所以先禁用列移动的动画
917
916
  */
918
- _this5.api.__setProperty('suppressColumnMoveAnimation', true);
917
+ _this4.api.__setProperty('suppressColumnMoveAnimation', true);
919
918
 
920
919
  var newState = _toConsumableArray(state);
921
920
 
@@ -938,7 +937,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
938
937
  * 初始化的时候,需要使用存储的columnState,不仅仅是顺序,其他情况由于在defs里已经有列的状态控制了
939
938
  */
940
939
 
941
- _this5.columnApi.applyColumnState({
940
+ _this4.columnApi.applyColumnState({
942
941
  state: allState ? newState : newState.map(function (item) {
943
942
  return {
944
943
  colId: item.colId
@@ -947,7 +946,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
947
946
  applyOrder: true
948
947
  });
949
948
 
950
- _this5.api.__setProperty('suppressColumnMoveAnimation', !!_this5.props.suppressColumnMoveAnimation);
949
+ _this4.api.__setProperty('suppressColumnMoveAnimation', !!_this4.props.suppressColumnMoveAnimation);
951
950
  }
952
951
  });
953
952
  }
@@ -984,7 +983,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
984
983
  }, {
985
984
  key: "getColumnDefs",
986
985
  value: function getColumnDefs() {
987
- var _this6 = this,
986
+ var _this5 = this,
988
987
  _this$props$customCol;
989
988
 
990
989
  var _this$props7 = this.props,
@@ -1014,7 +1013,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1014
1013
  opts.field = getColField(item);
1015
1014
  }
1016
1015
 
1017
- var def = _this6.getFullColumnDef(opts);
1016
+ var def = _this5.getFullColumnDef(opts);
1018
1017
  /** 部分列由于使用type 可能存在colId以及field都不存在, maintainColumnOrder下updateColumnDefs有问题,故从merge后的def中提取field或者colId */
1019
1018
 
1020
1019
 
@@ -1242,7 +1241,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1242
1241
  if (DataGrid.isSummaryRow({
1243
1242
  node: node
1244
1243
  }) && field.summaryType === 1) {
1245
- var summary = _this6.getFieldsSummary(_this6.dataSource, _this6.fields);
1244
+ var summary = _this5.getFieldsSummary(_this5.dataSource, _this5.fields);
1246
1245
 
1247
1246
  return get(summary, field.id);
1248
1247
  }
@@ -1387,21 +1386,21 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1387
1386
  }, {
1388
1387
  key: "updateRowData",
1389
1388
  value: function updateRowData() {
1390
- var _this7 = this;
1389
+ var _this6 = this;
1391
1390
 
1392
1391
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1393
1392
  this.afterReady(function () {
1394
- _this7.dataSource = data;
1393
+ _this6.dataSource = data;
1395
1394
 
1396
- _this7.api.setRowData(data);
1395
+ _this6.api.setRowData(data);
1397
1396
 
1398
- if (_this7.isPreserveSelected()) {
1399
- _this7.api.forEachNode(function (node) {
1400
- if (node.id && _this7.selected.has(node.id)) {
1401
- var rowData = _this7.selected.get(node.id);
1397
+ if (_this6.isPreserveSelected()) {
1398
+ _this6.api.forEachNode(function (node) {
1399
+ if (node.id && _this6.selected.has(node.id)) {
1400
+ var rowData = _this6.selected.get(node.id);
1402
1401
 
1403
1402
  if (node.data !== undefined && rowData !== node.data) {
1404
- _this7.selected.set(node.id, node.data);
1403
+ _this6.selected.set(node.id, node.data);
1405
1404
  }
1406
1405
 
1407
1406
  if (!node.isSelected()) {
@@ -1411,20 +1410,20 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1411
1410
  });
1412
1411
  } else {
1413
1412
  var keys = new Map(data.map(function (item) {
1414
- return [_this7.getRowId({
1413
+ return [_this6.getRowId({
1415
1414
  data: item
1416
1415
  }), item];
1417
1416
  }));
1418
1417
 
1419
- _this7.selected.forEach(function (id) {
1418
+ _this6.selected.forEach(function (id) {
1420
1419
  if (!keys.has(id)) {
1421
- _this7.selected.delete(id);
1420
+ _this6.selected.delete(id);
1422
1421
  } else {
1423
- var node = _this7.api.getRowNode(id);
1422
+ var node = _this6.api.getRowNode(id);
1424
1423
 
1425
1424
  if (node !== undefined) {
1426
- if (node.data !== undefined && _this7.selected.get(id) !== node.data) {
1427
- _this7.selected.set(id, node.data);
1425
+ if (node.data !== undefined && _this6.selected.get(id) !== node.data) {
1426
+ _this6.selected.set(id, node.data);
1428
1427
  }
1429
1428
 
1430
1429
  if (!node.isSelected()) {
@@ -1435,8 +1434,8 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1435
1434
  });
1436
1435
  }
1437
1436
 
1438
- if (_this7.selected.isDirty()) {
1439
- _this7.api.dispatchEvent({
1437
+ if (_this6.selected.isDirty()) {
1438
+ _this6.api.dispatchEvent({
1440
1439
  type: 'selectionChanged'
1441
1440
  });
1442
1441
  }
@@ -1470,36 +1469,36 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1470
1469
  }, {
1471
1470
  key: "getDataFromServer",
1472
1471
  value: function getDataFromServer() {
1473
- var _this8 = this;
1472
+ var _this7 = this;
1474
1473
 
1475
1474
  this.afterReady(function () {
1476
- var _this8$props = _this8.props,
1477
- fetch = _this8$props.fetch,
1478
- onLoading = _this8$props.onLoading,
1479
- onLoad = _this8$props.onLoad;
1475
+ var _this7$props = _this7.props,
1476
+ fetch = _this7$props.fetch,
1477
+ onLoading = _this7$props.onLoading,
1478
+ onLoad = _this7$props.onLoad;
1480
1479
 
1481
1480
  var loadingChange = function loadingChange(flag) {
1482
1481
  if (onLoading) {
1483
1482
  onLoading(flag);
1484
1483
  } else {
1485
- _this8.setState({
1484
+ _this7.setState({
1486
1485
  loading: flag
1487
1486
  });
1488
1487
  }
1489
1488
  };
1490
1489
 
1491
1490
  if (typeof fetch === 'function') {
1492
- if (_this8.requestId < Number.MAX_SAFE_INTEGER) {
1493
- _this8.requestId += 1;
1491
+ if (_this7.requestId < Number.MAX_SAFE_INTEGER) {
1492
+ _this7.requestId += 1;
1494
1493
  }
1495
1494
 
1496
- var _this8$state = _this8.state,
1497
- page = _this8$state.page,
1498
- pageSize = _this8$state.pageSize;
1495
+ var _this7$state = _this7.state,
1496
+ page = _this7$state.page,
1497
+ pageSize = _this7$state.pageSize;
1499
1498
 
1500
- var columnState = _this8.columnApi.getColumnState();
1499
+ var columnState = _this7.columnApi.getColumnState();
1501
1500
 
1502
- var id = _this8.requestId;
1501
+ var id = _this7.requestId;
1503
1502
  loadingChange(true);
1504
1503
  fetch({
1505
1504
  current: page,
@@ -1513,54 +1512,54 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1513
1512
  };
1514
1513
  })
1515
1514
  }).then(function (res) {
1516
- if (id !== _this8.requestId) {
1515
+ if (id !== _this7.requestId) {
1517
1516
  return;
1518
1517
  }
1519
1518
 
1520
1519
  loadingChange(false);
1521
1520
 
1522
1521
  if (res.total !== undefined) {
1523
- _this8.setState({
1522
+ _this7.setState({
1524
1523
  page: page,
1525
1524
  pageSize: pageSize,
1526
1525
  total: res.total
1527
1526
  });
1528
1527
  }
1529
1528
 
1530
- var summary = _this8.props.summary;
1529
+ var summary = _this7.props.summary;
1531
1530
 
1532
- _this8.updateRowData(res.data);
1531
+ _this7.updateRowData(res.data);
1533
1532
 
1534
- _this8.api.setPinnedBottomRowData(_this8.getSummaryRowData(summary, res.summary));
1533
+ _this7.api.setPinnedBottomRowData(_this7.getSummaryRowData(summary, res.summary));
1535
1534
 
1536
1535
  if (res.data.length > 0) {
1537
- _this8.api.ensureIndexVisible(0);
1536
+ _this7.api.ensureIndexVisible(0);
1538
1537
  }
1539
1538
 
1540
1539
  if (onLoad) {
1541
1540
  onLoad(res.extra);
1542
1541
  }
1543
1542
 
1544
- _this8.store.setState({
1543
+ _this7.store.setState({
1545
1544
  fetchError: undefined
1546
1545
  });
1547
1546
  }).catch(function (err) {
1548
- _this8.store.setState({
1547
+ _this7.store.setState({
1549
1548
  fetchError: err
1550
1549
  });
1551
1550
 
1552
1551
  loadingChange(false);
1553
1552
  /** 如果当前是在第一页说明根本没有数据,会误杀其他情况,但不重要 */
1554
1553
 
1555
- _this8.setState(function (prev) {
1554
+ _this7.setState(function (prev) {
1556
1555
  return {
1557
1556
  total: prev.page === 1 ? 0 : prev.total
1558
1557
  };
1559
1558
  });
1560
1559
 
1561
- _this8.updateRowData([]);
1560
+ _this7.updateRowData([]);
1562
1561
 
1563
- _this8.api.setPinnedBottomRowData([]);
1562
+ _this7.api.setPinnedBottomRowData([]);
1564
1563
  });
1565
1564
  }
1566
1565
  });
@@ -1568,20 +1567,20 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1568
1567
  }, {
1569
1568
  key: "pagination",
1570
1569
  value: function pagination(page, pageSize) {
1571
- var _this9 = this;
1570
+ var _this8 = this;
1572
1571
 
1573
1572
  this.setState({
1574
1573
  page: page,
1575
1574
  pageSize: pageSize
1576
1575
  }, function () {
1577
- if (_this9.isClientMode()) {
1576
+ if (_this8.isClientMode()) {
1578
1577
  withSyncRender(function () {
1579
- _this9.api.paginationGoToPage(page - 1);
1578
+ _this8.api.paginationGoToPage(page - 1);
1580
1579
 
1581
- _this9.api.paginationSetPageSize(pageSize);
1580
+ _this8.api.paginationSetPageSize(pageSize);
1582
1581
  });
1583
1582
  } else {
1584
- _this9.getDataFromServer();
1583
+ _this8.getDataFromServer();
1585
1584
  }
1586
1585
  });
1587
1586
  }
@@ -1597,7 +1596,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1597
1596
  }, {
1598
1597
  key: "validateRecord",
1599
1598
  value: function validateRecord(record) {
1600
- var _this10 = this;
1599
+ var _this9 = this;
1601
1600
 
1602
1601
  if (this.validator === null) {
1603
1602
  return;
@@ -1607,7 +1606,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1607
1606
  data: record
1608
1607
  });
1609
1608
  return this.validator.validate(record).then(function () {
1610
- var errors = new Map(_this10.store.getState().errors);
1609
+ var errors = new Map(_this9.store.getState().errors);
1611
1610
  var error = errors.get(rowId);
1612
1611
 
1613
1612
  if (error === undefined) {
@@ -1616,12 +1615,12 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1616
1615
 
1617
1616
  errors.delete(rowId);
1618
1617
 
1619
- _this10.store.setState({
1618
+ _this9.store.setState({
1620
1619
  errors: errors
1621
1620
  });
1622
1621
  }).catch(function (_ref7) {
1623
1622
  var fields = _ref7.fields;
1624
- var errors = new Map(_this10.store.getState().errors);
1623
+ var errors = new Map(_this9.store.getState().errors);
1625
1624
  var error = new Map();
1626
1625
  Object.entries(fields).forEach(function (item) {
1627
1626
  error.set(item[0], item[1].map(function (err) {
@@ -1630,7 +1629,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1630
1629
  });
1631
1630
  errors.set(rowId, error);
1632
1631
 
1633
- _this10.store.setState({
1632
+ _this9.store.setState({
1634
1633
  errors: errors
1635
1634
  });
1636
1635
  });
@@ -1639,7 +1638,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1639
1638
  key: "validate",
1640
1639
  value: function () {
1641
1640
  var _validate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
1642
- var _this11 = this;
1641
+ var _this10 = this;
1643
1642
 
1644
1643
  var promises, result, flag, errors, failed;
1645
1644
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
@@ -1654,14 +1653,14 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1654
1653
  return;
1655
1654
  }
1656
1655
 
1657
- var rowId = _this11.getRowId({
1656
+ var rowId = _this10.getRowId({
1658
1657
  data: record
1659
1658
  });
1660
1659
 
1661
- if (_this11.validator === null) {
1660
+ if (_this10.validator === null) {
1662
1661
  promises.push(Promise.resolve(true));
1663
1662
  } else {
1664
- promises.push(_this11.validator.validate(record).catch(function (_ref8) {
1663
+ promises.push(_this10.validator.validate(record).catch(function (_ref8) {
1665
1664
  var fields = _ref8.fields;
1666
1665
  return Promise.reject({
1667
1666
  id: rowId,
@@ -1729,13 +1728,13 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1729
1728
  }, {
1730
1729
  key: "fetch",
1731
1730
  value: function fetch(page) {
1732
- var _this12 = this;
1731
+ var _this11 = this;
1733
1732
 
1734
1733
  var curr = page || 1;
1735
1734
  this.setState({
1736
1735
  page: curr
1737
1736
  }, function () {
1738
- _this12.getDataFromServer();
1737
+ _this11.getDataFromServer();
1739
1738
  });
1740
1739
  }
1741
1740
  }, {
@@ -1786,7 +1785,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1786
1785
  }, {
1787
1786
  key: "render",
1788
1787
  value: function render() {
1789
- var _this13 = this,
1788
+ var _this12 = this,
1790
1789
  _classNames;
1791
1790
 
1792
1791
  var _this$props8 = this.props,
@@ -1860,7 +1859,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1860
1859
  current: page,
1861
1860
  total: total,
1862
1861
  onChange: function onChange(curr, limit) {
1863
- _this13.pagination(curr, limit);
1862
+ _this12.pagination(curr, limit);
1864
1863
 
1865
1864
  if (mPage.onChange) {
1866
1865
  mPage.onChange(curr, limit);
@@ -1881,7 +1880,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1881
1880
  return;
1882
1881
  }
1883
1882
 
1884
- _this13.handleBlur();
1883
+ _this12.handleBlur();
1885
1884
  },
1886
1885
  onFocus: this.handleFocus
1887
1886
  }, /*#__PURE__*/React.createElement(AgGridReact, _extends({
@@ -333,3 +333,15 @@ span.@{ant-prefix}-radio + * {
333
333
  line-height: 20px;
334
334
  }
335
335
  }
336
+
337
+ /** alert **/
338
+ @alert-padding-vertical: @padding-xs - 2;
339
+
340
+ .@{ant-prefix}-alert {
341
+ align-items: flex-start;
342
+
343
+ &-icon {
344
+ padding: 2px 0;
345
+ font-size: 18px;
346
+ }
347
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/kits",
3
- "version": "1.0.5-0",
3
+ "version": "1.0.5-2",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",