2021-01-17 21:57:34 +08:00

1.5 KiB
Raw Blame History

DSL设计

DSL层主要约定了Dooring组件的数据协议包括组件的可编辑属性、编辑类型、初始值等之所以定义一致的协议层主要是方便后期的组件扩展配置后移有助于不同后端语言开发和数据存储接下来我们看看header组件的schema。

1.editData 可编辑的属性类型DSL

2.config 可编辑组件的默认属性

const Header: IHeaderSchema = {
  editData: [
    {
      key: 'bgColor',
      name: '背景色',
      type: 'Color',
    },
    {
      key: 'height',
      name: '高度',
      type: 'Number',
    },
    {
      key: 'logo',
      name: 'logo',
      type: 'Upload',
      isCrop: true,
      cropRate: 1000 / 618,
    },
    {
      key: 'logoText',
      name: 'logo文字',
      type: 'Text',
    },
    {
      key: 'color',
      name: '文字颜色',
      type: 'Color',
    },
    {
      key: 'fontSize',
      name: '文字大小',
      type: 'Number',
    }
  ],
  config: {
    bgColor: 'rgba(245,245,245,1)',
    logo: [
      {
        uid: '001',
        name: 'image.png',
        status: 'done',
        url: `${serverUrl}/uploads/3_1740be8a482.png`,
      },
    ],
    logoText: '页头Header',
    fontSize: 20,
    color: 'rgba(47,84,235,1)',
    height: 50
  },
};

由以上代码可知我们可以在editData属性中给组件添加可编辑的属性比如背景图然后再component中接受属性从而设置样式。

在config属性中我们可以设置组件默认属性值和editData中每一项的key一一对应。