diff --git a/src/views/SpellPractice.vue b/src/views/SpellPractice.vue index 3adb5c2..cd58626 100644 --- a/src/views/SpellPractice.vue +++ b/src/views/SpellPractice.vue @@ -92,12 +92,13 @@ let audioCache = new Map(); // 缓存已生成的音频 // 长按状态 const longPressState = reactive({ - pause: false, // 暂停按钮是否正在长按 - replay: false, // 重播按钮是否正在长按 + replay: false, // 跟读按钮是否正在长按 }); // 长按定时器 let longPressTimer = null; +// 标记长按是否已经触发(避免重复执行) +let longPressTriggered = false; // 长按开始 const handleLongPressStart = (buttonType) => { @@ -106,17 +107,17 @@ const handleLongPressStart = (buttonType) => { clearTimeout(longPressTimer); } + longPressTriggered = false; longPressState[buttonType] = true; // 设置长按触发时间(800ms) longPressTimer = setTimeout(() => { - if (buttonType === "pause" && dictationState.value === "playing") { - // 长按暂停按钮 = 停止听写 - stopDictation(); - } else if (buttonType === "replay") { - // 长按重播按钮 = 显示当前单词 + longPressTriggered = true; + if (buttonType === "replay") { + // 长按跟读按钮 = 显示当前单词 showCurrentWord(); } + // 长按触发后重置状态 longPressState[buttonType] = false; }, 800); }; @@ -127,7 +128,11 @@ const handleLongPressEnd = (buttonType) => { clearTimeout(longPressTimer); longPressTimer = null; } - longPressState[buttonType] = false; + // 只有当长按未触发时才重置状态(已触发时已在定时器中重置) + if (!longPressTriggered) { + longPressState[buttonType] = false; + } + longPressTriggered = false; }; // 显示当前单词(用于听写时查看答案) @@ -594,13 +599,7 @@ onUnmounted(() => {