Documentation
¶
Index ¶
- func Clear()
- func FilterFields(extra any, fields []string) any
- func List() []string
- func ParseConfig(config map[string]any, target any) error
- func ParseExtendJSON(extend string) map[string]any
- func Register(component Component) error
- func ShouldPopulateDisplay(config map[string]any) bool
- type Component
- type ComponentRegistry
- type Display
- type DisplayConfig
- type Option
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterFields ¶
FilterFields 根据 display.fields 过滤字段
func ParseExtendJSON ¶
ParseExtendJSON 解析扩展字段(JSON 字符串)
func ShouldPopulateDisplay ¶
ShouldPopulateDisplay 判断是否应该填充显示信息
Types ¶
type Component ¶
type Component interface {
// Name 返回组件的唯一标识符
Name() string
// Validate 验证字段值是否符合组件规则
Validate(ctx context.Context, config map[string]any, value any) error
// GetOptions 获取字段的可选值列表(用于下拉框、单选框等)
GetOptions(ctx context.Context, config map[string]any) ([]Option, error)
// PopulateDisplay 批量填充字段的显示信息(用于列表展示)
PopulateDisplay(ctx context.Context, config map[string]any, values []any) (map[any]Display, error)
}
Component 是所有组件必须实现的接口
type ComponentRegistry ¶
type ComponentRegistry struct {
// contains filtered or unexported fields
}
ComponentRegistry 组件注册中心
type Display ¶
type Display struct {
Label string `json:"label"` // 显示文本
Value any `json:"value"` // 原始值
Extra any `json:"extra,omitempty"` // 扩展信息
}
Display 表示组件的显示信息
type DisplayConfig ¶
type DisplayConfig struct {
Mode string `json:"mode"` // auto | always | never | on-demand
Fields []string `json:"fields,omitempty"` // 需要填充的字段
Cache bool `json:"cache,omitempty"` // 是否缓存
}
DisplayConfig Display 配置
func ExtractDisplayConfig ¶
func ExtractDisplayConfig(config map[string]any) *DisplayConfig
ExtractDisplayConfig 提取 Display 配置
type Option ¶
type Option struct {
Label string `json:"label"` // 显示文本
Value any `json:"value"` // 实际值
Extra any `json:"extra,omitempty"` // 额外信息(如颜色、图标)
}
Option 表示组件的可选项
type ValidationError ¶
ValidationError 组件验证错误
func NewValidationError ¶
func NewValidationError(component, field, message string, err error) *ValidationError
NewValidationError 创建验证错误
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error
Click to show internal directories.
Click to hide internal directories.