export default [ { name: 'dataList', title: '折叠面板项', setter: { componentName: 'ArraySetter', props: { itemSetter: { componentName: 'ObjectSetter', props: { config: { items: [ { name: 'title', title: '标题', defaultValue: '标题名', setter: 'StringSetter', }, { name: 'icon', title: '图标', defaultValue: '', setter: 'StringSetter', }, { name: 'key', title: '项目编号', condition: () => false, setter: 'StringSetter', }, { name: 'isContent', title: '是否有内容', setter: 'BoolSetter', initValue: true, }, ], }, }, initialValue: () => { return { key: String(Math.floor(Math.random() * 10000)), title: '标题名', icon: '', isContent: true, } }, }, }, }, extraProps: { getValue(target) { const map = target.node.children.map((child) => { const primaryKey = child.getPropValue('key') ? String(child.getPropValue('key')) : child.id return { key: primaryKey, title: child.getPropValue('title') || '标题名', icon: child.getPropValue('icon') || '', isContent: child.getPropValue('isContent'), } }) return map }, setValue(target, value) { const { node } = target const map = {} if (!Array.isArray(value)) { value = [] } value.forEach((item) => { const tabitem = Object.assign({}, item) map[item.key] = tabitem }) node.children.mergeChildren( (child) => { const primaryKey = String(child.getPropValue('key')) if (Object.hasOwnProperty.call(map, primaryKey)) { child.setPropValue('title', map[primaryKey].title) child.setPropValue('icon', map[primaryKey].icon) child.setPropValue('isContent', map[primaryKey].isContent) delete map[primaryKey] return false } return true }, () => { const items: any = [] for (const primaryKey in map) { if (Object.hasOwnProperty.call(map, primaryKey)) { items.push({ componentName: 'CollapseSelectorItem', props: map[primaryKey], }) } } return items }, (child1, child2) => { const a = value.findIndex( (item) => String(item.key) === String(child1.getPropValue('key')), ) const b = value.findIndex( (item) => String(item.key) === String(child2.getPropValue('key')), ) return a - b }, ) }, }, }, ]