fix: 优化

This commit is contained in:
李梦 2026-02-16 19:28:59 +08:00
parent aa61e61e23
commit 7e4a25f64d

View File

@ -886,6 +886,42 @@ const fillBlankNum = computed(() => {
// ========== / ========== // ========== / ==========
// options admin normalizedOptions // 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 rawParsedOptions = computed(() => {
const data = props.data; const data = props.data;
let raw = data?.optionsMu != null ? data.optionsMu let raw = data?.optionsMu != null ? data.optionsMu
@ -893,13 +929,10 @@ const rawParsedOptions = computed(() => {
if (typeof raw === 'string') { if (typeof raw === 'string') {
try { raw = JSON.parse(raw); } catch { raw = null; } try { raw = JSON.parse(raw); } catch { raw = null; }
} }
if (!Array.isArray(raw)) return []; if (Array.isArray(raw)) {
// [[...]] [...] return normalizeOptionsFromOptionList(raw) ?? raw;
let list = raw;
while (Array.isArray(list) && list.length === 1 && Array.isArray(list[0])) {
list = list[0];
} }
return list; return [];
}); });
// stem + options // stem + options