|
@@ -3,7 +3,8 @@ import { Task } from '@/domain/work';
|
|
|
|
|
|
|
|
interface UseMultiSelectionOptions {
|
|
interface UseMultiSelectionOptions {
|
|
|
selectedIds: string[];
|
|
selectedIds: string[];
|
|
|
- onSelectionChange: (ids: string[]) => void;
|
|
|
|
|
|
|
+ selectedSecondaryIds?: string[]; // 可选
|
|
|
|
|
+ onSelectionChange: ((ids: string[], secondaryIds?: string[]) => void);
|
|
|
enableMultiSelect?: boolean;
|
|
enableMultiSelect?: boolean;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -13,9 +14,11 @@ interface UseMultiSelectionOptions {
|
|
|
*/
|
|
*/
|
|
|
export const useMultiSelection = ({
|
|
export const useMultiSelection = ({
|
|
|
selectedIds,
|
|
selectedIds,
|
|
|
|
|
+ selectedSecondaryIds,
|
|
|
onSelectionChange,
|
|
onSelectionChange,
|
|
|
enableMultiSelect = true,
|
|
enableMultiSelect = true,
|
|
|
}: UseMultiSelectionOptions) => {
|
|
}: UseMultiSelectionOptions) => {
|
|
|
|
|
+ const useDualIdMode = selectedSecondaryIds !== undefined;
|
|
|
/**
|
|
/**
|
|
|
* 处理桌面环境的行点击事件
|
|
* 处理桌面环境的行点击事件
|
|
|
* @param record - 点击的行数据
|
|
* @param record - 点击的行数据
|
|
@@ -24,22 +27,46 @@ export const useMultiSelection = ({
|
|
|
const handleRowClick = useCallback((record: Task, event: React.MouseEvent) => {
|
|
const handleRowClick = useCallback((record: Task, event: React.MouseEvent) => {
|
|
|
if (!enableMultiSelect) {
|
|
if (!enableMultiSelect) {
|
|
|
// 如果禁用多选,只选中当前项
|
|
// 如果禁用多选,只选中当前项
|
|
|
- onSelectionChange([record.StudyID]);
|
|
|
|
|
|
|
+ onSelectionChange([record.StudyID], useDualIdMode ? [record.entry_id ?? ''] : undefined);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const studyId = record.StudyID;
|
|
const studyId = record.StudyID;
|
|
|
-
|
|
|
|
|
|
|
+ const entryId = record.entry_id;
|
|
|
|
|
+
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
// 桌面环境:Ctrl+点击进行多选/取消多选
|
|
// 桌面环境:Ctrl+点击进行多选/取消多选
|
|
|
- const newSelectedIds = selectedIds.includes(studyId)
|
|
|
|
|
- ? selectedIds.filter(id => id !== studyId) // 取消选择
|
|
|
|
|
- : [...selectedIds, studyId]; // 添加选择
|
|
|
|
|
-
|
|
|
|
|
- onSelectionChange(newSelectedIds);
|
|
|
|
|
|
|
+ let newSelectedIds;
|
|
|
|
|
+ let newSelectedSecondaryIds;
|
|
|
|
|
+ if (useDualIdMode) {
|
|
|
|
|
+ if (studyId) {//本地task
|
|
|
|
|
+ const index = selectedIds.indexOf(studyId);
|
|
|
|
|
+ if (index > -1) {//说明已经在选中数组中了,需要取消选择
|
|
|
|
|
+ newSelectedIds = selectedIds.splice(index, 1);
|
|
|
|
|
+ newSelectedSecondaryIds = selectedSecondaryIds?.splice(index, 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ newSelectedIds = [...selectedIds, studyId];
|
|
|
|
|
+ newSelectedSecondaryIds = [...(selectedSecondaryIds ?? []), entryId ?? ''];
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (entryId) {//ris task
|
|
|
|
|
+ const index = selectedSecondaryIds.indexOf(entryId);
|
|
|
|
|
+ if (index > -1) {//说明已经在选中数组中了,需要取消选择
|
|
|
|
|
+ newSelectedIds = selectedIds.splice(index, 1);
|
|
|
|
|
+ newSelectedSecondaryIds = selectedSecondaryIds?.splice(index, 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ newSelectedIds = [...selectedIds, studyId];
|
|
|
|
|
+ newSelectedSecondaryIds = [...(selectedSecondaryIds ?? []), entryId ?? ''];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ newSelectedIds = selectedIds.includes(studyId)
|
|
|
|
|
+ ? selectedIds.filter(id => id !== studyId) // 取消选择
|
|
|
|
|
+ : [...selectedIds, studyId]; // 添加选择
|
|
|
|
|
+ }
|
|
|
|
|
+ onSelectionChange(newSelectedIds, newSelectedSecondaryIds);
|
|
|
} else {
|
|
} else {
|
|
|
// 普通点击:清空其他选择,只选中当前项
|
|
// 普通点击:清空其他选择,只选中当前项
|
|
|
- onSelectionChange([studyId]);
|
|
|
|
|
|
|
+ onSelectionChange([studyId], useDualIdMode ? [record.entry_id ?? ''] : undefined);
|
|
|
}
|
|
}
|
|
|
}, [selectedIds, onSelectionChange, enableMultiSelect]);
|
|
}, [selectedIds, onSelectionChange, enableMultiSelect]);
|
|
|
|
|
|
|
@@ -49,13 +76,13 @@ export const useMultiSelection = ({
|
|
|
*/
|
|
*/
|
|
|
const handleTouchClick = useCallback((record: Task) => {
|
|
const handleTouchClick = useCallback((record: Task) => {
|
|
|
const studyId = record.StudyID;
|
|
const studyId = record.StudyID;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 触摸屏环境:单击选中,再次单击取消选中
|
|
// 触摸屏环境:单击选中,再次单击取消选中
|
|
|
const newSelectedIds = selectedIds.includes(studyId)
|
|
const newSelectedIds = selectedIds.includes(studyId)
|
|
|
? selectedIds.filter(id => id !== studyId) // 取消选择
|
|
? selectedIds.filter(id => id !== studyId) // 取消选择
|
|
|
: [studyId]; // 添加选择
|
|
: [studyId]; // 添加选择
|
|
|
-
|
|
|
|
|
- onSelectionChange(newSelectedIds);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ onSelectionChange(newSelectedIds, useDualIdMode ? [record.entry_id ?? ''] : undefined);
|
|
|
}, [selectedIds, onSelectionChange]);
|
|
}, [selectedIds, onSelectionChange]);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -73,7 +100,7 @@ export const useMultiSelection = ({
|
|
|
handleRowClick(record, event);
|
|
handleRowClick(record, event);
|
|
|
} else {
|
|
} else {
|
|
|
// 默认行为:只选中当前项
|
|
// 默认行为:只选中当前项
|
|
|
- onSelectionChange([record.StudyID]);
|
|
|
|
|
|
|
+ onSelectionChange([record.StudyID], useDualIdMode ? [record.entry_id ?? ''] : undefined);
|
|
|
}
|
|
}
|
|
|
}, [handleRowClick, handleTouchClick, onSelectionChange]);
|
|
}, [handleRowClick, handleTouchClick, onSelectionChange]);
|
|
|
|
|
|