VoidField
调用createVoidField所返回的 VoidField 模型。
以下会列出所有模型属性,如果该属性是可写的,那么我们可以直接引用是修改该属性,@formily/reactive 便会响应从而触发 UI 更新。
属性
| 属性 | 描述 | 类型 | 是否只读 | 默认值 |
|---|---|---|---|---|
| initialized | 字段是否已被初始化 | Boolean | 否 | false |
| mounted | 字段是否已挂载 | Boolean | 否 | false |
| unmounted | 字段是否已卸载 | Boolean | 否 | false |
| address | 字段节点路径 | FormPath | 是 | |
| path | 字段数据路径 | FormPath | 是 | |
| title | 字段标题 | Any(由泛型 TextType 决定) | 否 | "" |
| description | 字段描述 | Any(由泛型 TextType 决定) | 否 | "" |
| data | 字段扩展属性 | Object | 否 | null |
| content | 字段内容 | any | 否 | null |
| decorator | 字段装饰器 | Any[] | 否 | null |
| component | 字段组件 | Any[] | 否 | null |
| parent | 父级字段 | GeneralField | 是 | null |
| display | 字段展示状态 | FieldDisplayTypes | 否 | "visible" |
| pattern | 字段交互模式 | FieldPatternTypes | 否 | "editable" |
| hidden | 字段是否隐藏 | Boolean | 否 | false |
| visible | 字段是否显示 | Boolean | 否 | true |
| disabled | 字段是否禁用 | Boolean | 否 | false |
| readOnly | 字段是否只读 | Boolean | 否 | false |
| readPretty | 字段是否为阅读态 | Boolean | 否 | false |
| editable | 字段是可编辑 | Boolean | 否 | true |
| indexes | 字段数字索引集合 | Number[] | 是 | - |
| index | 字段数字索引 | Number | 是 | - |
详细解释
hidden
为 true 时是 display 为 hidden,为 false 时是 display 为 visible
visible
为 true 时是 display 为 visible,为 false 时是 display 为 none
方法
setTitle
描述
设置字段标题
签名
interface setTitle {
(title?: any): void
}setDescription
描述
设置字段描述信息
签名
interface setDescription {
(title?: any): void
}setDisplay
描述
设置字段展示状态
签名
interface setDisplay {
(display?: FieldDisplayTypes): void
}FieldDisplayTypes 参考 FieldDisplayTypes
setPattern
描述
设置字段交互模式
签名
interface setPattern {
(pattern?: FieldPatternTypes): void
}FieldPatternTypes 参考 FieldPatternTypes
setComponent
描述
设置字段组件
签名
interface setComponent {
(component?: FieldComponent, props?: any): void
}FieldComponent 参考 FieldComponent
setComponentProps
描述
设置字段组件属性
签名
interface setComponentProps {
(props?: any): void
}setDecorator
描述
设置字段装饰器
签名
interface setDecorator {
(decorator?: FieldDecorator, props?: any): void
}FieldDecorator 参考 FieldDecorator
setDecoratorProps
描述
设置字段装饰器属性
签名
interface setDecoratorProps {
(props?: any): void
}setState
描述
设置字段状态
签名
interface setState {
(state: IVoidFieldState): void
(callback: (state: IVoidFieldState) => void): void
}IVoidFieldState 参考 IVoidFieldState
getState
描述
获取字段状态
签名
interface getState<T> {
(): IVoidFieldState
(callback: (state: IVoidFieldState) => T): T
}IVoidFieldState 参考 IVoidFieldState
setData
描述
设置 Data 值
签名
interface setData {
(data: any): void
}setContent
描述
设置 Content 值
签名
interface setContent {
(content: any): void
}onInit
描述
触发字段初始化,默认不需要手动调用
签名
interface onInit {
(): void
}onMount
描述
触发字段挂载
签名
interface onMount {
(): void
}onUnmount
描述
触发字段卸载
签名
interface onUnmount {
(): void
}query
描述
查询字段,可以基于当前字段查询相邻字段
签名
interface query {
(pattern: FormPathPattern): Query
}FormPathPattern API 参考 FormPath
Query 对象 API 参考 Query
dispose
描述
释放 observer,默认不需要手动释放
签名
interface dispose {
(): void
}destroy
描述
释放 observer,并删除字段模型
签名
interface destroy {
(): void
}match
描述
基于路径匹配字段
签名
interface match {
(pattern: FormPathPattern): boolean
}FormPathPattern API 参考 FormPath
inject
描述
给字段模型注入可执行方法
签名
interface inject {
(actions: Record<string, (...args: any[]) => any>): void
}invoke
描述
调用字段模型通过 inject 注入的可执行方法
签名
interface invoke {
(name: string, ...args: any[]): any
}类型
TextType
type TextType = anyVoidField 在核心层并不单独约束标题和描述的消息类型,而是通过泛型 TextType 交给上层适配。
FieldComponent
type FieldComponent = string | JSXComponentConstructor字段组件,如果我们在支持 JSX 的框架中使用,FieldComponent 推荐直接存储 JSX 组件引用,否则可以存储一个组件标识字符串,在实际渲染的时候做一次分发。
FieldDecorator
type FieldDecorator = string | JSXComponentConstructor字段装饰器,如果我们在支持 JSX 的框架中使用,FieldDecorator 推荐直接存储 JSX 组件引用,否则可以存储一个组件标识字符串,在实际渲染的时候做一次分发。
FieldReaction
type FieldReaction = (field: GeneralField) => voidFieldDisplayTypes
type FieldDisplayTypes = 'none' | 'hidden' | 'visible'FieldPatternTypes
type FieldPatternTypes = 'editable' | 'disabled' | 'readOnly' | 'readPretty'GeneralField
type GeneralField = Field | VoidField | ArrayField | ObjectFieldField 参考 Field
ArrayField 参考 ArrayField
ObjectField 参考 ObjectField
IVoidFieldState
interface IVoidFieldState {
selfDisplay?: FieldDisplayTypes
selfPattern?: FieldPatternTypes
content?: any
data?: any
decoratorType?: any
decoratorProps?: Record<string, any>
componentType?: any
componentProps?: Record<string, any>
designable?: boolean
hidden?: boolean
visible?: boolean
editable?: boolean
readOnly?: boolean
disabled?: boolean
readPretty?: boolean
title?: any
description?: any
initialized?: boolean
mounted?: boolean
unmounted?: boolean
decorator?: FieldDecorator
component?: FieldComponent
display?: FieldDisplayTypes
pattern?: FieldPatternTypes
index?: number
indexes?: number[]
}IGeneralFieldState
type IGeneralFieldState = IVoidFieldState & IFieldStateIFieldState 参考 IFieldState