import { uuid } from '../_utils/utils'; import snippets from './snippets'; export default { snippets, componentName: 'Steps', title: 'step bar', category: 'Navigation', props: [ { name: 'steps', title: 'step configuration', setter: { componentName: 'ArraySetter', props: { itemSetter: { componentName: 'ObjectSetter', props: { config: { items: [ { name: 'key', title: 'key', setter: 'StringSetter', initialValue: (val) => val || uuid(), }, { name: 'title', title: 'title', setter: 'StringSetter', }, { name: 'subTitle', title: 'subtitle', setter: 'StringSetter', }, { name: 'description', title: 'description', setter: 'StringSetter', }, { name: 'disabled', title: 'disabled', setter: 'BoolSetter', initialValue: false, }, { name: 'status', title: { label: 'state', tip: 'select box size' }, setter: { componentName: 'RadioGroupSetter', props: { options: [ { title: 'wait', value: 'wait', }, { title: 'process', value: 'process', }, { title: 'finish', value: 'finish', }, { title: 'error', value: 'error', }, ], }, }, propType: { type: 'oneOf', value: ['wait', 'process', 'finish', 'error'], }, defaultValue: 'wait', }, ], }, }, initialValue: () => { return { key: `Steps${uuid()}`, title: '步骤', disabled: false, }; }, }, }, }, extraProps: { getValue(target, fieldValue) { const map = target.node.children.map((child) => { const key = child.getPropValue('key') ? String(child.getPropValue('key')) : child.id; return { key, title: child.getPropValue('title'), subTitle: child.getPropValue('subTitle'), description: child.getPropValue('description'), disabled: child.getPropValue('disabled'), status: child.getPropValue('status'), }; }); 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 key = String(child.getPropValue('key')); if (Object.hasOwnProperty.call(map, key)) { child.setPropValue('title', map[key].title); child.setPropValue('subTitle', map[key].subTitle); child.setPropValue('description', map[key].description); child.setPropValue('disabled', map[key].disabled); child.setPropValue('status', map[key].status); delete map[key]; return false; } return true; }, () => { const items = []; for (const key in map) { if (Object.hasOwnProperty.call(map, key)) { items.push({ componentName: 'Steps.Step', props: map[key], }); } } 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; }, ); }, }, }, { name: 'className', title: { label: 'classname', tip: 'step bar class name' }, propType: 'string', }, { name: 'type', title: { label: 'type', tip: 'Step bar types, including `default` and `navigation`', }, propType: { type: 'oneOf', value: ['default', 'navigation'] }, defaultValue: 'default', }, { name: 'current', title: { label: 'current step', tip: 'Specify the current step, counting from 0. In child Step elements, status can be overridden via the `status` attribute', }, propType: 'number', }, { name: 'direction', title: { label: 'bar direction', tip: 'Specifies the step bar direction. Currently supports horizontal (`horizontal`) and vertical (`vertical`) directions.', }, propType: { type: 'oneOf', value: ['horizontal', 'vertical'], }, }, { name: 'labelPlacement', title: { label: 'label placement', tip: 'Specify the label placement position. By default, it is placed horizontally to the right of the icon. `vertical` is optional and placed below the icon.', }, propType: { type: 'oneOf', value: ['horizontal', 'vertical'], }, defaultValue: 'horizontal', }, { name: 'progressDot', title: { label: 'progess dot', tip: 'Dotted step bar, can be set to a func', }, propType: { type: 'oneOfType', value: ['bool', 'func'] }, }, { name: 'size', title: { label: 'size', tip: 'specify size', }, propType: { type: 'oneOf', value: ['default', 'small'], }, defaultValue: 'default', }, { name: 'status', title: { label: 'current step status', tip: 'Specify the status of the current step, optional `wait` `process` `finish` `error`', }, propType: { type: 'oneOf', value: ['wait', 'process', 'finish', 'error'], }, defaultValue: 'process', }, { name: 'initial', title: { label: 'Starting sequence number', tip: 'Starting sequence number, counting from 0', }, propType: 'number', defaultValue: 0, }, { name: 'onChange', title: { label: 'on change', tip: 'Triggered when a switch step is clicked' }, propType: 'func', }, ], configure: { component: { isContainer: true, nestingRule: { childWhitelist: ['Steps.Step'] }, }, supports: { style: true, events: [ { name: 'onChange', template: "onChange(current,${extParams}){\n// 点击切换步骤时触发\nconsole.log('onChange',current);}", }, ], }, }, };