@yibozhang/pro-table 16.0.2 → 16.0.4

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.
@@ -770,8 +770,6 @@ class ProTableComponent {
770
770
  _selectedTableRow = null;
771
771
  // 选中的行数据(用于复选框选择)- 保留用于兼容性
772
772
  _selectedRows = [];
773
- // 使用 Set 存储选中项的 ID,支持跨页选中
774
- _selectedRowIds = new Set();
775
773
  // 全选状态
776
774
  _checkedAll = false;
777
775
  // 半选状态(部分选中)
@@ -1399,16 +1397,6 @@ class ProTableComponent {
1399
1397
  }
1400
1398
  // 直接设置数据对象的 checked 属性
1401
1399
  data.checked = checked;
1402
- // 同步更新 _selectedRowIds(用于跨页选中)
1403
- const id = this.getRowId(data);
1404
- if (id !== undefined) {
1405
- if (checked) {
1406
- this._selectedRowIds.add(id);
1407
- }
1408
- else {
1409
- this._selectedRowIds.delete(id);
1410
- }
1411
- }
1412
1400
  // 同步更新 _selectedRows(用于兼容性)
1413
1401
  const index = this._selectedRows.findIndex((row) => this.isSameRow(row, data));
1414
1402
  if (checked) {
@@ -1456,16 +1444,6 @@ class ProTableComponent {
1456
1444
  // 批量设置 checked 属性
1457
1445
  availableRows.forEach((row) => {
1458
1446
  row.checked = checked;
1459
- // 同步更新 _selectedRowIds(用于跨页选中)
1460
- const id = this.getRowId(row);
1461
- if (id !== undefined) {
1462
- if (checked) {
1463
- this._selectedRowIds.add(id);
1464
- }
1465
- else {
1466
- this._selectedRowIds.delete(id);
1467
- }
1468
- }
1469
1447
  });
1470
1448
  // 同步更新 _selectedRows(用于兼容性)
1471
1449
  if (checked) {
@@ -1491,17 +1469,7 @@ class ProTableComponent {
1491
1469
  return;
1492
1470
  }
1493
1471
  // 数据对象的 checked 属性已经通过双向绑定自动更新
1494
- // 这里只需要同步更新 _selectedRowIds 和 _selectedRows
1495
- // 同步更新 _selectedRowIds(用于跨页选中)
1496
- const id = this.getRowId(data);
1497
- if (id !== undefined) {
1498
- if (checked) {
1499
- this._selectedRowIds.add(id);
1500
- }
1501
- else {
1502
- this._selectedRowIds.delete(id);
1503
- }
1504
- }
1472
+ // 这里只需要同步更新 _selectedRows
1505
1473
  // 同步更新 _selectedRows(用于兼容性)
1506
1474
  const index = this._selectedRows.findIndex((row) => this.isSameRow(row, data));
1507
1475
  if (checked) {
@@ -1550,8 +1518,6 @@ class ProTableComponent {
1550
1518
  row.checked = false;
1551
1519
  });
1552
1520
  }
1553
- // 清空选中集合
1554
- this._selectedRowIds.clear();
1555
1521
  this._selectedRows = [];
1556
1522
  this._checkedAll = false;
1557
1523
  this._indeterminate = false;
@@ -1629,8 +1595,6 @@ class ProTableComponent {
1629
1595
  this._pageInfo.pageIndex > 1) {
1630
1596
  this._pageInfo.pageIndex = this._pageInfo.pageIndex - 1;
1631
1597
  }
1632
- // 保存删除前的数据源(用于删除后查询时移除被删除项的选中状态)
1633
- const previousDataSource = afterDelete && this.showCheckbox ? [...this.dataSource] : [];
1634
1598
  this._loading = true;
1635
1599
  if (this.request) {
1636
1600
  try {
@@ -1645,37 +1609,14 @@ class ProTableComponent {
1645
1609
  ? { sort: this.buildServerSortPayload() }
1646
1610
  : {}),
1647
1611
  });
1648
- // 自动注入 checked 字段,支持跨页选中
1612
+ // 查询后默认不保留跨页选中状态:每次返回的数据均初始化为未选中
1649
1613
  if (this.showCheckbox) {
1650
1614
  this.dataSource = (result.data || []).map((item) => {
1651
- const id = this.getRowId(item);
1652
- // 如果数据已有 checked 属性,保留;否则根据 _selectedRowIds 判断
1653
- const checked = item.checked !== undefined
1654
- ? item.checked
1655
- : id !== undefined
1656
- ? this._selectedRowIds.has(id)
1657
- : false;
1658
1615
  return {
1659
1616
  ...item,
1660
- checked: checked,
1617
+ checked: false,
1661
1618
  };
1662
1619
  });
1663
- // 删除后查询:移除被删除项的选中状态
1664
- if (afterDelete && previousDataSource.length > 0) {
1665
- const newDataIds = new Set(this.dataSource.map((item) => this.getRowId(item)));
1666
- // 遍历之前的数据源,如果不在新数据源中,说明被删除了,需要清除其选中状态
1667
- previousDataSource.forEach((oldItem) => {
1668
- const oldId = this.getRowId(oldItem);
1669
- if (oldId !== undefined && !newDataIds.has(oldId)) {
1670
- // 被删除的项,从选中集合中移除
1671
- this._selectedRowIds.delete(oldId);
1672
- // 如果数据对象还在其他地方引用,清除其选中状态
1673
- if (oldItem.checked !== undefined) {
1674
- oldItem.checked = false;
1675
- }
1676
- }
1677
- });
1678
- }
1679
1620
  }
1680
1621
  else {
1681
1622
  this.dataSource = result.data || [];
@@ -1686,9 +1627,9 @@ class ProTableComponent {
1686
1627
  this.sortDataSourceInPlace();
1687
1628
  }
1688
1629
  this._pageInfo.total = result.total || 0;
1689
- // 更新全选状态
1630
+ // 取消跨页多选:查询后清空选中状态
1690
1631
  if (this.showCheckbox) {
1691
- this.updateCheckAllStatus();
1632
+ this.clearSelectedRows();
1692
1633
  }
1693
1634
  }
1694
1635
  catch (error) {
@@ -1706,7 +1647,6 @@ class ProTableComponent {
1706
1647
  console.warn("未提供 _request 回调函数");
1707
1648
  this._loading = false;
1708
1649
  }
1709
- // 不再调用 clearSelectedRows(),保留跨页选中状态
1710
1650
  }
1711
1651
  // 触发列排序变更
1712
1652
  onSortChange(sortKey, sortOrder) {
@@ -1736,12 +1676,11 @@ class ProTableComponent {
1736
1676
  }
1737
1677
  handleTableRowClick(data) {
1738
1678
  this._selectedTableRow = data;
1739
- // 如果开启了复选框,点击行时只选中点击行(如果行未被禁用)
1740
1679
  if (this.showCheckbox && !this.isRowDisabled(data)) {
1741
1680
  // 先清空所有选中行
1742
1681
  this._selectedRows = [];
1743
- // 只选中当前点击的行
1744
- this.toggleRowChecked(data, true);
1682
+ const nextChecked = !this.isRowChecked(data);
1683
+ this.toggleRowChecked(data, nextChecked);
1745
1684
  }
1746
1685
  this.onRowClick.emit(this._selectedTableRow);
1747
1686
  }
@@ -1879,7 +1818,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
1879
1818
  args: [TemplateRef]
1880
1819
  }], onWindowResize: [{
1881
1820
  type: HostListener,
1882
- args: ['window:resize']
1821
+ args: ["window:resize"]
1883
1822
  }] } });
1884
1823
 
1885
1824
  class PageContainerModule {