fix: 修复作业多选题

This commit is contained in:
阿梦 2026-06-04 15:17:17 +09:00
parent 4bba6bd98f
commit 1124ca4029
2 changed files with 39 additions and 35 deletions

View File

@ -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(/&nbsp;/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(/&nbsp;/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

View File

@ -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)"
> >