fix: 修复作业多选题
This commit is contained in:
parent
4bba6bd98f
commit
1124ca4029
@ -56,37 +56,7 @@ const isCompositeStem = computed(() => {
|
|||||||
return props.data.stem.includes('qml-sq') && props.data.stem.includes('qml-op')
|
return props.data.stem.includes('qml-sq') && props.data.stem.includes('qml-op')
|
||||||
})
|
})
|
||||||
|
|
||||||
function getAnswerCountFromAnswerHtml(answerHtml: unknown) {
|
// 从 answerHtml 中提取选择题答案字母 (如 "A"、"BCD" 或 "A,B,C")
|
||||||
if (!answerHtml) return 0
|
|
||||||
if (Array.isArray(answerHtml)) return answerHtml.filter(Boolean).length
|
|
||||||
|
|
||||||
if (typeof answerHtml === 'string') {
|
|
||||||
const raw = answerHtml.trim()
|
|
||||||
if (!raw) return 0
|
|
||||||
|
|
||||||
try {
|
|
||||||
const parsed = JSON.parse(raw)
|
|
||||||
if (Array.isArray(parsed)) return parsed.filter(Boolean).length
|
|
||||||
} catch {
|
|
||||||
/* ignore */
|
|
||||||
}
|
|
||||||
|
|
||||||
const plainText = raw
|
|
||||||
.replace(/<[^>]*>/g, '')
|
|
||||||
.replace(/ /gi, ' ')
|
|
||||||
.trim()
|
|
||||||
if (!plainText) return 0
|
|
||||||
return plainText.split(/[,,\s]+/).filter(Boolean).length
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
const isSingleChoiceByAnswerHtml = computed(() => {
|
|
||||||
return props.data?.stemType === 2 && getAnswerCountFromAnswerHtml(props.data?.answerHtml) === 1
|
|
||||||
})
|
|
||||||
|
|
||||||
// 从 answerHtml 中提取选择题答案字母 (如 "A" 或 "A,B,C")
|
|
||||||
function extractChoiceLettersFromAnswerHtml(answerHtml: unknown): string {
|
function extractChoiceLettersFromAnswerHtml(answerHtml: unknown): string {
|
||||||
if (!answerHtml) return ''
|
if (!answerHtml) return ''
|
||||||
if (Array.isArray(answerHtml)) {
|
if (Array.isArray(answerHtml)) {
|
||||||
@ -125,6 +95,40 @@ function extractChoiceLettersFromAnswerHtml(answerHtml: unknown): string {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 以 answerHtml 为准:如 "BCD" 为 3 个答案,"A" 或 "A,B" 按逗号/字母解析
|
||||||
|
function getAnswerCountFromAnswerHtml(answerHtml: unknown) {
|
||||||
|
const normalized = extractChoiceLettersFromAnswerHtml(answerHtml)
|
||||||
|
if (normalized) return normalized.split(',').filter(Boolean).length
|
||||||
|
|
||||||
|
if (!answerHtml) return 0
|
||||||
|
if (Array.isArray(answerHtml)) return answerHtml.filter(Boolean).length
|
||||||
|
|
||||||
|
if (typeof answerHtml === 'string') {
|
||||||
|
const raw = answerHtml.trim()
|
||||||
|
if (!raw) return 0
|
||||||
|
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(raw)
|
||||||
|
if (Array.isArray(parsed)) return parsed.filter(Boolean).length
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
|
||||||
|
const plainText = raw
|
||||||
|
.replace(/<[^>]*>/g, '')
|
||||||
|
.replace(/ /gi, ' ')
|
||||||
|
.trim()
|
||||||
|
if (!plainText) return 0
|
||||||
|
return plainText.split(/[,,\s]+/).filter(Boolean).length
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSingleChoiceByAnswerHtml = computed(() => {
|
||||||
|
return props.data?.stemType === 2 && getAnswerCountFromAnswerHtml(props.data?.answerHtml) === 1
|
||||||
|
})
|
||||||
|
|
||||||
// 选择题(单选/多选)的正确答案,优先使用 answerHtml
|
// 选择题(单选/多选)的正确答案,优先使用 answerHtml
|
||||||
const choiceAnswer = computed(() => {
|
const choiceAnswer = computed(() => {
|
||||||
const stemType = props.data?.stemType
|
const stemType = props.data?.stemType
|
||||||
|
|||||||
@ -65,12 +65,12 @@ const content = computed(() => {
|
|||||||
'multiple-choice-item': true,
|
'multiple-choice-item': true,
|
||||||
pointer: true,
|
pointer: true,
|
||||||
active: selectChoice.includes(choiceEnum[idx]),
|
active: selectChoice.includes(choiceEnum[idx]),
|
||||||
success:
|
success: isDeadline && reportFlag && answerArray?.includes(choiceEnum[idx]),
|
||||||
|
fail:
|
||||||
isDeadline &&
|
isDeadline &&
|
||||||
reportFlag &&
|
reportFlag &&
|
||||||
answerArray?.includes(choiceEnum[idx]) &&
|
stuAnswerArray?.includes(choiceEnum[idx]) &&
|
||||||
stuAnswerArray?.includes(choiceEnum[idx]),
|
!answerArray?.includes(choiceEnum[idx]),
|
||||||
fail: isDeadline && reportFlag && stuAnswerArray?.includes(choiceEnum[idx]),
|
|
||||||
}"
|
}"
|
||||||
@click="handleSelect(idx)"
|
@click="handleSelect(idx)"
|
||||||
>
|
>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user