refactor: 新增 useElapsedSeconds 统一秒表计时

This commit is contained in:
2026-08-27 21:48:28 +08:00
parent 96cc57ae06
commit 468bba8670
3 changed files with 136 additions and 11 deletions
+18 -11
View File
@@ -13,6 +13,7 @@ import {
} from "@/api/standardMindMap";
import { ElMessage, ElMessageBox } from "element-plus";
import MindMapViewer, { type MindMapTreeNode } from "@/components/MindMapViewer.vue";
import { useElapsedSeconds } from "@/components/composables/useElapsedSeconds";
const route = useRoute();
const router = useRouter();
@@ -21,12 +22,20 @@ const taskNum = computed(() => route.params.taskNum as string);
const loading = ref(false);
const standard = ref<StandardMindMap | null>(null);
const comparing = ref(false);
const comparingSeconds = ref(0);
let comparingTimer: ReturnType<typeof setInterval> | null = null;
const {
seconds: comparingSeconds,
start: startComparingTimer,
stop: stopComparingTimer,
} = useElapsedSeconds();
// 重新生成标准导图
const regenerating = ref(false);
const regeneratingSeconds = ref(0);
let regeneratingTimer: ReturnType<typeof setInterval> | null = null;
const {
seconds: regeneratingSeconds,
start: startRegeneratingTimer,
stop: stopRegeneratingTimer,
} = useElapsedSeconds();
const lastResult = ref<any>(null);
const hasCompared = ref(false);
@@ -127,7 +136,7 @@ const loadData = async () => {
// 匹配失败时仍可进入回忆页
}
}
} catch (e: any) {
} catch {
standard.value = null;
} finally {
loading.value = false;
@@ -201,8 +210,7 @@ const handleRegenerate = async () => {
// 开始生成
regenerating.value = true;
regeneratingSeconds.value = 0;
regeneratingTimer = setInterval(() => { regeneratingSeconds.value++; }, 1000);
startRegeneratingTimer();
try {
const res = await regenerateStandardMindMap(taskNum.value, mode);
standard.value = res?.data || null;
@@ -211,7 +219,7 @@ const handleRegenerate = async () => {
ElMessage.error(e.message || "重新生成失败");
} finally {
regenerating.value = false;
if (regeneratingTimer) { clearInterval(regeneratingTimer); regeneratingTimer = null; }
stopRegeneratingTimer();
}
};
@@ -223,8 +231,7 @@ const handleRecallCompare = async () => {
return;
}
comparing.value = true;
comparingSeconds.value = 0;
comparingTimer = setInterval(() => { comparingSeconds.value++; }, 1000);
startComparingTimer();
try {
const res = await recallCompare(taskNum.value, outline, focusPath.value || undefined);
standard.value = res?.data || null;
@@ -248,7 +255,7 @@ const handleRecallCompare = async () => {
ElMessage.error(e.message || "对比失败");
} finally {
comparing.value = false;
if (comparingTimer) { clearInterval(comparingTimer); comparingTimer = null; }
stopComparingTimer();
}
};