From 7e4a25f64d2af47aeee69b48fb91c416ed2d7764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=A2=A6?= Date: Mon, 16 Feb 2026 19:28:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/doWork/components/Question.vue | 45 ++++++++++++++++++++---- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/pages/doWork/components/Question.vue b/src/pages/doWork/components/Question.vue index 0b56247..b938864 100644 --- a/src/pages/doWork/components/Question.vue +++ b/src/pages/doWork/components/Question.vue @@ -886,6 +886,42 @@ const fillBlankNum = computed(() => { // ========== 阅读理解 / 完形填空检测 ========== // 解析原始 options 数据(保留嵌套结构,不做展平),与 admin 端 normalizedOptions 对齐 +// 将纯值数组转为 { label, value } 格式 +function toSimpleOptions(list: any[]) { + return list.map((value: any, idx: number) => ({ + label: String.fromCharCode(65 + idx), + value: value ?? '', + })); +} + +// 规范化选项数据(与 admin 端 normalizeOptionsFromOptionList 对齐) +function normalizeOptionsFromOptionList(optionList: any[]) { + if (!Array.isArray(optionList) || !optionList.length) return undefined; + + let list = optionList; + // 解包多余嵌套 [[...]] → [...] + while (Array.isArray(list) && list.length === 1 && Array.isArray(list[0])) { + list = list[0]; + } + + // 数组的数组 → 完形填空结构 [{ options: [{label, value}] }] + if ( + list.every((i: any) => Array.isArray(i)) && + list.some((i: any) => Array.isArray(i) && i.length) + ) { + return (list as any[]).map((sub: any[]) => ({ + options: toSimpleOptions(sub), + })); + } + + // 纯字符串数组 → 简单选项 [{label, value}] + if (list.every((i: any) => typeof i === 'string')) { + return toSimpleOptions(list as any[]); + } + + return list; +} + const rawParsedOptions = computed(() => { const data = props.data; let raw = data?.optionsMu != null ? data.optionsMu @@ -893,13 +929,10 @@ const rawParsedOptions = computed(() => { if (typeof raw === 'string') { try { raw = JSON.parse(raw); } catch { raw = null; } } - if (!Array.isArray(raw)) return []; - // 解包多余嵌套 [[...]] → [...] - let list = raw; - while (Array.isArray(list) && list.length === 1 && Array.isArray(list[0])) { - list = list[0]; + if (Array.isArray(raw)) { + return normalizeOptionsFromOptionList(raw) ?? raw; } - return list; + return []; }); // 是否为阅读理解(选项含 stem + options 子结构)