From 78ddc17fce8a57e23592a1eb928732016d7680a5 Mon Sep 17 00:00:00 2001 From: CNWei Date: Wed, 4 Nov 2026 23:02:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20=E7=A8=B3=E5=AE=9A=E8=99=9A?= =?UTF-8?q?=E6=8B=9F=E7=8E=AF=E5=A2=83=E6=8E=A2=E6=B5=8B=E7=8A=B6=E6=80=81?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E8=BE=93=E5=85=A5=E6=97=B6=E9=97=AA?= =?UTF-8?q?=E7=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 探测状态保留上一次结果,新结果返回后再更新;空目录改为中性提示;防抖期间不因旧工作目录闪出警告;占位数据期间不自动回填虚拟环境。 --- frontend/src/components/TaskEditorModal.tsx | 48 +++++++++++++-------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/TaskEditorModal.tsx b/frontend/src/components/TaskEditorModal.tsx index 1d38891..d3bf386 100644 --- a/frontend/src/components/TaskEditorModal.tsx +++ b/frontend/src/components/TaskEditorModal.tsx @@ -1,5 +1,10 @@ import { zodResolver } from '@hookform/resolvers/zod' -import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' +import { + keepPreviousData, + useMutation, + useQuery, + useQueryClient, +} from '@tanstack/react-query' import { Button, Checkbox, @@ -209,6 +214,7 @@ export function TaskEditorModal({ actionType === 'script' && isPythonScript && Boolean(debouncedWorkingDir.trim()), + placeholderData: keepPreviousData, retry: false, staleTime: 15_000, }) @@ -230,7 +236,9 @@ export function TaskEditorModal({ onError: (error) => toast.error(error.message), }) const linkedVenv = - isPythonScript && venvProbe.data?.status === 'linked' + isPythonScript && + !venvProbe.isPlaceholderData && + venvProbe.data?.status === 'linked' ? venvProbe.data : null const previewVirtualEnv = isPythonScript @@ -270,7 +278,7 @@ export function TaskEditorModal({ // 探测到虚拟环境就自动填进「虚拟环境目录」,但用户自己改过就保留用户的值。 useEffect(() => { - if (!open || !isPythonScript) { + if (!open || !isPythonScript || venvProbe.isPlaceholderData) { return } const probe = venvProbe.data @@ -295,7 +303,7 @@ export function TaskEditorModal({ shouldDirty: true, shouldValidate: true, }) - }, [debouncedVenv, debouncedWorkingDir, getValues, isPythonScript, open, setValue, venvProbe.data]) + }, [debouncedVenv, debouncedWorkingDir, getValues, isPythonScript, open, setValue, venvProbe.data, venvProbe.isPlaceholderData]) // 打开后把焦点给第一个可编辑字段:新建时是任务标识,编辑时 ID 已锁定,跳名称。 // 原生 dialog 默认聚焦关闭按钮,不符合编辑表单的节奏。 @@ -595,7 +603,7 @@ export function TaskEditorModal({ - - ● 请输入有效的工作目录以探测环境 - + 填写工作目录后自动检测环境 ) } - if (pending) { + if (!probe) { + if (pending) { + return ( +
+ ⏳ 正在检测环境... +
+ ) + } + if (failed) { + return ( +
+ ● 环境探测失败,可稍后重试 +
+ ) + } return (
- ⏳ 正在探测解释器... -
- ) - } - - if (failed || !probe) { - return ( -
- ● 环境探测失败,可稍后重试 + 正在检测环境...
) }