|
252 | 252 | </div> |
253 | 253 |
|
254 | 254 | <div class="dojo-input-area"> |
255 | | - <input |
256 | | - ref="dojoInputRef" |
257 | | - v-model="dojoAnswer" |
258 | | - type="text" |
259 | | - class="search-input dojo-input" |
260 | | - :class="{ 'input-correct': dojoFeedback?.isCorrect, 'input-error': dojoFeedback && !dojoFeedback.isCorrect }" |
261 | | - placeholder="输入假名或罗马音..." |
262 | | - @compositionstart="isComposing = true" |
263 | | - @compositionend="isComposing = false" |
264 | | - @keyup.enter="handleDojoEnter" |
265 | | - :disabled="!!dojoFeedback" |
266 | | - autocomplete="off" |
267 | | - > |
| 255 | + <div class="dojo-input-wrapper"> |
| 256 | + <input |
| 257 | + ref="dojoInputRef" |
| 258 | + v-model="dojoAnswer" |
| 259 | + type="text" |
| 260 | + class="search-input dojo-input" |
| 261 | + :class="{ 'input-correct': dojoFeedback?.isCorrect, 'input-error': dojoFeedback && !dojoFeedback.isCorrect }" |
| 262 | + placeholder="输入假名或罗马音..." |
| 263 | + @compositionstart="isComposing = true" |
| 264 | + @compositionend="isComposing = false" |
| 265 | + @keyup.enter="handleDojoEnter" |
| 266 | + :disabled="!!dojoFeedback" |
| 267 | + autocomplete="off" |
| 268 | + > |
| 269 | + <button |
| 270 | + v-if="dojoAnswer && !dojoFeedback" |
| 271 | + class="dojo-clear-btn" |
| 272 | + @click="clearDojoInput" |
| 273 | + title="清除输入" |
| 274 | + > |
| 275 | + <Icon name="x" class="icon-x" /> |
| 276 | + </button> |
| 277 | + </div> |
268 | 278 | <button v-if="!dojoFeedback" class="search-btn" @click="checkDojoAnswer" :disabled="!dojoAnswer.trim()">提交</button> |
269 | 279 | <button v-else class="search-btn btn-next" @click="nextDojoQuestion"> |
270 | 280 | {{ dojoCurrentIndex < dojoQuestions.length - 1 ? '下一题' : '查看成绩' }} |
@@ -484,6 +494,13 @@ const checkDojoAnswer = () => { |
484 | 494 | dojoFeedback.value = { isCorrect, correctAnswer: q.answer }; |
485 | 495 | }; |
486 | 496 |
|
| 497 | +const clearDojoInput = () => { |
| 498 | + dojoAnswer.value = ''; |
| 499 | + nextTick(() => { |
| 500 | + dojoInputRef.value?.focus(); |
| 501 | + }); |
| 502 | +}; |
| 503 | +
|
487 | 504 | const nextDojoQuestion = () => { |
488 | 505 | if (dojoCurrentIndex.value < dojoQuestions.value.length - 1) { |
489 | 506 | dojoCurrentIndex.value++; |
@@ -2030,16 +2047,49 @@ ruby rt { |
2030 | 2047 | display: flex; |
2031 | 2048 | gap: 12px; |
2032 | 2049 | margin-bottom: 24px; |
| 2050 | + justify-content: center; |
| 2051 | +} |
| 2052 | +
|
| 2053 | +.dojo-input-wrapper { |
| 2054 | + position: relative; |
| 2055 | + display: flex; |
| 2056 | + align-items: center; |
2033 | 2057 | } |
2034 | 2058 |
|
2035 | 2059 | .dojo-input { |
2036 | 2060 | border: 2px solid var(--surface-border); |
2037 | 2061 | border-radius: var(--radius-md); |
2038 | | - padding: 12px 16px; |
| 2062 | + padding: 12px 36px 12px 16px; /* Added right padding for the clear button */ |
2039 | 2063 | font-size: 1.2em; |
2040 | 2064 | text-align: center; |
2041 | 2065 | transition: all 0.3s; |
2042 | 2066 | background: rgba(255, 255, 255, 0.8); |
| 2067 | + width: 100%; |
| 2068 | +} |
| 2069 | +
|
| 2070 | +.dojo-clear-btn { |
| 2071 | + position: absolute; |
| 2072 | + right: 10px; |
| 2073 | + background: none; |
| 2074 | + border: none; |
| 2075 | + color: #94a3b8; |
| 2076 | + cursor: pointer; |
| 2077 | + padding: 4px; |
| 2078 | + display: flex; |
| 2079 | + align-items: center; |
| 2080 | + justify-content: center; |
| 2081 | + border-radius: 50%; |
| 2082 | + transition: all 0.2s; |
| 2083 | +} |
| 2084 | +
|
| 2085 | +.dojo-clear-btn:hover { |
| 2086 | + color: #475569; |
| 2087 | + background: rgba(0, 0, 0, 0.05); |
| 2088 | +} |
| 2089 | +
|
| 2090 | +.icon-x { |
| 2091 | + width: 16px; |
| 2092 | + height: 16px; |
2043 | 2093 | } |
2044 | 2094 |
|
2045 | 2095 | .dojo-input:focus { |
|
0 commit comments