UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

474 lines (473 loc) 16.3 kB
import { AxiosError, AxiosInstance, AxiosPromise, AxiosRequestConfig, Method } from 'axios'; import { CSSProperties, ReactNode } from 'react'; import noop from 'lodash/noop'; import { Tooltip } from '../../pro/lib/core/enum'; import { LovConfig } from '../../pro/lib/lov/Lov'; import { ExportMode, RecordStatus } from '../../pro/lib/data-set/enum'; import { expandIconProps, Suffixes, TableCustomized, TablePaginationConfig, TableProps, TableQueryBarHook } from '../../pro/lib/table/Table'; import { PerformanceTableCustomized } from '../../pro/lib/performance-table/Table.d.ts'; import { ValidationMessages } from '../../pro/lib/validator/Validator'; import { ButtonProps } from '../../pro/lib/button/Button'; import { ColumnAlign, DragColumnAlign, HighLightRowType, TableQueryBarType } from '../../pro/lib/table/enum'; import { TransportHookProps, TransportProps } from '../../pro/lib/data-set/Transport'; import DataSet from '../../pro/lib/data-set/DataSet'; import { FeedBack } from '../../pro/lib/data-set/FeedBack'; import Record from '../../pro/lib/data-set/Record'; import Field from '../../pro/lib/data-set/Field'; import { CacheOptions } from '../../pro/lib/_util/Cache'; import { LabelLayout, ShowValidation } from '../../pro/lib/form/enum'; import { ButtonColor, FuncType } from '../../pro/lib/button/enum'; import { HighlightRenderer } from '../../pro/lib/field/FormField'; import { FormatNumberFunc, FormatNumberFuncOptions } from '../../pro/lib/number-field/NumberField'; import { ModalProps } from '../../pro/lib/modal/interface'; import { ColumnProps, onCellProps } from '../../pro/lib/table/Column'; import { TimeZone } from '../../pro/lib/date-picker/DatePicker'; import { AttachmentListType } from '../../pro/lib/attachment/Attachment'; import AttachmentFile, { FileLike } from '../../pro/lib/data-set/AttachmentFile'; import { Action } from '../trigger/enum'; import { TooltipTheme } from '../tooltip'; import { SpinProps } from '../spin'; import { PanelProps } from '../collapse'; import { Size } from '../_util/enum'; import { TabsCustomized } from '../tabs/Tabs'; export declare type Status = { [RecordStatus.add]: string; [RecordStatus.update]: string; [RecordStatus.delete]: string; }; export declare type renderEmptyHandler = (componentName?: string) => ReactNode; export declare type PerformanceEvents = { Table: { name: string; url: string | undefined; size: number; timing: { fetchStart: number; fetchEnd: number; loadStart: number; loadEnd: number; renderStart: number; renderEnd: number; }; }; }; export declare type PerformanceEventHook<T extends keyof PerformanceEvents> = (key: T, event: PerformanceEvents[T]) => void; export declare type TooltipTarget = 'table-cell' | 'output' | 'label' | 'button' | 'select-option' | 'validation' | 'help'; export declare type TooltipHook = (target?: TooltipTarget) => Tooltip | undefined; export declare type TooltipThemeHook = (target?: TooltipTarget) => TooltipTheme; export declare type TableFilterAdapterProps = ({ type, config, searchCode, queryDataSet }: { type: any; config: any; searchCode: any; queryDataSet: any; }) => AxiosRequestConfig; export declare type Customizable = { Table?: boolean; PerformanceTable?: boolean; Tabs?: boolean; }; export interface Customized { Table?: TableCustomized; PerformanceTable?: PerformanceTableCustomized; Tabs?: TabsCustomized; } export declare type CustomizedSave = <T extends keyof Customized>(code: string, customized: Customized[T], component: T) => void; export declare type CustomizedLoad = <T extends keyof Customized>(code: string, component: T) => Promise<Customized[T] | null>; export declare type Formatter = { jsonDate: string | null; date: string; dateTime: string; time: string; year: string; month: string; week: string; timeZone?: TimeZone; }; export declare type AttachmentConfig = { defaultFileKey: string; defaultFileSize: number; action?: AxiosRequestConfig | ((props: { attachment: AttachmentFile; bucketName?: string; bucketDirectory?: string; storageCode?: string; attachmentUUID: string; }) => AxiosRequestConfig); batchFetchCount?: <T extends string | number | symbol>(attachmentUUIDs: T[]) => Promise<{ [key in T]: number; }>; fetchList?: (props: { bucketName?: string; bucketDirectory?: string; storageCode?: string; attachmentUUID: string; }) => Promise<FileLike[]>; getPreviewUrl?: (props: { attachment: AttachmentFile; bucketName?: string; bucketDirectory?: string; storageCode?: string; attachmentUUID: string; }) => string; getDownloadUrl?: (props: { attachment: AttachmentFile; bucketName?: string; bucketDirectory?: string; storageCode?: string; attachmentUUID: string; }) => string; getDownloadAllUrl?: (props: { bucketName?: string; bucketDirectory?: string; storageCode?: string; attachmentUUID: string; }) => string; getAttachmentUUID?: () => Promise<string> | string; renderIcon?: (attachment: AttachmentFile, listType: AttachmentListType, defaultIcon: ReactNode) => ReactNode; renderHistory?: (props: { attachment: AttachmentFile; bucketName?: string; bucketDirectory?: string; storageCode?: string; attachmentUUID: string; }) => ReactNode; onUploadSuccess?: (response: any, attachment: AttachmentFile) => void; onUploadError?: (error: AxiosError, attachment: AttachmentFile) => void; onOrderChange?: (props: { attachmentUUID: string; attachments: AttachmentFile[]; bucketName?: string; bucketDirectory?: string; storageCode?: string; }) => Promise<void>; onRemove?: (props: { attachment: AttachmentFile; attachmentUUID: string; bucketName?: string; bucketDirectory?: string; storageCode?: string; }) => Promise<boolean>; }; export declare type Config = { prefixCls?: string; proPrefixCls?: string; iconfontPrefix?: string; ripple?: boolean; collapseExpandIconPosition?: string; collapseExpandIcon?: (panelProps: PanelProps) => ReactNode | 'text'; collapseTrigger?: string; lookupCache?: CacheOptions<string, AxiosPromise>; lookupUrl?: string | ((code: string) => string); lookupAxiosMethod?: Method; lookupAxiosConfig?: AxiosRequestConfig | ((props: { params?: any; dataSet?: DataSet; record?: Record; lookupCode?: string; }) => AxiosRequestConfig); lookupBatchAxiosConfig?: (codes: string[]) => AxiosRequestConfig; lovDefineUrl?: string | ((code: string) => string); lovDefineAxiosConfig?: AxiosRequestConfig | ((code: string) => AxiosRequestConfig); lovQueryUrl?: string | ((code: string, lovConfig: LovConfig | undefined, props: TransportHookProps) => string); lovQueryAxiosConfig?: AxiosRequestConfig | ((code: string, lovConfig: LovConfig | undefined, props: TransportHookProps) => AxiosRequestConfig); lovQueryCachedSelected?: (code: string, cachedSelected: Map<string, Record>) => Promise<object[]>; lovTableProps?: Partial<TableProps>; lovModalProps?: Partial<ModalProps>; lovAutoSelectSingle?: boolean; lovQueryBar?: TableQueryBarType | TableQueryBarHook; lovQueryBarProps?: object; axios?: AxiosInstance; feedback?: FeedBack; dataKey?: string; totalKey?: string; statusKey?: string; tlsKey?: string; status?: Status; exportMode?: ExportMode; labelLayout?: LabelLayout; queryBar?: TableQueryBarType | TableQueryBarHook; queryBarProps?: object; tableVirtual?: boolean; tableVirtualCell?: boolean; tableBorder?: boolean; tableColumnEditorBorder?: boolean; tableHighLightRow?: boolean | HighLightRowType; tableParityRow?: boolean; tableSelectedHighLightRow?: boolean; tableRowHeight?: 'auto' | number; tableColumnResizable?: boolean; tableColumnHideable?: boolean; performanceTableColumnHideable?: boolean; tableColumnTitleEditable?: boolean; performanceTableColumnTitleEditable?: boolean; tableDragColumnAlign?: DragColumnAlign; tableColumnDraggable?: boolean; performanceTableColumnDraggable?: boolean; tableRowDraggable?: boolean; tableExpandIcon?: (props: expandIconProps) => ReactNode; tableSpinProps?: SpinProps; tableButtonProps?: ButtonProps; tableCommandProps?: ButtonProps; tableColumnOnCell?: (props: onCellProps) => object; tableColumnAlign?: (column: ColumnProps, field?: Field) => ColumnAlign | undefined; tableShowSelectionTips?: boolean; tableAlwaysShowRowBox?: boolean; tableUseMouseBatchChoose?: boolean; tableEditorNextKeyEnterDown?: boolean; tableAutoFocus?: boolean; tableKeyboard?: boolean; tableFilterAdapter?: TableFilterAdapterProps; tableFilterSuffix?: Suffixes[]; tableFilterSearchText?: string; tableAutoHeightDiff?: number; tableShowRemovedRow?: boolean; tableButtonsLimit?: number; pagination?: TablePaginationConfig | false; modalSectionBorder?: boolean; drawerSectionBorder?: boolean; drawerTransitionName?: string; modalAutoCenter?: boolean; modalOkFirst?: boolean; drawerOkFirst?: boolean; modalButtonProps?: ButtonProps; modalKeyboard?: boolean; modalMaskClosable?: string | boolean; buttonFuncType?: FuncType; buttonColor?: ButtonColor; renderEmpty?: renderEmptyHandler; highlightRenderer?: HighlightRenderer; defaultValidationMessages?: ValidationMessages; transport?: TransportProps; icons?: { [key: string]: string[]; } | string[]; generatePageQuery?: (pageParams: { page?: number; pageSize?: number; sortName?: string; sortOrder?: string; sort?: string[]; }) => object; formatter?: Formatter; dropdownMatchSelectWidth?: boolean; selectReverse?: boolean; selectPagingOptionContent?: string | ReactNode; selectSearchable?: boolean; selectTrigger?: Action[]; useColon?: boolean; textFieldAutoComplete?: string; resultStatusRenderer?: object; numberFieldNonStrictStep?: boolean; numberFieldFormatter?: FormatNumberFunc; numberFieldFormatterOptions?: FormatNumberFuncOptions; currencyFormatter?: FormatNumberFunc; currencyFormatterOptions?: FormatNumberFuncOptions; /** * 是否显示长度信息 */ showLengthInfo?: boolean; /** * moment非法时显示Invalid date */ showInvalidDate?: boolean; /** * 只有在空值时显示必填背景色和边框色 */ showRequiredColorsOnlyEmpty?: boolean; /** * 性能监控钩子 */ onPerformance?: PerformanceEventHook<keyof PerformanceEvents>; /** * 开启性能监控 */ performanceEnabled?: { [key in keyof PerformanceEvents]: boolean; }; /** * tooltip */ tooltip?: Tooltip | TooltipHook; /** * tooltip 主题 */ tooltipTheme?: TooltipTheme | TooltipThemeHook; /** * 附件相关配置 */ attachment?: AttachmentConfig; /** * 表单校验提示方式 */ showValidation?: ShowValidation; /** * Tabs 墨条样式 */ tabsInkBarStyle?: CSSProperties; /** * 个性化开关 */ customizable?: boolean | Customizable; customizedSave?: CustomizedSave; customizedLoad?: CustomizedLoad; /** * @deprecated */ validationTooltipTheme?: TooltipTheme; /** * @deprecated */ tableColumnTooltip?: Tooltip; /** * @deprecated */ buttonTooltip?: Tooltip; /** * @deprecated */ selectOptionTooltip?: Tooltip; /** * @deprecated */ labelTooltip?: Tooltip; /** * @deprecated */ excludeUseColonTagList?: string[]; /** * @deprecated */ tableDefaultRenderer?: ReactNode; /** * @deprecated * 同 tableColumnDraggable */ tableDragColumn?: boolean; /** * @deprecated * 同 tableRowDraggable */ tableDragRow?: boolean; /** * @deprecated */ lovTableCustomizable?: boolean; /** * @deprecated */ tableCustomizable?: boolean; /** * @deprecated */ performanceTableCustomizable?: boolean; /** * @deprecated */ tableCustomizedSave?: CustomizedSave; /** * @deprecated */ tableCustomizedLoad?: CustomizedLoad; }; export declare type ConfigKeys = keyof Config; declare const defaultConfig: { prefixCls: string; proPrefixCls: string; iconfontPrefix: string; ripple: boolean; collapseExpandIconPosition: string; collapseTrigger: string; lookupCache: CacheOptions<string, AxiosPromise<any>>; lookupUrl: (code: any) => string; lookupAxiosMethod: Method; lovDefineUrl: (code: any) => string; lovQueryUrl: (code: any) => string; lovTableProps: {}; lovModalProps: {}; lovAutoSelectSingle: boolean; dataKey: string; totalKey: string; statusKey: string; tlsKey: string; status: Status; labelLayout: LabelLayout; queryBar: TableQueryBarType; tableBorder: boolean; tableHighLightRow: boolean; tableSelectedHighLightRow: boolean; tableRowHeight: number; tableDefaultRenderer: string; tableColumnResizable: boolean; tableColumnHideable: boolean; performanceTableColumnHideable: boolean; tableRowDraggable: boolean; tableColumnDraggable: boolean; performanceTableColumnDraggable: boolean; tableColumnAlign: (_column: ColumnProps, field?: Field | undefined) => ColumnAlign | undefined; tableSpinProps: { size: Size; wrapperClassName: string; }; tableButtonProps: ButtonProps; tableCommandProps: ButtonProps; tableAlwaysShowRowBox: boolean; tableUseMouseBatchChoose: boolean; tableEditorNextKeyEnterDown: boolean; tableAutoFocus: boolean; tableKeyboard: boolean; tableFilterSearchText: string; tableAutoHeightDiff: number; customizedSave: CustomizedSave; customizedLoad: CustomizedLoad; tableShowRemovedRow: boolean; modalSectionBorder: boolean; drawerSectionBorder: boolean; drawerTransitionName: string; modalOkFirst: boolean; modalAutoCenter: boolean; modalKeyboard: boolean; modalMaskClosable: boolean; buttonColor: ButtonColor; buttonFuncType: FuncType; feedback: { loadSuccess(_result: any): void; loadFailed(error: any): void; submitSuccess(_result: any): void; submitFailed(error: any): void; }; renderEmpty: renderEmptyHandler; icons: { whatsNew: string[]; direction: string[]; suggestion: string[]; edit: string[]; data: string[]; other: string[]; series: string[]; }; formatter: Formatter; dropdownMatchSelectWidth: boolean; selectReverse: boolean; selectPagingOptionContent: string; selectSearchable: boolean; selectTrigger: Action[]; useColon: boolean; excludeUseColonTagList: string[]; numberFieldNonStrictStep: boolean; showInvalidDate: boolean; highlightRenderer: HighlightRenderer; onPerformance: typeof noop; performanceEnabled: { Table: boolean; }; tooltipTheme: TooltipThemeHook; showValidation: ShowValidation; attachment: AttachmentConfig; }; export declare type DefaultConfig = typeof defaultConfig; export declare function getConfig<T extends ConfigKeys>(key: T): T extends keyof DefaultConfig ? DefaultConfig[T] : Config[T]; export declare function getPrefixCls(suffixCls: string, customizePrefixCls?: string): string; export declare function getProPrefixCls(suffixCls: string, customizePrefixCls?: string): string; export declare function getCustomizable<T extends keyof Customizable>(component: T): boolean | undefined; export default function configure(config: Config, merge?: boolean): void; export {};