refactor(web): migrate to TypeScript + standard Vue3 structure
This commit is contained in:
4
memora-web/src/services/api/index.ts
Normal file
4
memora-web/src/services/api/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './types'
|
||||
export * from './stats'
|
||||
export * from './words'
|
||||
export * from './review'
|
||||
16
memora-web/src/services/api/review.ts
Normal file
16
memora-web/src/services/api/review.ts
Normal 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
|
||||
}
|
||||
7
memora-web/src/services/api/stats.ts
Normal file
7
memora-web/src/services/api/stats.ts
Normal 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
|
||||
}
|
||||
35
memora-web/src/services/api/types.ts
Normal file
35
memora-web/src/services/api/types.ts
Normal 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
|
||||
}
|
||||
17
memora-web/src/services/api/words.ts
Normal file
17
memora-web/src/services/api/words.ts
Normal 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()}`
|
||||
}
|
||||
Reference in New Issue
Block a user