抽题数支持0(该题型不抽取):bank add/update 允许0落库(update改用*int仅更新显式字段)、start跳过0题型、前端编辑回显0与min=0
This commit is contained in:
4 files changed
+43
-46
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -946,7 +946,7 @@
|
||||
"delete_title": "删除题库",
|
||||
"delete_msg": "删除题库\"{name}\"将同时删除其下所有题目,确认继续?",
|
||||
"err_name_required": "请填写题库名称",
|
||||
"draw_count_hint": "每种题型随机抽取数量,题目不足则该题型全部抽取",
|
||||
"draw_count_hint": "每种题型随机抽取数量,填 0 表示该题型不抽取;题目不足则全部抽取",
|
||||
"back": "返回题库列表",
|
||||
"manage_questions": "管理题目",
|
||||
"single_short": "单",
|
||||
|
||||
@@ -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)
|
||||
<input
|
||||
v-model.number="form.countSingle"
|
||||
type="number"
|
||||
min="1"
|
||||
min="0"
|
||||
max="100"
|
||||
class="w-20 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-sm text-gray-900 outline-none transition-colors focus:border-blue-500 dark:border-dk-muted dark:bg-dk-base dark:text-white"
|
||||
/>
|
||||
@@ -447,7 +447,7 @@ onMounted(fetchBanks)
|
||||
<input
|
||||
v-model.number="form.countMultiple"
|
||||
type="number"
|
||||
min="1"
|
||||
min="0"
|
||||
max="100"
|
||||
class="w-20 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-sm text-gray-900 outline-none transition-colors focus:border-blue-500 dark:border-dk-muted dark:bg-dk-base dark:text-white"
|
||||
/>
|
||||
@@ -457,7 +457,7 @@ onMounted(fetchBanks)
|
||||
<input
|
||||
v-model.number="form.countJudge"
|
||||
type="number"
|
||||
min="1"
|
||||
min="0"
|
||||
max="100"
|
||||
class="w-20 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-sm text-gray-900 outline-none transition-colors focus:border-blue-500 dark:border-dk-muted dark:bg-dk-base dark:text-white"
|
||||
/>
|
||||
@@ -467,7 +467,7 @@ onMounted(fetchBanks)
|
||||
<input
|
||||
v-model.number="form.countBlank"
|
||||
type="number"
|
||||
min="1"
|
||||
min="0"
|
||||
max="100"
|
||||
class="w-20 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-sm text-gray-900 outline-none transition-colors focus:border-blue-500 dark:border-dk-muted dark:bg-dk-base dark:text-white"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user