mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
Merge pull request #8822 from wanglinfang2014/feat-nav
fix: table嵌套模式下selectedChange参数错误、table展示单选可多选问题修复
This commit is contained in:
commit
31c857e399
@ -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或picker,multiple始终设置了true或false
|
||||
// 如果仅使用table,默认multiple为true,但props未设置multiple的情况下其实是展示单选
|
||||
self.multiple = false;
|
||||
}
|
||||
config.footable !== undefined && (self.footable = config.footable);
|
||||
config.expandConfig !== undefined &&
|
||||
(self.expandConfig = config.expandConfig);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user