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

@@ -0,0 +1,4 @@
export * from './types'
export * from './stats'
export * from './words'
export * from './review'

View File

@@ -0,0 +1,16 @@
import { http } from '../http'
import type { MemoryRecord, ReviewMode, ReviewResult } from './types'
export async function getReviewWords(params: { mode?: ReviewMode; limit?: number } = {}) {
const res = await http.get<{ data: MemoryRecord[] }>('/review', { params })
return res.data
}
export async function submitReview(payload: { recordId: number; answer: string; mode: ReviewMode }) {
const res = await http.post<{ data: ReviewResult }>('/review', {
record_id: payload.recordId,
answer: payload.answer,
mode: payload.mode
})
return res.data
}

View File

@@ -0,0 +1,7 @@
import { http } from '../http'
import type { Stats } from './types'
export async function getStatistics() {
const res = await http.get<{ data: Stats }>('/stats')
return res.data
}

View File

@@ -0,0 +1,35 @@
export interface Word {
id: number
word: string
phonetic_uk?: string
phonetic_us?: string
audio_uk?: string
audio_us?: string
part_of_speech?: string
definition?: string
}
export interface MemoryRecord {
id: number
word_id: number
correct_count: number
total_count: number
mastery_level: number
word?: Word
}
export interface Stats {
total_words: number
mastered_words: number
need_review: number
today_reviewed: number
}
export type ReviewMode = 'spelling' | 'en2cn' | 'cn2en'
export interface ReviewResult {
word: Word
correct: boolean
answer: string
correct_ans?: string
}

View File

@@ -0,0 +1,17 @@
import { http } from '../http'
import type { Word } from './types'
export async function addWord(word: string) {
const res = await http.post<{ data: Word }>('/words', { word })
return res.data
}
export async function getWords(params: { limit?: number; offset?: number } = {}) {
const res = await http.get<{ data: Word[]; total: number }>('/words', { params })
return res.data
}
export function audioUrl(word: string, type: 'uk' | 'us' = 'uk') {
const q = new URLSearchParams({ word, type })
return `/api/audio?${q.toString()}`
}