import React from 'react'; import { ComponentsType, DataType, iProperty, TagType } from '../../base/type'; import IOTCordEntryEnum from './IOTCordEntryEnum'; import { IOTCordEntryEnumProps } from './interface'; import iGrapesJSConfig from '../../type'; import { mergeParameters } from '../../base/utils'; import { iOTCardEntryEnumJSON } from '.'; const grapesJSConfig: iGrapesJSConfig = { type: [ComponentsType.EnumType], id: 'IOTCordEntryEnum', tag: TagType.IOTCordEntryEnum, access: 'rw', render: (jsonData, ...args) => { const props = mergeParameters(jsonData, ...args); return ; }, buildData: (mock: boolean = false, property?: iProperty) => { if (property === undefined) return; //区分类 const props: iOTCardEntryEnumJSON = { title: property['display-name'], icon: { value: 'insideicon-cu-1', show: true }, subTitle: { show: true, value: '副标题', }, streamId: property.streamName, type: DataType.EnumType, disabled: false, handler: function (val: any): void { throw new Error('Function not implemented.'); }, items: getEnumItems(property), }; return props; }, traits: () => { return [ { type: 'option-icon', name: 'icon', label: '显示图标', }, { type: 'text', name: 'title', label: '', }, { type: 'option-text', name: 'subTitle', label: '副标题', }, { type: 'solt-text', name: 'items', label: '枚举列表', }, ]; }, }; export const getEnumItems = (propery: iProperty) => { const items = Array<{ text: string; value: string; icon: string }>(); const values = propery?.valuedef?.specs?.values; for (const key in values) { // 对此对象属性中的每个键执行的代码 items.push({ text: values[`${key}`], value: key, icon: 'insideicon-cu-1', }); } return items; }; export default grapesJSConfig;