UNPKG

@flatbiz/antd

Version:
76 lines (73 loc) 2.62 kB
import { TAny, TPlainObject } from '@flatbiz/utils'; import { CSSProperties, ReactElement } from 'react'; export type LocalLoadingServiceConfig = { onRequest: (params?: TAny) => Promise<TAny>; params?: TPlainObject; /** 标记serviceConfig.params中无效参数,被设置的params key 不传入服务接口入参 */ invalidParamKey?: string[]; /** 必填字段设置 */ requiredParamsKeys?: string[]; }; export interface LocalLoadingProps { className?: string; style?: CSSProperties; contentStyle?: CSSProperties; /** 接口数据配置 */ serviceConfig: LocalLoadingServiceConfig; /** children 为函数,参数【respData】为接口返回数据 */ children: (respData?: TAny) => ReactElement; /** * 是否异步,默认:false * ``` * true(异步):onRequest、react dom渲染同步执行 * false(同步):onRequest有结果了才渲染 react dom * ``` */ isAsync?: boolean; /** loading高度,默认值:100;isAsync = true 无效 */ loadingHeight?: number | string; /** loading spin 属性设置 */ loadingSpinProps?: { /** loading tip,默认值:Loading */ tip?: string; /** loading 内容 */ content?: ReactElement; /** 背景色,默认值:rgba(0,0,0,0.01) */ bgColor?: string; }; textConfigs?: { /** 必填异常文本 */ requiredErrorText?: string; }; /** 是否显示必填异常 */ showRequiredError?: boolean; /** 自定义异常渲染处理 */ errorRender?: (error?: TAny) => ReactElement; /** 设置内部滚动,需要设置 style.height 才能生效,@5.0.16 */ contentScroll?: boolean; /** 设置高度 */ height?: number | string; } export type LocalLoadingRefApi = { onRefresh: (params?: TPlainObject) => void; }; /** * 局部加载,包含接口数据处理逻辑 * ``` * 包括 * 1. loading显示效果、error显示效果、获取服务数据 * 2. 当 serviceConfig.params 值与上一次值不相等时,会主动发起服务调用 * 3. 通过 serviceConfig.requiredParamsKeys 设置服务调用必填字段 * 4. 通过 ref.onRequest 可主动发起服务调用 * 5. 子组件通过下面方式主动发起服务调用 * const localLoadingApi = LocalLoading.useLocalLoading(); * localLoadingApi.onRequest(); * 6. 如果内部需要滚动条,可设置 contentScroll = true (外部有高度或者设置style.height 才能生效) * ``` */ export declare const LocalLoading: import("react").ForwardRefExoticComponent<LocalLoadingProps & import("react").RefAttributes<LocalLoadingRefApi>> & { useLocalLoading: () => { onRequest: (params?: TPlainObject) => void; }; }; export {};