diff --git a/apps/client/components/main/Question/Question.vue b/apps/client/components/main/Question/Question.vue index 6770c1f92..2d8a852e7 100644 --- a/apps/client/components/main/Question/Question.vue +++ b/apps/client/components/main/Question/Question.vue @@ -70,7 +70,7 @@ const { getInputCursorPosition, inputChangedCallback, }); -const { hiddenAnswerTip } = useAnswerTip(); +const { showAnswerTip, hiddenAnswerTip } = useAnswerTip(); watch( () => inputValue.value, @@ -175,6 +175,24 @@ function inputWidth(word: string) { return width; } +function answerError() { + let wrongTimes = 0; + + function handleAnswerError() { + playErrorSound(); + wrongTimes++; + if (wrongTimes >= 3) { + showAnswerTip(); + } + } + + return { + handleAnswerError, + }; +} + +const { handleAnswerError } = answerError(); + function handleKeydown(e: KeyboardEvent) { if (e.code === "Enter") { e.stopPropagation(); @@ -182,11 +200,11 @@ function handleKeydown(e: KeyboardEvent) { () => { playRightSound(); // 正确提示 showAnswer(); + hiddenAnswerTip(); }, - playErrorSound // 错误提示 + handleAnswerError // 错误提示 ); - hiddenAnswerTip(); return; } @@ -197,9 +215,7 @@ function handleKeydown(e: KeyboardEvent) { playRightSound(); // 正确提示 showAnswer(); }, - errorCallback: () => { - playErrorSound(); - }, + errorCallback: handleAnswerError, // 错误提示 }, }); }