主要改动: 1. 组件拆分:将Question.tsx(605行)拆分为4个子组件(303行) - QuestionProgress: 进度条和统计显示 - QuestionCard: 题目卡片和答题界面 - AnswerResult: 答案结果展示 - CompletionSummary: 完成统计摘要 2. 新增功能: - 答题进度条:显示当前进度、正确数、错误数 - 进度保存:使用localStorage持久化答题进度 - 完成统计:答完所有题目后显示统计摘要和正确率 - 从第一题开始:改为顺序答题而非随机 3. UI优化: - 移除右上角统计按钮 - 移除底部随机题目、题目列表、筛选按钮 - 移除"开始xxx答题"提示消息 - 简化页面布局 4. 代码优化: - 提高代码可维护性和可测试性 - 单一职责原则,每个组件负责一个特定功能 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
43 lines
1.9 KiB
Go
43 lines
1.9 KiB
Go
package models
|
|
|
|
import "gorm.io/gorm"
|
|
|
|
// PracticeQuestion 练习题目模型
|
|
type PracticeQuestion struct {
|
|
gorm.Model
|
|
QuestionID string `gorm:"size:50;not null" json:"question_id"` // 题目ID (原JSON中的id字段)
|
|
Type string `gorm:"index;size:30;not null" json:"type"` // 题目类型
|
|
TypeName string `gorm:"size:50" json:"type_name"` // 题型名称(中文)
|
|
Question string `gorm:"type:text;not null" json:"question"` // 题目内容
|
|
AnswerData string `gorm:"type:text;not null" json:"-"` // 答案数据(JSON格式存储)
|
|
OptionsData string `gorm:"type:text" json:"-"` // 选项数据(JSON格式存储,用于选择题)
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (PracticeQuestion) TableName() string {
|
|
return "practice_questions"
|
|
}
|
|
|
|
// PracticeQuestionDTO 用于前端返回的数据传输对象
|
|
type PracticeQuestionDTO struct {
|
|
ID uint `json:"id"` // 数据库自增ID
|
|
QuestionID string `json:"question_id"` // 题目编号(原JSON中的id)
|
|
Type string `json:"type"` // 前端使用的简化类型: single, multiple, judge, fill
|
|
Content string `json:"content"` // 题目内容
|
|
Options []Option `json:"options"` // 选择题选项数组
|
|
Category string `json:"category"` // 题目分类
|
|
}
|
|
|
|
// PracticeAnswerSubmit 练习题答案提交
|
|
type PracticeAnswerSubmit struct {
|
|
QuestionID uint `json:"question_id" binding:"required"` // 数据库ID
|
|
Answer interface{} `json:"answer" binding:"required"` // 用户答案
|
|
}
|
|
|
|
// PracticeAnswerResult 练习题答案结果
|
|
type PracticeAnswerResult struct {
|
|
Correct bool `json:"correct"` // 是否正确
|
|
UserAnswer interface{} `json:"user_answer"` // 用户答案
|
|
CorrectAnswer interface{} `json:"correct_answer,omitempty"` // 正确答案(仅在错误时返回)
|
|
}
|