const app = getApp() const deckTemplate = [ { word: 'prosperity', meaning: 'n. 繁荣, 兴旺', answer: 'pe' }, { word: 'sustainable', meaning: 'adj. 可持续的', answer: 'sus' }, { word: 'acquire', meaning: 'v. 获取, 获得', answer: 'ac' }, { word: 'abstract', meaning: 'adj. 抽象的', answer: 'ab' }, { word: 'benevolent', meaning: 'adj. 仁慈的', answer: 'be' }, ] Page({ data: { progress: 0, current: 1, total: 0, word: '', meaning: '', answer: '', feedback: '', showFeedback: false, completed: false, masterHint: false, }, onLoad() { if (!app.globalData.reviewSession.deck.length) { const { questionCount, shuffle } = app.globalData.reviewPlan let deck = deckTemplate.slice(0, Math.max(1, Math.min(questionCount, deckTemplate.length))) if (shuffle) deck = deck.slice().sort(() => Math.random() - 0.5) app.globalData.reviewSession = { deck, currentIndex: 0, correctCount: 0, wrongCount: 0, completed: false, currentAnswer: '', } } this.syncSession() }, syncSession() { const session = app.globalData.reviewSession const current = session.deck[session.currentIndex] const total = session.deck.length || 1 this.setData({ progress: Math.round((session.currentIndex / total) * 100), current: session.currentIndex + 1, total, word: current?.word || '', meaning: current?.meaning || '', answer: session.currentAnswer || '', feedback: '', showFeedback: false, completed: session.completed, masterHint: false, }) }, onAnswerInput(e) { const answer = e.detail.value app.globalData.reviewSession.currentAnswer = answer this.setData({ answer }) }, checkAnswer() { const session = app.globalData.reviewSession const current = session.deck[session.currentIndex] if (!current) return const correct = (this.data.answer || '').trim().toLowerCase() === current.answer.toLowerCase() session.correctCount += correct ? 1 : 0 session.wrongCount += correct ? 0 : 1 this.setData({ feedback: correct ? '回答正确' : `正确答案:${current.answer}`, showFeedback: true, }) }, nextQuestion() { const session = app.globalData.reviewSession if (!session.deck.length) return if (session.currentIndex >= session.deck.length - 1) { session.completed = true wx.navigateTo({ url: '/pages/review-result/review-result' }) return } session.currentIndex += 1 session.currentAnswer = '' this.syncSession() }, markMastered() { this.setData({ masterHint: true }) wx.showToast({ title: '已标记', icon: 'success' }) }, })