@hzab/form-render
formily schema 表单渲染组件
组件
Tips
示例
import FormRender from "@hzab/form-render";
<FormRender schema={testSchema} />;
组件远程数据
- 使用 schemaScope 传入全局配置变量,在响应器的动作响应中调用
{
"form": {
"labelCol": 6,
"wrapperCol": 12
},
"schema": {
"type": "object",
"properties": {
"parentId": {
"type": "string",
"title": "上级菜单",
"x-decorator": "FormItem",
"x-component": "TreeSelect",
"x-validator": [],
"x-component-props": {},
"x-decorator-props": {},
"x-reactions": {
"fulfill": {
"run": "fetchMenuTree($self);"
}
},
"name": "parentId",
"x-designable-id": "i012z5nbd5z",
"x-index": 0
}
}
}
}
<FormRender
schema={testSchema}
schemaScope={{
fetchMenuTree(field) {
setTimeout(() => {
field.component[1].treeData = [{ value: 1, label: 1 }];
}, 1000)
},
}}
/>
自定义组件
- 使用 components 传入自定义组件,在 schema 中 x-component 配置对应的组件名称
{
"form": {
"labelCol": 6,
"wrapperCol": 12
},
"schema": {
"type": "object",
"properties": {
"parentId": {
"type": "string",
"title": "图标选择器",
"x-decorator": "FormItem",
"x-component": "IconSelect",
"x-validator": [],
"x-component-props": {},
"x-decorator-props": {},
"x-reactions": {},
"name": "parentId",
"x-designable-id": "i012z5nbd5z",
"x-index": 0
}
}
}
}
<FormRender
schema={testSchema}
components={{
IconSelect() {
return "IconSelect";
},
}}
/>
API
InfoPanel Attributes
参数 | 类型 | 必填 | 默认值 | 说明 |
---|
schema | Object | 是 | - | 数据信息的 schema |
schemaScope | Object | 否 | - | 全局作用域,用于实现协议表达式变量注入 |
layout | Object | 否 | horizontal | 表单布局,horizontal vertical \ inline |
initialValues | Object | 否 | - | form 初始值 |
components | Object | 否 | - | 自定义组件 |
formOptions | Object | 否 | - | createForm 的参数 |
disabled | boolean | 否 | - | 禁用状态 |
readOnly | boolean | 否 | - | 只读状态 |
方法 Methods
Schema
{
"form": {
"labelCol": 6,
"wrapperCol": 12
},
"schema": {
"type": "object",
"properties": {
"parentId": {
"type": "string",
"title": "上级菜单",
"x-decorator": "FormItem",
"x-component": "TreeSelect",
"x-validator": [],
"x-component-props": {
"virtual": true,
"allowClear": true,
"showSearch": true
},
"x-decorator-props": {},
"x-reactions": {
"dependencies": [
{
"property": "value",
"type": "any"
}
],
"fulfill": {
"state": {
"visible": "{{$deps.menuType === \"C\" || $deps.menuType === \"F\"}}"
},
"run": "fetchMenuTree($self);"
}
},
"name": "parentId",
"x-designable-id": "i012z5nbd5z",
"x-index": 0,
"inTable": false
}
}
}
}
组件开发流程
- 在 config/webpack.config/webpack.config.dev.js 中按需修改 alias 配置的包名,便于本地调试
- 在 example/typings.d.ts 中按需修改 declare module 配置的包名,解决 ts 报错问题
- npm run dev
文件目录
- example 本地测试代码
- src 组件源码
- lib 组件打包编译后的代码
命令
- 本地运行:npm run dev
- 测试环境打包编译:npm run build-flow-dev
- 生产环境打包编译:npm run build
发布
- 在 config/webpack.config/webpack.config.prod.js 中按需修改 entry 配置的文件名
- 编译组件:npm run build
- 命令:npm publish --access public
- 发布目录:
配置
配置文件
- 本地配置文件:config/global-config/config.local.js
- 测试环境配置文件:config/global-config/config.flowDev.js
- 生产环境配置文件:config/global-config/config.production.js
webpack 配置文件