/** * 把 accordion / fieldset 的 `schema.sections` 声明展开成「块标题 + 字段定义」。 * * 参考主题把「升级价格」这类复合配置拆成若干可折叠块,每块用 keys 声明自己 * 包含哪些字段。这里是纯函数,方便在 Node 契约测试里直接用真实 schema 校验, * 避免渲染层的一个小疏忽让整块手风琴静默退化成平铺。 */ export function buildFieldsetSections(schema) { const declared = schema && Array.isArray(schema.sections) ? schema.sections : [] if (!declared.length) return [] const byKey = {} const nested = Array.isArray(schema.fields) ? schema.fields : [] for (const field of nested) { if (field && field.key) byKey[field.key] = field } return declared.map((section) => ({ title: String((section && section.title) || ''), fields: (Array.isArray(section && section.keys) ? section.keys : []) .map((key) => byKey[key]) .filter(Boolean), })) }