fix: 修复搜索和随机模式的两个问题

后端改动:
- 修复搜索功能中的 PostgreSQL 类型问题,将 question_id 转换为文本类型进行搜索

前端改动:
- 优化随机刷题模式,避免在答题后选到相同题目

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yanlongqi 2025-11-10 13:49:24 +08:00
parent f7c662d9ac
commit 41cf72db12
2 changed files with 6 additions and 4 deletions

View File

@ -100,7 +100,8 @@ func GetPracticeQuestions(c *gin.Context) {
// 根据搜索关键词过滤(搜索题目内容或题目编号)
if searchQuery != "" {
query = query.Where("question LIKE ? OR question_id LIKE ?", "%"+searchQuery+"%", "%"+searchQuery+"%")
// 将 question_id 显式转换为文本类型,避免 PostgreSQL 将其作为数字类型处理
query = query.Where("question LIKE ? OR question_id::text LIKE ?", "%"+searchQuery+"%", "%"+searchQuery+"%")
}
// 获取总数

View File

@ -303,15 +303,16 @@ const QuestionPage: React.FC = () => {
// 随机模式:从题库中随机选择一题
if (randomMode) {
// 获取所有未答题目的索引
// 获取所有未答题目的索引(排除当前题目)
const unansweredIndexes: number[] = [];
for (let i = 0; i < allQuestions.length; i++) {
if (!answeredStatus.has(i)) {
// 排除当前题目索引,避免选到同一题
if (i !== currentIndex && !answeredStatus.has(i)) {
unansweredIndexes.push(i);
}
}
// 如果所有题目都已回答,显示总结页面
// 如果没有未答题目,显示总结页面
if (unansweredIndexes.length === 0) {
setShowSummary(true);
// 清除进度