Merge pull request #8822 from wanglinfang2014/feat-nav

fix: table嵌套模式下selectedChange参数错误、table展示单选可多选问题修复
This commit is contained in:
hsm-lv 2023-11-21 12:54:09 +08:00 committed by GitHub
commit 31c857e399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 55 deletions

View File

@ -1050,7 +1050,13 @@ export const TableStore = iRendererStore
);
}
config.multiple !== undefined && (self.multiple = config.multiple);
if (config.multiple !== undefined) {
self.multiple = config.multiple;
} else {
// 如果通过crud或pickermultiple始终设置了true或false
// 如果仅使用table默认multiple为true但props未设置multiple的情况下其实是展示单选
self.multiple = false;
}
config.footable !== undefined && (self.footable = config.footable);
config.expandConfig !== undefined &&
(self.expandConfig = config.expandConfig);

View File

@ -967,56 +967,27 @@ export default class Table extends React.Component<TableProps, object> {
value = value !== undefined ? value : !item.checked;
let rows = [item];
if (shift) {
rows = store.getToggleShiftRows(item);
}
const selectedItems = value
? [
...store.selectedRows.map((row: IRow) => row.data),
...rows.map((row: IRow) => row.data)
]
: store.selectedRows
.filter(
(row: IRow) =>
rows.findIndex((rowItem: IRow) => rowItem === row) === -1
)
.map((row: IRow) => row.data);
const unSelectedItems = value
? store.unSelectedRows
.filter(
(row: IRow) =>
rows.findIndex((rowItem: IRow) => rowItem === row) === -1
)
.map((row: IRow) => row.data)
: [
...store.unSelectedRows.map((row: IRow) => row.data),
...rows.map((row: IRow) => row.data)
];
const rendererEvent = await dispatchEvent(
'selectedChange',
createObject(data, {
selectedItems,
unSelectedItems
})
);
if (rendererEvent?.prevented) {
return;
}
if (shift) {
store.toggleShift(item, value);
} else {
// 如果picker的value是绑定的上层数量变量
// 那么用户只能通过事件动作来更新上层变量来实现选中
// 但是注册了setValue动作后会优先通过componentDidUpdate更新了selectedRows
// 那么这里直接toggle就判断出错了 需要明确是选中还是取消选中
item.toggle(value);
}
const rendererEvent = await dispatchEvent(
'selectedChange',
createObject(data, {
selectedItems: store.selectedRows.map(row => row.data),
unSelectedItems: store.unSelectedRows.map(row => row.data),
item: item.data
})
);
if (rendererEvent?.prevented) {
return;
}
this.syncSelected();
}
@ -1069,29 +1040,21 @@ export default class Table extends React.Component<TableProps, object> {
const {store, data, dispatchEvent} = this.props;
const items = store.rows.map((row: any) => row.data);
const allChecked = store.allChecked;
const selectedItems = store.getSelectedRows();
store.toggleAll();
const rendererEvent = await dispatchEvent(
'selectedChange',
createObject(data, {
selectedItems: allChecked
? selectedItems.filter(item => !item.checkable).map(item => item.data)
: selectedItems.map(item => item.data),
unSelectedItems: allChecked ? selectedItems.map(item => item.data) : [],
selectedItems: store.selectedRows.map(row => row.data),
unSelectedItems: store.unSelectedRows.map(row => row.data),
items
})
);
if (rendererEvent?.prevented) {
return;
}
// selectedChange事件注册的动作里有可能已经通过setValue把selectedRows的情况改了
// 没有改的情况下 才会去执行store.toogleAll()
if (allChecked === store.allChecked) {
store.toggleAll();
}
this.syncSelected();
}