|
|
@@ -156,18 +156,33 @@ export default function SegregationPointManagement({ subMenu }: SegregationPoint
|
|
|
|
|
|
// 删除隔离点
|
|
|
const handleDelete = async (id?: number) => {
|
|
|
- const pointIds = id ? [id] : selectedRowKeys.map(key => Number(key));
|
|
|
+ // 如果传入了 id,使用传入的 id;否则使用选中的行
|
|
|
+ const pointIds = id !== undefined && id !== null ? [id] : selectedRowKeys.map(key => Number(key));
|
|
|
+
|
|
|
+ // 如果没有可删除的数据,提示用户
|
|
|
+ if (!pointIds || pointIds.length === 0 || pointIds.every(id => !id || isNaN(id))) {
|
|
|
+ toast.error(t('common.pleaseSelectData') || '请选择要删除的数据');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 过滤掉无效的 ID
|
|
|
+ const validPointIds = pointIds.filter(id => id !== undefined && id !== null && !isNaN(id));
|
|
|
+
|
|
|
+ if (validPointIds.length === 0) {
|
|
|
+ toast.error(t('common.pleaseSelectData') || '请选择要删除的数据');
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
Modal.confirm({
|
|
|
title: t('common.confirmDelete'),
|
|
|
icon: <ExclamationCircleOutlined />,
|
|
|
- content: `${t('common.confirmDeleteText')} ${pointIds.length} ${t('common.records')}?`,
|
|
|
+ content: `${t('common.confirmDeleteText')} ${validPointIds.length} ${t('common.records')}?`,
|
|
|
okText: t('common.confirmDelete'),
|
|
|
okType: 'danger',
|
|
|
cancelText: t('common.cancel'),
|
|
|
onOk: async () => {
|
|
|
try {
|
|
|
- await segregationPointApi.deleteIsIsolationPointByPointIds(pointIds);
|
|
|
+ await segregationPointApi.deleteIsIsolationPointByPointIds(validPointIds);
|
|
|
toast.success(t('common.deleteSuccess'));
|
|
|
setSelectedRowKeys([]);
|
|
|
await getList();
|
|
|
@@ -316,7 +331,15 @@ export default function SegregationPointManagement({ subMenu }: SegregationPoint
|
|
|
<UIButton
|
|
|
variant="ghost"
|
|
|
size="sm"
|
|
|
- onClick={() => handleDelete(record.pointId)}
|
|
|
+ onClick={() => {
|
|
|
+ // 使用和 rowKey 相同的逻辑获取 ID:优先使用 pointId,如果没有则使用 id
|
|
|
+ const deleteId = record.pointId ?? record.id;
|
|
|
+ if (deleteId !== undefined && deleteId !== null) {
|
|
|
+ handleDelete(deleteId);
|
|
|
+ } else {
|
|
|
+ toast.error(t('common.deleteIdNotFound') || '无法获取删除ID');
|
|
|
+ }
|
|
|
+ }}
|
|
|
className="h-8 px-2 transition-colors hover:underline"
|
|
|
style={{ color: '#000000' }}
|
|
|
onMouseEnter={(e) => {
|
|
|
@@ -492,7 +515,8 @@ export default function SegregationPointManagement({ subMenu }: SegregationPoint
|
|
|
// 全选时,只选中当前页的数据
|
|
|
const currentPageKeys = list
|
|
|
.map(item => item.pointId ?? item.id)
|
|
|
- .filter((id): id is number => id !== undefined && id !== null);
|
|
|
+ .filter((id): id is number => id !== undefined && id !== null)
|
|
|
+ .map(id => id as React.Key);
|
|
|
setSelectedRowKeys(prev => {
|
|
|
const newKeys = new Set(prev);
|
|
|
currentPageKeys.forEach(key => newKeys.add(key));
|
|
|
@@ -500,10 +524,13 @@ export default function SegregationPointManagement({ subMenu }: SegregationPoint
|
|
|
});
|
|
|
} else {
|
|
|
// 取消全选时,只取消当前页的选中
|
|
|
- const currentPageKeys = list
|
|
|
- .map(item => item.pointId ?? item.id)
|
|
|
- .filter((id): id is number => id !== undefined && id !== null);
|
|
|
- setSelectedRowKeys(prev => prev.filter(key => !currentPageKeys.includes(key)));
|
|
|
+ const currentPageKeys = new Set(
|
|
|
+ list
|
|
|
+ .map(item => item.pointId ?? item.id)
|
|
|
+ .filter((id): id is number => id !== undefined && id !== null)
|
|
|
+ .map(id => id as React.Key)
|
|
|
+ );
|
|
|
+ setSelectedRowKeys(prev => prev.filter(key => !currentPageKeys.has(key)));
|
|
|
}
|
|
|
},
|
|
|
getCheckboxProps: (record) => ({
|