57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
accuracy: 0,
|
|
timeUsed: '--:--',
|
|
total: 0,
|
|
mastered: 0,
|
|
reviewNeeded: 0,
|
|
improved: 0,
|
|
regressed: 0,
|
|
loading: false,
|
|
error: '',
|
|
},
|
|
onLoad() {
|
|
this.loadResult()
|
|
},
|
|
loadResult() {
|
|
const sessionId = app.globalData.reviewSessionMeta?.id
|
|
const fallbackSession = app.globalData.reviewSession
|
|
if (!sessionId && !fallbackSession?.completed) {
|
|
this.setData({ error: '暂无复习结果' })
|
|
return
|
|
}
|
|
this.setData({ loading: true, error: '' })
|
|
wx.request({
|
|
url: `${app.globalData.baseUrl}/api/v1/review-result?session_id=${sessionId}`,
|
|
header: { 'X-OpenID': app.globalData.openid || '' },
|
|
success: (res) => {
|
|
const data = res.data?.data || {}
|
|
const total = Number(data.total || 0)
|
|
const correct = Number(data.correct || 0)
|
|
const wrong = Number(data.wrong || Math.max(0, total - correct))
|
|
const accuracy = total ? Math.round((correct / total) * 100) : 0
|
|
this.setData({
|
|
total,
|
|
accuracy,
|
|
mastered: Number(data.mastered ?? correct),
|
|
reviewNeeded: Number(data.review_needed ?? wrong),
|
|
improved: Number(data.improved ?? 0),
|
|
regressed: Number(data.regressed ?? 0),
|
|
timeUsed: data.time_used || '--:--',
|
|
})
|
|
},
|
|
fail: () => this.setData({ error: '结果加载失败' }),
|
|
complete: () => this.setData({ loading: false }),
|
|
})
|
|
},
|
|
restart() {
|
|
app.globalData.reviewSession = { deck: [], currentIndex: 0, correctCount: 0, wrongCount: 0, completed: false, currentAnswer: '' }
|
|
wx.reLaunch({ url: '/pages/review-config/review-config' })
|
|
},
|
|
goHome() {
|
|
wx.reLaunch({ url: '/pages/index/index' })
|
|
},
|
|
})
|