import type { Slot, CSSProperties, VNode } from 'vue'; import type { IAnyObject } from './util'; import type { FormItemRule } from 'element-plus'; export type NoArrayObject = object; export interface TypeExtensions { default: {}; date: { viewType?: 'datetime'; }; number: {}; dateRange: { otherKey?: string; }; } export interface DRenderTypeExtensions { any: {}; } export type ComposeType = TypeExtensions & DRenderTypeExtensions; export type TChangeConfig = (config: ExtendedConfig, values: IAnyObject, outValues: IAnyObject) => ExtendedConfig; export type TChangeValue = (values: any, outValues: any) => { value: any; otherValue?: IAnyObject; } | void; /** 异步加载选项(dependOn / remote 等场景下的拉取函数) */ export type TAsyncOptions = (dependOnValues?: IAnyObject, outDependOnValues?: IAnyObject, extra?: unknown) => Promise; export type TChangeValueByOld = ({ key, oldValue }: { key: string; oldValue: unknown; }, values: IAnyObject, outValues: IAnyObject) => { value: unknown; otherValue: unknown; } | void; export type TInsert = { before: string; after?: string; } | { before?: string; after: string; }; export interface IRenderConfigDependOnEffect { changeValue?: boolean | TChangeValue; changeConfig?: boolean | TChangeConfig; } export interface IRenderConfigDependOn { key: string; effect?: IRenderConfigDependOnEffect & { resetValue?: boolean; } | boolean; } export interface IRenderConfig { ruleKey?: string; sourceKey?: string; realKey?: string; mergeDependOn?: boolean; /** * 组件类型 */ type?: T; /** * 表单项label文案展示 */ label?: string; /** * 辅助说明 */ description?: string; /** * */ descriptionEffect?: 'light' | 'dark' | (string & {}); /** * 表单项宽度 */ width?: number | string; /** * 当前表单项的依赖项(依赖项为当前表单的其他表单key),配置后,可在依赖项发生改变时,修改当前表单项的值或配置。 * 修改配置 - {@link changeConfig}; * 修改值 - {@link changeValue}; */ dependOn?: Array>; outDependOn?: Array; /** * 当前表单项的另一个key,在部分表单组件会抛出另一个值,抛出的值会被当前配置的otherKey接收 */ otherKey?: string | Array; /** * otherKey 的默认值,当 otherValue 为空时自动设置 * 支持: * - 静态数组:Array * - 函数:() => Array,运行时计算 * 数组元素按顺序对应 otherKey 数组 */ otherDefaultValue?: Array | (() => Array); /** * 当前表单项是否可编辑 */ writable?: boolean; /** * 当前表单项是否可读 */ readable?: boolean; /** * 是否可禁用当前表单项 */ disabled?: boolean; configSort?: number; importDisabled?: boolean; /** * 修改当前表单项的配置,受{@link dependOn} 配置影响,会在dependOn的值发生修改时触发 * @param {IRenderConfig} config - 当前表单项的配置 * @param {IAnyObject} values - dependOn配置的依赖项的值组成的对象 * @param {IAnyObject} outValues * @description 需要返回修改后的config,才能触发修改对当前表单项的配置 * @return config */ changeConfig?: TChangeConfig; changeConfigStr?: string; /** * 修改当前表单项的配置,受{@link dependOn} 配置影响,会在dependOn的值发生修改时触发 * @param {IAnyObject} values - dependOn配置的依赖项的值组成的对象 * @param {IAnyObject} outValues * @description 返回undefined将忽略本次对当前表单项更新值的操作,返回{value: any, otherValue: any}会对当前表单项的值进行修改 * @return undefined | {value: any, otherValue: any} */ changeValue?: TChangeValue; changeValueStr?: string; resetValue?: boolean; immediateChangeValue?: boolean; changeValueByOld?: TChangeValueByOld; changeEffect?: (value: unknown, key: string, model: IAnyObject) => Promise; insert?: TInsert; /** 是否隐藏整个表单项 */ hideItem?: boolean; placeholder?: string; noMatchText?: string; clearable?: boolean; /** * 主字段默认值,支持: * - 静态值:字符串、数字、布尔值等 * - 函数:() => any,运行时计算 * - 模板字符串:'{{now}}' 等模板 */ defaultValue?: V | (() => V) | string; /** 函数:异步拉取选项;字符串:设计器保存的函数体源码,运行时编译 */ asyncOptions?: TAsyncOptions | string; inputStyle?: CSSProperties; style?: CSSProperties; } export type ExtendedConfig = T extends any ? IRenderConfig & ComposeType[T] : never; export interface ITableRenderProps { config: Partial; fieldKey: string; index: number; model: IAnyObject; row?: IAnyObject; key: string; tableRuleKey?: string; propertyKey: string | number; columnKey: string; tableDependOnValues?: IAnyObject; tableData: Array; updateData: (val: IAnyObject, index: number) => void; $index: number; $position: 'table'; } export interface ITableRenderConfig { columnType?: 'checkbox' | 'mainField'; /** * 超出宽度后是否展示tooltip */ showOverflowTooltip?: boolean; dynamic?: boolean; formatter?: () => string; required?: boolean; trueLabel?: string; falseLabel?: string; __render?: (props: ITableRenderProps) => VNode; fixed?: boolean | 'left' | 'right'; /** * 当前列最小宽度 */ minWidth?: number | string; /** * 列内容对齐方式 */ align?: 'left' | 'center' | 'right'; /** * 表头对齐方式 */ headerAlign?: 'left' | 'center' | 'right'; slots?: { header?: Slot; }; selectable?: (params: { row: IAnyObject; index: number; }) => boolean; /** * 列文字层级,用于区分主次信息 * - `primary`:主信息,颜色最深 * - `regular`:常规信息(默认) * - `secondary`:次要信息,颜色最浅 */ textLevel?: 'primary' | 'regular' | 'secondary'; } export interface IBaseFormRenderConfig { /** * 当前表单项占用的栅格数 */ span?: number; labelWidth?: string | number; labelStyle?: CSSProperties; itemStyle?: CSSProperties; labelPosition?: 'left' | 'right' | 'top'; hideLabel?: boolean; contentEnd?: boolean; itemMarginBottom?: string; /** 自定义渲染插槽,form/searchForm 场景使用 */ __render?: Slot; /** 是否在此字段前强制换行 */ br?: boolean; } export interface ICustomValidator { (values: unknown, dependOnValues: IAnyObject, outDependOnValues: IAnyObject): Promise<{ data?: boolean; message?: string; }>; message: string; type: string; } export interface IRuntimeConfig { /** 内部属性: layout 的 item 需要用到 */ _isGrid?: number; /** 内部属性: 控制是否显示 */ _isShow?: boolean; /** 内部属性: 序号,由 genNo 注入 */ no?: string | VNode; } export interface IFormRenderConfig { /** * 当前表单项是否必填 */ required?: boolean; customRequiredRule?: (config: IRenderConfig, otherValue: IAnyObject, dependOnValues: IAnyObject, outDependOnValues: IAnyObject) => FormItemRule; requiredErrorMessage?: string; triggerType?: 'input'; requiredType?: FormItemRule['type']; validateValue?: 'email' | 'identityCard' | 'mobilePhone' | 'sql'; regexpValidate?: string; regexpValidateErrorMessage?: string; validateExistRemote?: (value: unknown, dependOnValues: IAnyObject, outDependOnValues: IAnyObject) => Promise<{ data: boolean; }> | { data: boolean; }; validateExistRemoteErrorMessage?: string; requiredRuleConfig?: any; validateValueErrorMessage?: string; customValidators?: Array; importantDisabled?: boolean; /** 是否为目录(层级) */ directory?: number; /** 特殊的静态组件 */ staticInfo?: string; /** 表单项边框(showOnly + border 将出现边框) */ border?: boolean; } export interface ISearchRenderConfig { immediateSearch?: boolean; autoSelect?: boolean; } export type TSearchFormConfig = ExtendedConfig & IBaseFormRenderConfig & ISearchRenderConfig & IRuntimeConfig; export type TFormConfig = ExtendedConfig & IBaseFormRenderConfig & IFormRenderConfig & IRuntimeConfig; export interface IEntityConfig { type?: string; field?: string; _renderConfig?: IRenderConfig; } /** 通用字段项容器 */ export interface IFieldItem { key: string; id?: string; config: C; /** 是否在此字段前强制换行 */ br?: boolean; } /** * 向后兼容别名 * @deprecated 请优先使用 IFieldItem、IFormFieldItem、ISearchFieldItem 或 ITableColumnItem */ export type IFormConfig<_T extends NoArrayObject<_T> = Record> = IFieldItem; export type TTableColumns = ExtendedConfig & ITableRenderConfig & IRuntimeConfig & { children?: Array<{ key: string; config: TTableColumns; }>; }; export interface ITableColumnConfig { key: string; config: TTableColumns; } /** 便捷别名 */ export type IFormFieldItem = IFieldItem; export type ISearchFieldItem = IFieldItem; export type ITableColumnItem = IFieldItem & { config: TTableColumns & { children: Array; }; }; type TFieldConfigKind = 'field' | 'form' | 'table' | 'search'; declare const FIELD_CONFIG_KIND: unique symbol; type TMarkedFieldConfig = ConfigMap & { readonly [FIELD_CONFIG_KIND]?: Kind; }; type TFieldMapKey = Exclude; export type IFieldConfig = Record> = Partial, ExtendedConfig>>; export type IFormFieldConfig = Record> = Partial, TFormConfig>>; export type ISearchFieldConfig = Record> = Partial, TSearchFormConfig>>; export type ITableFieldConfig = Record> = Partial, TTableColumns>>; /** 合并来源:普通 map、实体 map,或 define*FieldConfig 打标后的 map */ type TFieldConfigMapSource = Record> = IFieldConfig | Record | TMarkedFieldConfig, 'form'> | TMarkedFieldConfig, 'search'> | TMarkedFieldConfig, 'table'>; type TFieldConfigKindOf = ConfigMap extends { readonly [FIELD_CONFIG_KIND]?: infer Kind; } ? Kind extends TFieldConfigKind ? Kind : 'field' : 'field'; type TFieldListItem = IFieldItem & { sort: number; }; type TGenerateFieldListResult = TFieldConfigKindOf extends 'table' ? Array> : TFieldConfigKindOf extends 'search' ? Array> : TFieldConfigKindOf extends 'form' ? Array> : Array>; export declare function generateFieldList = Record, ConfigMap extends TFieldConfigMapSource = TFieldConfigMapSource>(configMap: ConfigMap, ...source: Array>>): TGenerateFieldListResult; export declare function mergeFieldConfig, ConfigMap extends TFieldConfigMapSource = TFieldConfigMapSource>(targetConfigMap: ConfigMap, ...sourceConfigMaps: Array>>): ConfigMap; /** * config 对象转为数组 (table时用的较多) */ export declare function configMapToList = Record, ConfigMap extends TFieldConfigMapSource = TFieldConfigMapSource>(configMap: ConfigMap): TGenerateFieldListResult; /** * 将一个字段配置数据插入到另一个配置数据中 */ export declare function insertFieldConfigToList(target: IFieldItem[] | undefined, source: Array>): IFieldItem[]; export declare function configListToMap, C extends ExtendedConfig = ExtendedConfig>(configList: Array>): Partial>; export declare function keysToConfigMap = Record>(keys: Array): Partial, IRenderConfig<"number", unknown> | IRenderConfig<"default", unknown> | (IRenderConfig<"date", unknown> & { viewType?: "datetime" | undefined; }) | (IRenderConfig<"dateRange", unknown> & { otherKey?: string | undefined; }) | IRenderConfig<"any", unknown>>>; export declare function defineFieldConfig = Record>(config: IFormFieldConfig): TMarkedFieldConfig, 'form'>; export declare function defineFormFieldConfig = Record>(config: IFormFieldConfig): TMarkedFieldConfig, 'form'>; export declare function defineTableFieldConfig = Record>(config: ITableFieldConfig): TMarkedFieldConfig, 'table'>; export declare function defineSearchFieldConfig = Record>(config: ISearchFieldConfig): TMarkedFieldConfig, 'search'>; export {};