From 375946ac93df0dcfe380f56e706a1d40a255dbc0 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 9 Sep 2026 20:40:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E9=A2=98=E6=95=B0=E6=94=AF=E6=8C=810(?= =?UTF-8?q?=E8=AF=A5=E9=A2=98=E5=9E=8B=E4=B8=8D=E6=8A=BD=E5=8F=96)?= =?UTF-8?q?=EF=BC=9Abank=20add/update=20=E5=85=81=E8=AE=B80=E8=90=BD?= =?UTF-8?q?=E5=BA=93(update=E6=94=B9=E7=94=A8*int=E4=BB=85=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=98=BE=E5=BC=8F=E5=AD=97=E6=AE=B5)=E3=80=81start?= =?UTF-8?q?=E8=B7=B3=E8=BF=870=E9=A2=98=E5=9E=8B=E3=80=81=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E7=BC=96=E8=BE=91=E5=9B=9E=E6=98=BE0=E4=B8=8Emin=3D0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/my_work/routers/apiQuiz.go | 69 +++++++++---------- frontend/ops_vue_js/src/i18n/en.json | 2 +- frontend/ops_vue_js/src/i18n/zh-CN.json | 2 +- .../ops_vue_js/src/views/quiz/ManageBanks.vue | 16 ++--- 4 files changed, 43 insertions(+), 46 deletions(-) diff --git a/backend/my_work/routers/apiQuiz.go b/backend/my_work/routers/apiQuiz.go index 4ede6bd..eb5eb3b 100644 --- a/backend/my_work/routers/apiQuiz.go +++ b/backend/my_work/routers/apiQuiz.go @@ -434,21 +434,6 @@ func quizBankNameMap(sessions []TabQuizSession) map[uint]string { ids := []uint{ return m } -// quizDefaultCount 各题型默认抽题数 -func quizDefaultCount(qType string) int { - switch qType { - case QuizTypeSingle: - return 20 - case QuizTypeMultiple: - return 10 - case QuizTypeJudge: - return 20 - case QuizTypeBlank: - return 10 - } - return 10 -} - // ApiQuizInit 初始化答题模块 func ApiQuizInit() { models.DB.AutoMigrate(&TabQuizBank{}) @@ -503,17 +488,17 @@ func ApiQuiz(r *gin.RouterGroup) { ReturnJson(ctx, "jsonErr", nil) return } - if from.CountSingle <= 0 { - from.CountSingle = quizDefaultCount(QuizTypeSingle) + if from.CountSingle < 0 { + from.CountSingle = 0 } - if from.CountMultiple <= 0 { - from.CountMultiple = quizDefaultCount(QuizTypeMultiple) + if from.CountMultiple < 0 { + from.CountMultiple = 0 } - if from.CountJudge <= 0 { - from.CountJudge = quizDefaultCount(QuizTypeJudge) + if from.CountJudge < 0 { + from.CountJudge = 0 } - if from.CountBlank <= 0 { - from.CountBlank = quizDefaultCount(QuizTypeBlank) + if from.CountBlank < 0 { + from.CountBlank = 0 } if from.DurationSec < 0 { from.DurationSec = 0 @@ -550,10 +535,10 @@ func ApiQuiz(r *gin.RouterGroup) { ID uint `json:"id"` Name string `json:"name"` Description string `json:"description"` - CountSingle int `json:"countSingle"` - CountMultiple int `json:"countMultiple"` - CountJudge int `json:"countJudge"` - CountBlank int `json:"countBlank"` + CountSingle *int `json:"countSingle"` + CountMultiple *int `json:"countMultiple"` + CountJudge *int `json:"countJudge"` + CountBlank *int `json:"countBlank"` DurationSec int `json:"durationSec"` Active *bool `json:"active"` } @@ -573,17 +558,29 @@ func ApiQuiz(r *gin.RouterGroup) { if from.Description != "" { bank.Description = from.Description } - if from.CountSingle > 0 { - bank.CountSingle = from.CountSingle + if from.CountSingle != nil { + bank.CountSingle = *from.CountSingle + if bank.CountSingle < 0 { + bank.CountSingle = 0 + } } - if from.CountMultiple > 0 { - bank.CountMultiple = from.CountMultiple + if from.CountMultiple != nil { + bank.CountMultiple = *from.CountMultiple + if bank.CountMultiple < 0 { + bank.CountMultiple = 0 + } } - if from.CountJudge > 0 { - bank.CountJudge = from.CountJudge + if from.CountJudge != nil { + bank.CountJudge = *from.CountJudge + if bank.CountJudge < 0 { + bank.CountJudge = 0 + } } - if from.CountBlank > 0 { - bank.CountBlank = from.CountBlank + if from.CountBlank != nil { + bank.CountBlank = *from.CountBlank + if bank.CountBlank < 0 { + bank.CountBlank = 0 + } } if from.DurationSec >= 0 { bank.DurationSec = from.DurationSec @@ -1096,7 +1093,7 @@ func ApiQuiz(r *gin.RouterGroup) { questions := []TabQuizQuestion{} for _, d := range typeDraws { if d.count <= 0 { - d.count = quizDefaultCount(d.qType) + continue } var pool []TabQuizQuestion models.DB.Where("bank_id = ? AND active = ? AND type = ?", bank.ID, true, d.qType).Find(&pool) diff --git a/frontend/ops_vue_js/src/i18n/en.json b/frontend/ops_vue_js/src/i18n/en.json index 1df05a2..69e3c60 100644 --- a/frontend/ops_vue_js/src/i18n/en.json +++ b/frontend/ops_vue_js/src/i18n/en.json @@ -945,7 +945,7 @@ "delete_title": "Delete Bank", "delete_msg": "Deleting \"{name}\" will also delete all its questions. Continue?", "err_name_required": "Please enter the bank name", - "draw_count_hint": "Random draw count per type; draws all of that type if fewer are available", + "draw_count_hint": "Random draw count per type; 0 = do not draw this type; draws all of that type if fewer are available", "back": "Back to banks", "manage_questions": "Manage Questions", "single_short": "S", diff --git a/frontend/ops_vue_js/src/i18n/zh-CN.json b/frontend/ops_vue_js/src/i18n/zh-CN.json index a6bba6f..e81e3bd 100644 --- a/frontend/ops_vue_js/src/i18n/zh-CN.json +++ b/frontend/ops_vue_js/src/i18n/zh-CN.json @@ -946,7 +946,7 @@ "delete_title": "删除题库", "delete_msg": "删除题库\"{name}\"将同时删除其下所有题目,确认继续?", "err_name_required": "请填写题库名称", - "draw_count_hint": "每种题型随机抽取数量,题目不足则该题型全部抽取", + "draw_count_hint": "每种题型随机抽取数量,填 0 表示该题型不抽取;题目不足则全部抽取", "back": "返回题库列表", "manage_questions": "管理题目", "single_short": "单", diff --git a/frontend/ops_vue_js/src/views/quiz/ManageBanks.vue b/frontend/ops_vue_js/src/views/quiz/ManageBanks.vue index c9bfabe..83ac39a 100644 --- a/frontend/ops_vue_js/src/views/quiz/ManageBanks.vue +++ b/frontend/ops_vue_js/src/views/quiz/ManageBanks.vue @@ -169,10 +169,10 @@ function openEdit(row, event) { editingId.value = row.id form.name = row.name form.description = row.description || '' - form.countSingle = row.countSingle || 20 - form.countMultiple = row.countMultiple || 10 - form.countJudge = row.countJudge || 20 - form.countBlank = row.countBlank || 10 + form.countSingle = row.countSingle ?? 20 + form.countMultiple = row.countMultiple ?? 10 + form.countJudge = row.countJudge ?? 20 + form.countBlank = row.countBlank ?? 10 form.durationMin = Math.round((row.durationSec || 0) / 60) showModal.value = true } @@ -437,7 +437,7 @@ onMounted(fetchBanks) @@ -447,7 +447,7 @@ onMounted(fetchBanks) @@ -457,7 +457,7 @@ onMounted(fetchBanks) @@ -467,7 +467,7 @@ onMounted(fetchBanks)