formily 的协议主要是基于标准 JSON Schema 来进行驱动渲染的
同时在标准之上又扩展了一些x-*属性来表达 UI,让整个表单渲染引擎可以具备完整描述一个复杂系统的能力
- @formily/core 就是 ViewModel
- Component 和 Decorator 就是 View
- ViewModel 和 View 的绑定就叫做模型绑定
- @formily/react 就是将 ViewModel 和 View 绑定起来的胶水层
x-component
formily支持的 x- 属性可以在线测试 https://designable-antd.formilyjs.org
JSON Schema外,通过x-的扩展方式,抽象了x-属性以对表单UI进行描述
- x-component 字段编辑组件类型,比如Input、Select等,另外仍然可以是CustomComponent,通过渲染层注入组件即可
- x-component-props 组件的 props,例如 Input,Select
- x-decorator
- x-decorator-props:字段属性描述,通俗可以理解为FormItem属性定义
- x-validator 表单验证
- x-designable-id
- x-index
{
"type": "number",
"title": "NumberPicker",
"x-decorator": "FormItem",
"x-component": "NumberPicker",
"x-validator": [],
"x-component-props": {},
"x-decorator-props": {},
"x-designable-id": "q51a2b2r3dw",
"x-index": 3
}
x-component类型
- Input
- Input.TextArea
- DatePicker
- DatePicker.RangePicker
- TimePicker
- Radio.Group
- Cascader
- Checkbox.Group
- Upload
- Upload.Dragger
- Password
- NumberPicker
- Rate
- Slider
- Select
- TreeSelect
- Transfer
- Switch
搜索表单案例
{
"form": {
"labelCol": 4,
"wrapperCol": 20
},
"schema": {
"type": "object",
"properties": {
"otw6zkqmond": {
"type": "void",
"x-component": "FormGrid",
"x-validator": [],
"x-component-props": {},
"x-designable-id": "otw6zkqmond",
"x-index": 0,
"properties": {
"ubpqsz5z6xq": {
"type": "void",
"x-component": "FormGrid.GridColumn",
"x-designable-id": "ubpqsz5z6xq",
"x-index": 0,
"properties": {
"c1x350m23ai": {
"type": "number",
"title": "重量",
"x-decorator": "FormItem",
"x-component": "NumberPicker",
"x-validator": [],
"x-component-props": {},
"x-decorator-props": {},
"x-designable-id": "c1x350m23ai",
"x-index": 0
}
}
},
"dxamcghnxgg": {
"type": "void",
"x-component": "FormGrid.GridColumn",
"x-designable-id": "dxamcghnxgg",
"x-index": 1,
"properties": {
"cxlgzfanh2z": {
"title": "来源",
"x-decorator": "FormItem",
"x-component": "Select",
"x-validator": [],
"x-component-props": {},
"x-decorator-props": {},
"x-designable-id": "cxlgzfanh2z",
"x-index": 0
}
}
},
"0cu4jvzmtqr": {
"type": "void",
"x-component": "FormGrid.GridColumn",
"x-designable-id": "0cu4jvzmtqr",
"x-index": 2,
"properties": {
"bvpse88vn38": {
"type": "string",
"title": "日期",
"x-decorator": "FormItem",
"x-component": "DatePicker",
"x-validator": [],
"x-component-props": {},
"x-decorator-props": {},
"x-designable-id": "bvpse88vn38",
"x-index": 0
}
}
}
}
},
"6ftvfh7qwos": {
"type": "void",
"x-component": "FormGrid",
"x-validator": [],
"x-component-props": {},
"x-designable-id": "6ftvfh7qwos",
"properties": {
"kih7etsd61b": {
"type": "void",
"x-component": "FormGrid.GridColumn",
"x-designable-id": "kih7etsd61b",
"properties": {
"qvudj88c1ri": {
"type": "string",
"title": "时间",
"x-decorator": "FormItem",
"x-component": "TimePicker",
"x-validator": [],
"x-component-props": {},
"x-decorator-props": {},
"x-designable-id": "qvudj88c1ri",
"x-index": 0
}
},
"x-index": 0
},
"dw0mvx4viuh": {
"type": "void",
"x-component": "FormGrid.GridColumn",
"x-designable-id": "dw0mvx4viuh",
"properties": {
"riyrre6y8nh": {
"type": "string",
"title": "日期",
"x-decorator": "FormItem",
"x-component": "DatePicker",
"x-validator": [],
"x-component-props": {},
"x-decorator-props": {},
"x-designable-id": "riyrre6y8nh",
"x-index": 0
}
},
"x-index": 1
},
"gmxjqf6u60c": {
"type": "void",
"x-component": "FormGrid.GridColumn",
"x-designable-id": "gmxjqf6u60c",
"properties": {
"mwqz9kt98td": {
"type": "string",
"title": "手机",
"x-decorator": "FormItem",
"x-component": "Input",
"x-validator": [],
"x-component-props": {},
"x-decorator-props": {},
"x-designable-id": "mwqz9kt98td",
"x-index": 0
}
},
"x-index": 2
}
},
"x-index": 1
}
},
"x-designable-id": "n0lpepey1ve"
}
}