主要改动: 1. 后端修改: - 在 UserStatistics 模型中添加 wrong_questions 字段 - 在 GetStatistics 接口中查询并返回错题总数(包括已掌握和未掌握) 2. 前端修改: - 在 Statistics 接口中添加 wrong_questions 字段 - 在首页统计卡片中新增"错题数量"显示 - 调整布局为4列展示(题库总数、已答题数、错题数量、正确率) 3. UI优化: - 错题数量使用红色显示(#ff4d4f) - 响应式布局:移动端每行2个,PC端每行4个 - 与错题本页面的统计数据保持一致 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
31 lines
978 B
Go
31 lines
978 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// UserAnswerRecord 用户答题记录
|
|
type UserAnswerRecord struct {
|
|
gorm.Model
|
|
UserID uint `gorm:"index;not null" json:"user_id"` // 用户ID
|
|
QuestionID uint `gorm:"index;not null" json:"question_id"` // 题目ID
|
|
IsCorrect bool `gorm:"not null" json:"is_correct"` // 是否答对
|
|
AnsweredAt time.Time `gorm:"not null" json:"answered_at"` // 答题时间
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (UserAnswerRecord) TableName() string {
|
|
return "user_answer_records"
|
|
}
|
|
|
|
// UserStatistics 用户统计数据
|
|
type UserStatistics struct {
|
|
TotalQuestions int `json:"total_questions"` // 题库总数
|
|
AnsweredQuestions int `json:"answered_questions"` // 已答题数
|
|
CorrectAnswers int `json:"correct_answers"` // 答对题数
|
|
WrongQuestions int `json:"wrong_questions"` // 错题数量
|
|
Accuracy float64 `json:"accuracy"` // 正确率
|
|
}
|