API 文档
AnyCore提供了丰富的API,用于快速构建基于装饰器的应用程序。本章节将详细介绍各个模块的API接口。
模块概览
AnyCore主要包含以下模块:
装饰器模块
装饰器模块提供了一系列装饰器,用于标记和配置类和字段。
CustomClass
用于配置类的自定义信息。
签名:
typescript
function CustomClass(config?: { name?: string }): ClassDecorator
参数:
config
:类配置对象,包含:name
:类的自定义名称
相关函数:
typescript
function getCustomClassConfig(target: any): { name?: string }
CustomField
用于配置字段的自定义名称和字典数组。
签名:
typescript
function CustomField(name: string, dictionaryArray?: AnyDictionaryArrayModel<AnyDictionaryModel> | (() => Promise<IDictionary[]>)): PropertyDecorator
参数:
name
:字段的自定义名称dictionaryArray
:字典数组或获取字典数组的函数
相关函数:
typescript
function getCustomFieldName(target: any, field: string): string
function getCustomFieldDictionaryArray(target: any, field: string): AnyDictionaryArrayModel<AnyDictionaryModel>
FormField
用于配置字段的表单相关属性。
签名:
typescript
function FormField(config?: IFormFieldConfig): PropertyDecorator
参数:
config
:表单字段配置对象,具体配置项请参考IFormFieldConfig
相关函数:
typescript
function getFormFieldList(target: any): string[]
function getFormFieldConfigObj(target: any, fieldList?: string[]): Record<string, IFormFieldConfig>
TableField
用于配置字段的表格相关属性。
签名:
typescript
function TableField(config?: ITableFieldConfig): PropertyDecorator
参数:
config
:表格字段配置对象,具体配置项请参考ITableFieldConfig
相关函数:
typescript
function getTableFieldList(target: any): string[]
function getTableFieldConfigObj(target: any, fieldList?: string[]): Record<string, ITableFieldConfig>
SearchField
用于配置字段的搜索相关属性。
辅助函数模块
辅助函数模块提供了各种工具函数,用于数据处理和转换。
AnyDecoratorHelper
装饰器助手类,用于处理类装饰器、属性装饰器等。
主要方法:
setClassConfig(target: any, classConfigKey: string, classConfig: any)
:设置类配置项getClassConfig(target: any, classConfigKey: string, defaultValue?: any, isObject?: boolean)
:获取类配置项setFieldConfig(target: any, keyOrContext: string | ClassFieldDecoratorContext, fieldConfigKey: string, fieldConfig: any)
:设置字段配置getFieldList(target: any, fieldConfigKey: string)
:获取配置了指定装饰器的字段列表getFieldConfigObject<T>(target: any, fieldConfigKey: string, fieldList?: string[])
:获取字段配置对象
AnyDataTransformHelper
数据转换助手类,用于数据格式转换。
AnyDateTimeHelper
日期时间助手类,用于日期时间的格式化和处理。
AnyDictionaryHelper
字典助手类,用于字典数据的处理。
AnyFileHelper
文件助手类,用于文件相关操作。
AnyValidatorHelper
验证助手类,用于数据验证。
模型模块
模型模块提供了基础模型类,包含通用操作方法。
AnyBaseModel
基础模型类,所有实体类的基类。
主要方法:
getFormFieldLabel(field: string)
:获取表单字段的标签getTableFieldLabel(field: string)
:获取表格字段的标签getFormFieldConfigObj()
:获取表单字段配置对象getTableFieldConfigObj()
:获取表格字段配置对象
接口和枚举
主要接口
IFormFieldConfig
表单字段配置接口。
属性:
formType
:表单控件类型label
:字段标签placeholder
:占位符rules
:验证规则disabled
:是否禁用required
:是否必填options
:选项数据
ITableFieldConfig
表格字段配置接口。
属性:
label
:字段标签width
:列宽ellipsis
:是否省略显示sorter
:是否可排序fixed
:固定方式align
:对齐方式customRender
:自定义渲染函数dateFormat
:日期格式isAlways
:是否常驻在表格中
主要枚举
EFormItemType
表单控件类型枚举。
值:
INPUT
:输入框SELECT
:选择器DATE_PICKER
:日期选择器CHECKBOX
:复选框RADIO
:单选框SWITCH
:开关TEXTAREA
:文本域
EDateFormatType
日期格式枚举。
类型定义
AnyCore提供了丰富的类型定义,用于TypeScript项目的类型检查。详细信息请参考源码中的types目录。