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({ const longPressState = reactive({
pause: false, // replay: false, //
replay: false, //
}); });
// //
let longPressTimer = null; let longPressTimer = null;
//
let longPressTriggered = false;
// //
const handleLongPressStart = (buttonType) => { const handleLongPressStart = (buttonType) => {
@ -106,17 +107,17 @@ const handleLongPressStart = (buttonType) => {
clearTimeout(longPressTimer); clearTimeout(longPressTimer);
} }
longPressTriggered = false;
longPressState[buttonType] = true; longPressState[buttonType] = true;
// 800ms // 800ms
longPressTimer = setTimeout(() => { longPressTimer = setTimeout(() => {
if (buttonType === "pause" && dictationState.value === "playing") { longPressTriggered = true;
// = if (buttonType === "replay") {
stopDictation(); // =
} else if (buttonType === "replay") {
// =
showCurrentWord(); showCurrentWord();
} }
//
longPressState[buttonType] = false; longPressState[buttonType] = false;
}, 800); }, 800);
}; };
@ -127,7 +128,11 @@ const handleLongPressEnd = (buttonType) => {
clearTimeout(longPressTimer); clearTimeout(longPressTimer);
longPressTimer = null; longPressTimer = null;
} }
longPressState[buttonType] = false; //
if (!longPressTriggered) {
longPressState[buttonType] = false;
}
longPressTriggered = false;
}; };
// //
@ -594,13 +599,7 @@ onUnmounted(() => {
<template v-else-if="dictationState === 'playing'"> <template v-else-if="dictationState === 'playing'">
<button <button
class="control-btn pause-btn" class="control-btn pause-btn"
:class="{ pressing: longPressState.pause }"
@click="pauseDictation" @click="pauseDictation"
@mousedown="handleLongPressStart('pause')"
@mouseup="handleLongPressEnd('pause')"
@mouseleave="handleLongPressEnd('pause')"
@touchstart.prevent="handleLongPressStart('pause')"
@touchend="handleLongPressEnd('pause')"
> >
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -625,6 +624,7 @@ onUnmounted(() => {
@mouseleave="handleLongPressEnd('replay')" @mouseleave="handleLongPressEnd('replay')"
@touchstart.prevent="handleLongPressStart('replay')" @touchstart.prevent="handleLongPressStart('replay')"
@touchend="handleLongPressEnd('replay')" @touchend="handleLongPressEnd('replay')"
@touchcancel="handleLongPressEnd('replay')"
> >
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -683,6 +683,7 @@ onUnmounted(() => {
@mouseleave="handleLongPressEnd('replay')" @mouseleave="handleLongPressEnd('replay')"
@touchstart.prevent="handleLongPressStart('replay')" @touchstart.prevent="handleLongPressStart('replay')"
@touchend="handleLongPressEnd('replay')" @touchend="handleLongPressEnd('replay')"
@touchcancel="handleLongPressEnd('replay')"
> >
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -1438,11 +1439,6 @@ onUnmounted(() => {
opacity: 0.8; 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 { .replay-btn.pressing {
background: linear-gradient(135deg, var(--accent-5), #d97706); background: linear-gradient(135deg, var(--accent-5), #d97706);
color: white; color: white;