diff --git a/client/src/components/TaskManager.tsx b/client/src/components/TaskManager.tsx index 130f03d..d74ea08 100644 --- a/client/src/components/TaskManager.tsx +++ b/client/src/components/TaskManager.tsx @@ -240,6 +240,19 @@ export default function TaskManager({ const activeInspectionObject = inspectionObjects.find( object => object.id === activeTask?.inspectionObjectId ); + + // 打开新建任务表单时默认选择首个可用检测对象;若列表异步刷新, + // 则仅在当前选择失效时回退到第一项,避免覆盖用户的手动选择。 + useEffect(() => { + if (!adding) return; + setNewTaskInspectionObjectId(currentId => { + if (inspectionObjects.some(object => object.id === currentId)) { + return currentId; + } + return inspectionObjects[0]?.id ?? null; + }); + }, [adding, inspectionObjects]); + const createTask = trpc.inspectionTask.create.useMutation({ onSuccess: result => { pendingDefaultSelection.current = { @@ -692,6 +705,7 @@ export default function TaskManager({