fix(practice): 修复长按状态处理逻辑

This commit is contained in:
cc 2026-04-15 21:10:06 +08:00
parent 3a00bd64db
commit 0aca637b06
1 changed files with 15 additions and 19 deletions

View File

@ -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(() => {
<template v-else-if="dictationState === 'playing'">
<button
class="control-btn pause-btn"
:class="{ pressing: longPressState.pause }"
@click="pauseDictation"
@mousedown="handleLongPressStart('pause')"
@mouseup="handleLongPressEnd('pause')"
@mouseleave="handleLongPressEnd('pause')"
@touchstart.prevent="handleLongPressStart('pause')"
@touchend="handleLongPressEnd('pause')"
>
<svg
xmlns="http://www.w3.org/2000/svg"
@ -625,6 +624,7 @@ onUnmounted(() => {
@mouseleave="handleLongPressEnd('replay')"
@touchstart.prevent="handleLongPressStart('replay')"
@touchend="handleLongPressEnd('replay')"
@touchcancel="handleLongPressEnd('replay')"
>
<svg
xmlns="http://www.w3.org/2000/svg"
@ -683,6 +683,7 @@ onUnmounted(() => {
@mouseleave="handleLongPressEnd('replay')"
@touchstart.prevent="handleLongPressStart('replay')"
@touchend="handleLongPressEnd('replay')"
@touchcancel="handleLongPressEnd('replay')"
>
<svg
xmlns="http://www.w3.org/2000/svg"
@ -1438,11 +1439,6 @@ onUnmounted(() => {
opacity: 0.8;
}
.pause-btn.pressing {
background: linear-gradient(135deg, #dc2626, #b91c1c);
box-shadow: 0 2px 10px rgba(239, 68, 68, 0.4);
}
.replay-btn.pressing {
background: linear-gradient(135deg, var(--accent-5), #d97706);
color: white;