refactor(web): migrate to TypeScript + standard Vue3 structure

This commit is contained in:
2026-02-26 12:29:25 +08:00
parent 52f691f02e
commit e2a9ebc7b7
28 changed files with 814 additions and 88 deletions

View File

@@ -22,10 +22,10 @@
<el-button @click="play">播放读音(uk)</el-button>
</template>
<template v-else-if="mode === 'en2cn'">
<div class="q">{{ record.word.word }}</div>
<div class="q">{{ record.word?.word }}</div>
</template>
<template v-else>
<div class="q">{{ record.word.definition }}</div>
<div class="q">{{ record.word?.definition }}</div>
</template>
</el-card>
@@ -46,15 +46,17 @@
</div>
</template>
<script setup>
<script setup lang="ts">
import { computed, ref } from 'vue'
import { audioUrl, getReviewWords, submitReview } from '../services/api'
const mode = ref('spelling')
const record = ref(null) // MemoryRecord (含 word)
import type { MemoryRecord, ReviewMode, ReviewResult } from '../services/api'
const mode = ref<ReviewMode>('spelling')
const record = ref<MemoryRecord | null>(null) // MemoryRecord (含 word)
const answer = ref('')
const loading = ref(false)
const result = ref(null)
const result = ref<ReviewResult | null>(null)
const modeHint = computed(() => {
if (mode.value === 'spelling') return '听读音,拼写单词'
@@ -65,14 +67,14 @@ const modeHint = computed(() => {
async function loadOne() {
result.value = null
answer.value = ''
const res = await getReviewWords({ mode: mode.value, limit: 1 })
const arr = res.data ?? res
record.value = Array.isArray(arr) && arr.length ? arr[0] : null
const res = await getReviewWords({ mode: mode.value, limit: 1 })
const arr = (res as any).data ?? (res as any)
record.value = Array.isArray(arr) && arr.length ? (arr[0] as MemoryRecord) : null
}
function play() {
if (!record.value?.word?.word) return
const a = new Audio(audioUrl({ word: record.value.word.word, type: 'uk' }))
const a = new Audio(audioUrl(record.value.word.word, 'uk'))
a.play()
}
@@ -82,7 +84,7 @@ async function submit() {
loading.value = true
try {
const res = await submitReview({ recordId: record.value.id, answer: answer.value, mode: mode.value })
result.value = res.data ?? res
result.value = (res as any).data ?? (res as any)
} finally {
loading.value = false
}