JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
修改多次点击会新建多个定时任务的问题
yt2026b42c140d7823
diff --git a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/CronTaskDrawer.tsx b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/CronTaskDrawer.tsxindex ccbc8df435..02a889981f 100644--- a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/CronTaskDrawer.tsx+++ b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/CronTaskDrawer.tsx@@ -121,6 +121,8 @@ interface CronTaskDrawerProps {maxEnabledJobs?: number;/** 正在编辑的任务当前算运行中。已在跑的任务改名称或时间,不占新的名额。 */editingCurrentlyRunning?: boolean;+ /** 提交请求进行中:禁用确定按钮防连点重复提交(对齐 ConfirmDialog.loading 的角色) */+ submitting?: boolean;onClose: () => void;onSubmit: (value: CronTaskFormValue) => void;onSwitchToManual?: () => void;@@ -138,7 +140,7 @@ function filterNonDefaultProjects(projects: ProjectInfo[]): ProjectInfo[] {return projects.filter((p) => !isDefaultLikeProject(p));}-export default function CronTaskDrawer({ mode, initial, projects, targetOptions, proactiveLocked = false, enabledQuotaFull = false, maxEnabledJobs = 5, editingCurrentlyRunning = false, onClose, onSubmit, onSwitchToManual, onSwitchToTemplate }: CronTaskDrawerProps) {+export default function CronTaskDrawer({ mode, initial, projects, targetOptions, proactiveLocked = false, enabledQuotaFull = false, maxEnabledJobs = 5, editingCurrentlyRunning = false, submitting = false, onClose, onSubmit, onSwitchToManual, onSwitchToTemplate }: CronTaskDrawerProps) {const { t } = useTranslation();const enterpriseMode = isEnterprise();const [form, setForm] = useState<CronTaskFormValue>(initial ?? emptyForm());@@ -378,8 +380,8 @@ export default function CronTaskDrawer({ mode, initial, projects, targetOptions,<span title={missingFieldsHint}><buttononClick={() => onSubmit(form)}- disabled={!canSubmit}- className="rounded-full bg-cron-action px-10 py-1.5 text-sm font-bold text-cron-action-foreground hover:bg-cron-action-hover disabled:opacity-50"+ disabled={!canSubmit || submitting}+ className="rounded-full bg-cron-action px-10 py-1.5 text-sm font-bold text-cron-action-foreground hover:bg-cron-action-hover disabled:cursor-not-allowed disabled:opacity-50">{t('cron.actions.confirm')}</button>diff --git a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/index.tsx b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/index.tsxindex 6f1b862b48..c27a3becb5 100644--- a/jiuwenswarm/channels/web/frontend/src/components/CronPanel/index.tsx+++ b/jiuwenswarm/channels/web/frontend/src/components/CronPanel/index.tsx@@ -300,6 +300,10 @@ export default function CronPanel({ sessionId, onCreateViaChat, onSelectSessionconst [confirmState, setConfirmState] = useState<{ type: 'delete' | 'stop' | 'runNow'; job: CronTaskUI } | null>(null);const [confirmBusy, setConfirmBusy] = useState(false);+ // confirmBusy 的同步镜像:React state 的置位要等重渲染提交后才对后续事件可见,而两次 click+ // 若落在同一个 JS 任务里(自动化工具一次调用连发两次 DOM click),中间没有任何让出点,+ // state 版 guard 和按钮 disabled 都来不及生效。ref 赋值即时生效,专门兜住这类合成连点。+ const confirmBusyRef = useRef(false);const channelLabel = useCallback((targets: string) => (KNOWN_TARGET_KEYS.includes(targets) ? t(`cron.targets.${targets}`) : targets),@@ -535,10 +539,13 @@ export default function CronPanel({ sessionId, onCreateViaChat, onSelectSessionconst expiredCount = useMemo(() => jobs.filter((j) => jobStatusKey(j) === 'expired').length, [jobs]);async function handleCreateSubmit(value: CronTaskFormValue) {+ if (confirmBusyRef.current) return; // 防重入:请求在途时忽略再次提交(连点确定会各发一个 cron.job.create),与下方三个确认弹窗同一模式;用 ref 做同步闸,见 confirmBusyRef 注释if (value.enabled && runningCount >= maxEnabledJobs) {setError(t('cron.errors.enabledQuotaReached', { max: maxEnabledJobs }));return;}+ confirmBusyRef.current = true;+ setConfirmBusy(true);try {const isOnce = cronExprToSchedule(value.cronExpr.trim())?.kind === 'once';await webRequest<{ job: CronJobDTO }>('cron.job.create', {@@ -585,16 +592,23 @@ export default function CronPanel({ sessionId, onCreateViaChat, onSelectSessionconst reason = createError instanceof Error ? createError.message.trim() : '';const message = reason ? t('cron.errors.createFailedWithReason', { reason }) : t('cron.errors.createFailed');setError(message);+ } finally {+ // 失败时抽屉保持打开(catch 已 setError),这里复位 busy 让确定按钮恢复可点、可正常重试+ confirmBusyRef.current = false;+ setConfirmBusy(false);}}async function handleEditSubmit(jobId: string, value: CronTaskFormValue) {+ if (confirmBusyRef.current) return; // 防重入:同 handleCreateSubmit,编辑保存(cron.job.update)连点同样只发一次;ref 同步闸见 confirmBusyRef 注释const existing = jobs.find((job) => job.id === jobId);const wasRunning = existing ? jobStatusKey(existing) === 'running' : false;if (!wasRunning && value.enabled && runningCount >= maxEnabledJobs) {setError(t('cron.errors.enabledQuotaReached', { max: maxEnabledJobs }));return;}+ confirmBusyRef.current = true;+ setConfirmBusy(true);try {const isProactive = jobId === PROACTIVE_AUTO_JOB_ID;const isOnce = cronExprToSchedule(value.cronExpr.trim())?.kind === 'once';@@ -633,6 +647,9 @@ export default function CronPanel({ sessionId, onCreateViaChat, onSelectSessionconst reason = updateError instanceof Error ? updateError.message.trim() : '';const message = reason ? t('cron.errors.updateFailedWithReason', { reason }) : t('cron.errors.updateFailed');setError(message);+ } finally {+ confirmBusyRef.current = false;+ setConfirmBusy(false); // 同 handleCreateSubmit:失败后复位,按钮恢复可点}}@@ -1316,6 +1333,7 @@ export default function CronPanel({ sessionId, onCreateViaChat, onSelectSessionenabledQuotaFull={enabledQuotaFull}maxEnabledJobs={maxEnabledJobs}editingCurrentlyRunning={editingCurrentlyRunning}+ submitting={confirmBusy}onClose={() => setDrawer(null)}onSwitchToManual={drawer.mode === 'template' ? () => setDrawer({ mode: 'create', initial: drawer.initial }) : undefined}onSwitchToTemplate={drawer.mode === 'create' ? () => { setDrawer(null); setActiveTab('template'); } : undefined}