fix(FormTable): fix table spread selection(#2565) (#2574)

Co-authored-by: luojingzhou <luojingzhou@kezaihui.com>
This commit is contained in:
luojz 2023-02-22 18:32:32 +08:00 committed by GitHub
parent f32d2715ef
commit 5335ae7578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,7 +44,8 @@
rowSelection: { rowSelection: {
type: 'checkbox', type: 'checkbox',
selectedRowKeys: checkedKeys, selectedRowKeys: checkedKeys,
onChange: onSelectChange, onSelect: onSelect,
onSelectAll: onSelectAll,
}, },
}); });
@ -52,16 +53,30 @@
console.log(getForm().getFieldsValue()); console.log(getForm().getFieldsValue());
} }
function onSelectChange(selectedRowKeys: (string | number)[]) { function onSelect(record, selected) {
console.log(selectedRowKeys); if (selected) {
checkedKeys.value = selectedRowKeys; checkedKeys.value = [...checkedKeys.value, record.id];
} else {
checkedKeys.value = checkedKeys.value.filter((id) => id !== record.id);
}
}
function onSelectAll(selected, selectedRows, changeRows) {
const changeIds = changeRows.map((item) => item.id);
if (selected) {
checkedKeys.value = [...checkedKeys.value, ...changeIds];
} else {
checkedKeys.value = checkedKeys.value.filter((id) => {
return !changeIds.includes(id);
});
}
} }
return { return {
registerTable, registerTable,
getFormValues, getFormValues,
checkedKeys, checkedKeys,
onSelectChange, onSelect,
onSelectAll,
}; };
}, },
}); });