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; 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; /** * 当前表单项是否可编辑 */ 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; requiredType?: FormItemRule['type']; validateValue?: string; regexpValidateErrorMessage?: string; validateExistRemote?: (value: unknown, values: IAnyObject, outValues: IAnyObject) => Promise<{ data: boolean; }> | { data: boolean; }; validateExistRemoteErrorMessage?: string; span?: number; labelWidth?: string | number; labelPosition?: 'left' | 'right' | 'top'; hideLabel?: boolean; contentEnd?: boolean; itemMarginBottom?: string; labelStyle?: CSSProperties; inputStyle?: CSSProperties; itemStyle?: CSSProperties; style?: CSSProperties; placeholder?: string; noMatchText?: string; clearable?: boolean; defaultValue?: V; asyncOptions?: (dependOnValue: any, outDependOnValues: any) => Promise; __render?: Slot; _isShow?: boolean; } export type ExtendedConfig = T extends any ? IRenderConfig & ComposeType[T] : never; export interface ITableRenderProps { config: ITableRenderConfig & IRenderConfig; fieldKey: string; index: number; model: IAnyObject; key: string; tableRuleKey: string; propertyKey: string; columnKey: string; tableDependOnValues: IAnyObject; tableData: Array; updateData: (val: IAnyObject, index: number) => void; $index: number; $position: 'table'; } export interface ITableRenderConfig { columnType?: 'checkbox' | 'mainField'; hideItem?: boolean; /** * 超出宽度后是否展示tooltip */ showOverflowTooltip?: boolean; dynamic?: boolean; formatter?: () => string; required?: boolean; trueLabel?: string; falseLabel?: string; __render?: (props: ITableRenderProps) => VNode; fixed?: boolean | 'left' | 'right'; /** * 当前表单项最小宽度 */ minWidth?: string; align?: 'left' | 'center' | 'right'; slots?: { header?: Slot; }; selectable?: (params: { row: IAnyObject; index: number; }) => boolean; } export interface IBaseFormRenderConfig { /** * 当前表单项占用的栅格数 */ span?: number; labelWidth?: string; labelStyle?: IAnyObject; itemStyle?: IAnyObject; } export interface ICustomValidator { (values: unknown, dependOnValues: IAnyObject, outDependOnValues: IAnyObject): Promise<{ data?: boolean; message?: string; }>; message: string; type: string; } export interface IFormRenderConfig { /** * 当前表单项是否必填 */ required?: boolean; customRequiredRule?: (config: IRenderConfig, otherValue: IAnyObject, dependOnValues: IAnyObject, outDependOnValues: IAnyObject) => FormItemRule; requiredErrorMessage?: string; triggerType?: 'input'; requiredType?: 'blur' | 'change'; validateValue?: 'email' | 'identityCard' | 'mobilePhone'; regexpValidate?: string; validateExistRemote?: (value: unknown, dependOnValues: IAnyObject) => Promise<{ data: boolean; }>; validateExistRemoteErrorMessage?: string; requiredRuleConfig?: any; validateValueErrorMessage?: string; customValidators?: Array; no?: string; directory?: boolean; importantDisabled?: boolean; } export interface ISearchRenderConfig { immediateSearch?: boolean; autoSelect?: boolean; } export type TSearchFormConfig = ExtendedConfig & IBaseFormRenderConfig & ISearchRenderConfig; export type TFormConfig = ExtendedConfig & IBaseFormRenderConfig & IFormRenderConfig; export interface IEntityConfig { type?: string; field?: string; _renderConfig?: IRenderConfig; } export interface IFormConfig = Record> { key: keyof T; id?: string; config: IRenderConfig; } export type TTableColumns = ExtendedConfig & ITableRenderConfig; export interface ITableColumnConfig { key: string; config: TTableColumns & { children: Array; }; } export type IFieldConfig = Record> = Partial>; export type IFormFieldConfig = Record> = Partial>; export type ISearchFieldConfig = Record> = Partial>; export type ITableFieldConfig = Record> = Partial>; export declare function generateFieldList = Record>(configMap: IFieldConfig, ...source: Array | IFieldConfig>): IFormConfig[]; export declare function mergeFieldConfig>(targetConfigMap: IFieldConfig, ...sourceConfigMaps: Array | IFieldConfig>): IFieldConfig; /** * config 对象转为数组 (table时用的较多) */ export declare function configMapToList = Record>(configMap: IFieldConfig): (IFormConfig & { sort: number; })[]; /** * 将一个字段配置数据插入到另一个配置数据中 */ export declare function insertFieldConfigToList>(target: IFormConfig[] | undefined, source: IFormConfig[]): IFormConfig[]; export declare function configListToMap>(configList: IFormConfig[]): Partial | IRenderConfig<"default", unknown> | (IRenderConfig<"date", unknown> & { viewType?: "datetime" | undefined; }) | (IRenderConfig<"dateRange", unknown> & { otherKey?: string | undefined; }) | IRenderConfig<"any", unknown>>>; export declare function keysToConfigMap = Record>(keys: Array): Partial | 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): IFormFieldConfig; export declare function defineFormFieldConfig = Record>(config: IFormFieldConfig): IFormFieldConfig; export declare function defineTableFieldConfig = Record>(config: ITableFieldConfig): ITableFieldConfig; export declare function defineSearchFieldConfig = Record>(config: ISearchFieldConfig): ISearchFieldConfig;