import type React from 'react'; import type { FormInstance, ThemeConfig } from 'antd'; import type { PropSelectType } from '../ProSelect/propsType'; import type { ProModalSelectType } from '../ProForm/components/combination/ProModalSelect/propsType'; import type { ProCascaderType } from '../ProForm/components/combination/ProCascader/propsType'; import type { ProEnumConfigType } from '../ProEnum/propsType'; /** 浏览器缓存类型,与 ProEnum / ProTable 的 StorageType 定义一致 */ export type StorageType = 'localStorage' | 'sessionStorage' | 'indexedDB'; /** 项目级全局配置(一处配置,全局生效) */ export interface GlobalConfig { /** 缓存存储位置,影响 ProTable 列配置缓存与 ProEnum 枚举缓存,默认由各组件自身决定 */ storage?: StorageType; } /** ProTable 组件全局默认配置,通过 ProConfigProvider 统一设置,无需每个实例单独声明 */ export interface ProTableGlobalConfig { /** 是否开启可伸缩列功能,默认 false */ resizeColumn?: boolean; /** 是否开启列配置功能,开启时默认同步开启缓存,默认 false */ columnConfig?: boolean | { onColumnOk?: (catchColumns: any, columns: any[]) => Promise; }; /** 是否开启列配置缓存,单位为天,true 时缓存一天,默认 false */ cacheTime?: number | boolean; } /** 对外配置项类型(value、内部 state 均为此类型,字段均可选) */ export interface ProConfigProviderType { locale?: string; /** 项目级全局配置:缓存位置等跨组件通用配置 */ globalConfig?: GlobalConfig; /** ProTable 组件全局默认配置 */ ProTable?: ProTableGlobalConfig; ProEnum?: Partial; ProSelect?: Partial & Record; ProModalSelect?: Partial & Record; ProAddressBar?: Partial & Record; ProCascader?: Partial & Record; forms?: Record; [key: string]: any; } /** ProConfigProvider 组件 Props(内部使用) */ export interface ProConfigProviderProps { value?: ProConfigProviderType; locale?: string; /** antd 原生主题配置,用法同 antd ConfigProvider 的 theme,会与内部 ThemeContext 的 antdConfig 深度合并后透传 */ theme?: ThemeConfig; onSuccess?: (data: any, params: any) => void; children?: React.ReactNode; } /** Config 上下文 */ export interface ConfigContext { state: ProConfigProviderType; dispatch: React.Dispatch; } /** ThemeAwareConfigProvider 内部组件 Props */ export interface ThemeAwareConfigProviderProps { locale: any; /** 外部传入的 antd 主题配置,与 ThemeContext 的 antdConfig 合并 */ theme?: ThemeConfig; children: React.ReactNode; } /** Reducer Actions */ export type ProConfigActions = { type: 'setFormRef'; name: string; value: FormInstance; } | { type: 'deleteFormRef'; name: string; } | { type: 'set'; payload: ProConfigProviderType; } | { type: 'setProEnum'; payload: Record; } | { type: 'setProEnumDic'; key: string; payload: any; } | { type: 'setWithLocal'; payload: ProConfigProviderType; };