VoidField
调用createVoidField所返回的 VoidField 模型。
以下会列出主要的公开模型属性。可写属性可以直接赋值,@silver-formily/reactive 会响应并触发 UI 更新。
属性
| 属性 | 描述 | 类型 | 是否只读 | 默认值 |
|---|---|---|---|---|
| initialized | 字段是否已被初始化 | Boolean | 否 | true |
| mounted | 字段是否已挂载 | Boolean | 否 | false |
| unmounted | 字段是否已卸载 | Boolean | 否 | false |
| address | 字段节点路径 | FormPath | 是 | |
| path | 字段数据路径 | FormPath | 是 | |
| title | 字段标题 | Any(由泛型 TextType 决定) | 否 | undefined |
| description | 字段描述 | Any(由泛型 TextType 决定) | 否 | undefined |
| data | 字段扩展属性 | Object | 否 | undefined |
| content | 字段内容 | any | 否 | undefined |
| decoratorContent 1.1.0 | 字段装饰器插槽内容 | any | 否 | undefined |
| decorator | 字段装饰器 | Any[] | 否 | [undefined, {}] |
| component | 字段组件 | Any[] | 否 | [undefined, {}] |
| parent | 父级字段 | GeneralField | 是 | undefined |
| 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 | 是 | - |
详细解释
initialized
VoidField 构造过程中会先将该状态设为 false。完成字段定位、状态初始化和响应式绑定后,构造函数会立即调用 onInit(),将其设为 true 并触发 onFieldInit 生命周期。因此,通过 form.createVoidField() 取得实例时,该值已经是 true。
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
}setDecoratorContent 1.1.0
描述
设置装饰器内容。Vue 绑定会将其作为装饰器插槽内容响应式渲染。
签名
interface setDecoratorContent {
(content: any): void
}onInit
描述
触发字段初始化,默认不需要手动调用
签名
interface onInit {
(): void
}onMount
描述
触发字段挂载
签名
interface onMount {
(): void
}onUnmount
描述
触发字段卸载
签名
interface onUnmount {
(): void
}query
描述
查询字段,可以基于当前字段查询相邻字段
签名
interface query {
(pattern: FormPathPattern | RegExp): Query
}FormPathPattern API 参考 FormPath
Query 对象 API 参考 Query
dispose
描述
释放 observer,默认不需要手动释放
签名
interface dispose {
(): void
}destroy
描述
释放 observer,并删除字段模型
签名
interface destroy {
(forceClear?: boolean): 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<Component extends JSXComponent, ComponentProps = any>
= | [Component]
| [Component, ComponentProps]
| boolean
| any[]字段组件是运行时配置槽位,通常以 [组件, 属性] 元组传入,也允许由上层适配器解释布尔值或其他数组形态。
FieldDecorator
type FieldDecorator<Decorator extends JSXComponent, DecoratorProps = any>
= | [Decorator]
| [Decorator, DecoratorProps]
| boolean
| any[]字段装饰器与 FieldComponent 使用相同的运行时存储形式。
FieldReaction
type FieldReaction = (field: GeneralField) => voidFieldDisplayTypes
type FieldDisplayTypes = 'none' | 'hidden' | 'visible' | ({} & string)FieldPatternTypes
type FieldPatternTypes
= | 'editable'
| 'readOnly'
| 'disabled'
| 'readPretty'
| ({} & string)GeneralField
type GeneralField = Field | VoidField | ArrayField | ObjectFieldField 参考 Field
ArrayField 参考 ArrayField
ObjectField 参考 ObjectField
IVoidFieldState
interface IVoidFieldState {
selfDisplay?: FieldDisplayTypes
selfPattern?: FieldPatternTypes
content?: any
decoratorContent?: 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