diff --git a/src/common/color.ts b/src/common/color.ts index ff4c648..f91144e 100644 --- a/src/common/color.ts +++ b/src/common/color.ts @@ -134,3 +134,12 @@ export function removeAllCustomCssValue() { removeCustomCssValue(COLOR_ENUM['GRAY_02']); removeCustomCssValue(COLOR_ENUM['LABEL_WHITE']); } + +export function getRandomColor(): string { + const letters = '0123456789ABCDEF'; + let color = '#'; + for (let i = 0; i < 6; i++) { + color += letters[Math.floor(Math.random() * 16)]; + } + return color; +} diff --git a/src/components/WordInput.vue b/src/components/WordInput.vue index 596f017..1d0ef74 100644 --- a/src/components/WordInput.vue +++ b/src/components/WordInput.vue @@ -351,7 +351,8 @@ watch( }); const wrongLength = wrongPos.length; const wordLength = inputTextArr.length; - const accuracy = (((wordLength - wrongLength) / wordLength) * 100).toFixed(0) + '%'; + const accuracy = + wordLength === 0 ? '0%' : (((wordLength - wrongLength) / wordLength) * 100).toFixed(0) + '%'; emit('typingInfo', { wordLength, wrongLength, @@ -426,6 +427,10 @@ function focusInput() { inputAreaRef.value.focus(); moveCaretToEnd(inputAreaRef.value); } +function blurInput() { + if (!inputAreaRef.value) return; + inputAreaRef.value.blur(); +} function moveCaretToEnd(element: HTMLElement) { // 使光标移动到末尾 @@ -520,6 +525,7 @@ function getTypingRecord() { defineExpose({ focusInput, + blurInput, getTypingRecord }); @@ -534,8 +540,7 @@ defineExpose({
{{ item.word }}