From defeb018082de52efcf7e2d570068ba3e3accb98 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Tue, 17 Mar 2026 14:50:57 +0800 Subject: [PATCH] fix: show elapsed time in execution result dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove setStartTime(null) from finally block to preserve start time for result display - Add resetStartTime function to useCleaner hook - Call resetStartTime when execution report dialog closes - Add useEffect to update timer when execution completes Now the total elapsed time (总耗时) will be shown in the result dialog after execution completes. --- .../src/components/ExecutionReportDialog.tsx | 54 +++++++++++++++++++ src/renderer/src/hooks/useCleaner.ts | 8 ++- src/renderer/src/pages/CleanerPage.tsx | 6 ++- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/ExecutionReportDialog.tsx b/src/renderer/src/components/ExecutionReportDialog.tsx index 4494460..99f77f4 100644 --- a/src/renderer/src/components/ExecutionReportDialog.tsx +++ b/src/renderer/src/components/ExecutionReportDialog.tsx @@ -61,6 +61,7 @@ export const ExecutionReportDialog: React.FC = ({ const showProgress = isExecuting && progress const isProgressing = !!showProgress + // Update timer during progress React.useEffect(() => { if (!showProgress || !startTime) return @@ -71,6 +72,27 @@ export const ExecutionReportDialog: React.FC = ({ return () => clearInterval(interval) }, [showProgress, startTime]) + // Update time when execution completes + React.useEffect(() => { + if (showProgress === false && startTime && isExecuting === false) { + setNow(Date.now()) + } + }, [showProgress, isExecuting, startTime]) + + const elapsedTime = React.useMemo(() => { + if (!startTime) return null + + const elapsedMs = now - startTime + const elapsedSeconds = Math.floor(elapsedMs / 1000) + const minutes = Math.floor(elapsedSeconds / 60) + const seconds = elapsedSeconds % 60 + + return { + totalSeconds: elapsedSeconds, + formatted: minutes > 0 ? `${minutes}分${seconds}秒` : `${seconds}秒` + } + }, [startTime, now]) + const estimatedTime = React.useMemo(() => { if (!showProgress || !startTime || !progress) return null @@ -204,6 +226,15 @@ export const ExecutionReportDialog: React.FC = ({ )} + {elapsedTime && ( +
+
+ 已运行 + {elapsedTime.formatted} +
+
+ )} + {estimatedTime && (
@@ -307,6 +338,29 @@ export const ExecutionReportDialog: React.FC = ({ )}
+ {elapsedTime && ( +
+ + + + + + 总耗时:{elapsedTime.formatted} + +
+ )} + {hasErrors && (
错误详情
diff --git a/src/renderer/src/hooks/useCleaner.ts b/src/renderer/src/hooks/useCleaner.ts index 19e4153..b9c0e10 100644 --- a/src/renderer/src/hooks/useCleaner.ts +++ b/src/renderer/src/hooks/useCleaner.ts @@ -471,10 +471,15 @@ export function useCleaner() { setIsRunning(false) setIsExecuting(false) setProgress(null) - setStartTime(null) + // Note: Don't clear startTime here - it's needed for the execution report dialog + // startTime will be reset when the dialog closes and a new execution starts } } + const resetStartTime = useCallback(() => { + setStartTime(null) + }, []) + const handleExportResults = async () => { if (filteredResults.length === 0) { showWarning('没有数据可导出') @@ -554,6 +559,7 @@ export function useCleaner() { handleAssignManagerOnSelect, progress, startTime, + resetStartTime, handleValidation, handleCheckboxToggle, handleConfirmDeletion, diff --git a/src/renderer/src/pages/CleanerPage.tsx b/src/renderer/src/pages/CleanerPage.tsx index a661806..df8069c 100644 --- a/src/renderer/src/pages/CleanerPage.tsx +++ b/src/renderer/src/pages/CleanerPage.tsx @@ -64,6 +64,7 @@ const CleanerPage: React.FC = () => { handleAssignManagerOnSelect, progress, startTime, + resetStartTime, handleValidation, handleCheckboxToggle, handleConfirmDeletion, @@ -509,7 +510,10 @@ const CleanerPage: React.FC = () => { {/* Execution Report Dialog */} setIsReportDialogOpen(false)} + onClose={() => { + setIsReportDialogOpen(false) + resetStartTime() + }} ordersProcessed={reportData?.ordersProcessed} materialsDeleted={reportData?.materialsDeleted} materialsSkipped={reportData?.materialsSkipped}