import React, { ReactNode } from 'react'; import { RadioProps, CheckboxProps } from 'antd'; import { Service, Options } from 'ahooks/lib/useRequest/src/types'; import { ProFormOtherProps } from '../index'; import { PropSelectProps } from '../ProSelect/propsType'; export interface DataOption { label?: string; value?: string; disabled?: boolean; [key: string]: any; } export interface ProEnumConfig { /** 是否枚举主入口 */ main?: boolean; /** 是否使用主入口枚举 */ share?: boolean; /** 是否开启调试 log */ debugger?: boolean; /** 是否对数据进行清洗 */ clear?: boolean; /** 字段别名 */ fieldNames?: Record<'label' | 'value' | 'children', string>; /** 缓存的key、默认 zat-design-pro-component-cacheKey */ cacheKey: string; /** 刷新请求、设置后每次进入都会重新请求 */ requestRefresh: boolean; /** 存储位置、不设置、默认读取 globalConfig 里面的 */ storage: 'localStorage' | 'sessionStorage'; /** 默认静态枚举数据 */ dataSource: Record; /** 对后台返回数据进行格式化 */ transformResponse?: (data: { data: Record; }) => Record | Promise>; /** 批量请求枚举接口 */ useRequest?: { service: Service; options?: Options & { codes?: string[]; ignoreCodes?: string[]; }; }; dics: Record; } type ProEnumType = 'ProSelect' | 'Radio' | 'Checkbox' | 'Tag'; export interface ProEnum { /** 组件展示类型、默认 ProSelect */ type?: ProEnumType; /** 用于自定义组件 */ component?: ReactNode; /** 用于提交 code */ code: string | string[]; /** 字段别名 */ fieldNames?: Record; /** 是否查看模式 */ isView?: boolean; /** 数据源 */ dataSource?: DataOption[]; value: any; onChange?: (value: any) => void; /** 远程请求接口 */ useRequest?: { service: Service; options?: Options; }; /** 对后台返回数据进行格式化 */ transformResponse?: (data: any) => DataOption[]; /** 时候合并 */ merge?: boolean; /** 查看模式下为空展示 */ viewEmpty?: React.ReactNode; optionRender?: any; /** 显示 code-value 形式 */ showCodeName?: boolean; /** 支持 {label:xx, value: xx} */ labelInValue?: boolean; otherProps?: ProFormOtherProps; } export type PropProSelectsMap = { type?: 'ProSelect'; } & PropSelectProps; export type PropRadioPropsMap = { type?: 'Radio'; } & RadioProps; export type CheckboxPropsMap = { type?: 'Checkbox'; } & CheckboxProps; export interface TagPropsMap { type?: 'Tag'; } export type ProEnumProps = Omit & (PropProSelectsMap | PropRadioPropsMap | CheckboxPropsMap | TagPropsMap); export {};