fix: 优化
This commit is contained in:
parent
aa61e61e23
commit
7e4a25f64d
@ -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 子结构)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user