import React, { ReactNode } from 'react'; import { RadioProps, CheckboxProps } from 'antd'; import { Service, Options } from 'ahooks/lib/useRequest/src/types'; import type { ProFormOtherType } from '../ProForm/propsType'; import type { PropSelectType } from '../ProSelect/propsType'; /** * @description 数据选项类型 */ export interface DataOptionType { /** * @description 展示标签 * @default - */ label?: string; /** * @description 选项值 * @default - */ value?: string; /** * @description 是否禁用 * @default false */ disabled?: boolean; /** * @description 允许扩展字段 */ [key: string]: any; } /** * @description 频繁变动的枚举配置 */ export interface FrequentEnumConfig { /** * @description 需要替换的缓存枚举code列表 */ enums: string[]; /** * @description 请求服务函数 */ service: Service; /** * @description 请求选项配置 */ options?: Options; /** * @description 对频繁枚举返回数据进行格式化(独立于全局transformResponse) * @param data 后台返回的数据 * @returns 格式化后的枚举数据 * @default - */ transformResponse?: (data: any) => Record | Promise>; } /** * @description ProEnum配置类型 */ export interface ProEnumConfigType { /** * @description 是否枚举主入口 * @default false */ main?: boolean; /** * @description 是否使用主入口枚举 * @default false */ share?: boolean; /** * @description 是否开启调试 log * @default false */ debugger?: boolean; /** * @description 是否对数据进行清洗 * @default false */ clear?: boolean; /** * @description 字段别名 * @default { label: 'label', value: 'value', children: 'children' } */ fieldNames?: { label?: string; value?: string; children?: string; [key: string]: string | undefined; }; /** * @description 缓存的key、默认 zat-design-pro-component-cacheKey * @default "zat-design-pro-component-cacheKey" */ cacheKey: string; /** * @description 刷新请求、设置后每次进入都会重新请求 * @default false */ requestRefresh: boolean; /** * @description 存储位置、不设置、默认读取 globalConfig 里面的 * @default "localStorage" */ storage: 'localStorage' | 'sessionStorage' | 'indexedDB'; /** * @description 默认静态枚举数据 * @default {} */ dataSource: Record; /** * @description 对后台返回数据进行格式化 * @param data 后台返回的数据 * @returns 格式化后的枚举数据 * @default - */ transformResponse?: (data: { data: Record; }) => Record | Promise>; /** * @description 批量请求枚举接口 * @default - */ useRequest?: { /** * @description 请求服务函数 */ service: Service; /** * @description 请求选项配置 */ options?: Options & { /** * @description 指定请求的枚举码 */ codes?: string[]; /** * @description 忽略的枚举码 */ ignoreCodes?: string[]; }; }; /** * @description 频繁变动的枚举配置 * @default - */ frequentEnums?: FrequentEnumConfig; /** * @description 字典数据 * @default {} */ dics: Record; } /** * @description 枚举组件类型枚举 */ type EnumComponentType = 'ProSelect' | 'Radio' | 'Checkbox' | 'Tag' | 'Group'; /** * @description ProEnum基础属性类型 */ export interface ProEnumBaseType { /** * @description 组件展示类型、默认 ProSelect * @default "ProSelect" */ type?: EnumComponentType; /** * @description 用于自定义组件 * @default - */ component?: ReactNode; /** * @description 用于提交 code * @default - */ code?: string | string[]; /** * @description 字段别名 * @default - */ fieldNames?: Record; /** * @description 是否查看模式 * @default false */ isView?: boolean; /** * @description 数据源 * @default - */ dataSource?: DataOptionType[]; /** * @description 当前值 * @default - */ value: any; /** * @description 值变化回调 * @default - */ onChange?: (value: any) => void; /** * @description 远程请求接口 * @default - */ useRequest?: { /** * @description 请求服务函数 */ service: Service; /** * @description 请求选项 */ options?: Options; }; /** * @description 对后台返回数据进行格式化 * @param data 后台返回的数据 * @returns 格式化后的选项数据 * @default - */ transformResponse?: (data: any) => DataOptionType[]; /** * @description 是否合并数据 * @default false */ merge?: boolean; /** * @description 查看模式下为空展示 * @default "-" */ viewEmpty?: React.ReactNode; /** * @description 自定义选项渲染 * @default - */ optionRender?: any; /** * @description 显示 code-value 形式 * @default false */ showCodeName?: boolean; /** * @description 支持 {label:xx, value: xx} 形式 * @default false */ labelInValue?: boolean; /** * @description 其他表单属性 * @default - */ otherProps?: ProFormOtherType; /** * @description 是否允许清除 * @default false */ allowClear?: boolean; /** * @description 组件ID * @default - */ id?: string; /** * @description 默认值 * @default - */ defaultValue?: any; } /** * @description ProSelect类型映射 */ export type PropProSelectsMapType = { /** * @description 类型为ProSelect * @default "ProSelect" */ type?: 'ProSelect'; } & PropSelectType; /** * @description Radio类型映射 */ export type PropRadioPropsMapType = { /** * @description 类型为Radio * @default "Radio" */ type?: 'Radio'; } & RadioProps; /** * @description Checkbox类型映射 */ export type CheckboxPropsMapType = { /** * @description 类型为Checkbox * @default "Checkbox" */ type?: 'Checkbox'; } & CheckboxProps; /** * @description Tag类型映射 */ export interface TagPropsMapType { /** * @description 类型为Tag或Group * @default - */ type?: 'Tag' | 'Group'; } /** * @description ProEnum组件属性类型 */ export type ProEnumType = Omit & (PropProSelectsMapType | PropRadioPropsMapType | CheckboxPropsMapType | TagPropsMapType); export {};