choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
171 lines (170 loc) • 7.7 kB
TypeScript
import { AxiosError, AxiosInstance, AxiosPromise, AxiosRequestConfig, Method } from 'axios';
import { Moment, MomentInput } from 'moment';
import noop from 'lodash/noop';
import { LovConfig } from '../interface';
import { ExportMode, RecordStatus, FieldType, DownloadAllMode } from '../data-set/enum';
import { ValidationMessages } from '../validator/Validator';
import { TransportHookProps, TransportProps } from '../data-set/Transport';
import DataSet from '../data-set/DataSet';
import { FeedBack } from '../data-set/FeedBack';
import { defaultValidationMessageFormatter, defaultValidationMessageReportFormatter, ValidationMessageFormatter, ValidationMessageReportFormatter } from '../validator/ValidationMessageReportFormatter';
import Field from '../data-set/Field';
import Record from '../data-set/Record';
import { CacheOptions } from '../cache';
import AttachmentFile, { FileLike } from '../data-set/AttachmentFile';
import AttachmentFileChunk from '../data-set/AttachmentFileChunk';
export declare type TimeZone = string | ((moment: Moment) => string);
export declare type Status = {
[RecordStatus.add]: string;
[RecordStatus.update]: string;
[RecordStatus.delete]: string;
};
export declare type Formatter = {
jsonDate: string | null;
date: string;
dateTime: string;
time: string;
year: string;
month: string;
week: string;
timeZone?: TimeZone;
};
export declare type AttachmentBatchFetchCount = <T extends string | number | symbol>(attachmentUUIDs: T[], props: {
isPublic?: boolean;
items: AttachmentValue[];
}) => Promise<{
[key in T]: number;
}>;
export interface AttachmentOption {
bucketName?: string;
bucketDirectory?: string;
storageCode?: string;
isPublic?: boolean;
}
export interface AttachmentValue extends AttachmentOption {
attachmentUUID: string;
}
export interface AttachmentProps extends AttachmentOption {
attachmentUUID?: string | undefined;
}
export interface AttachmentsProps extends AttachmentValue {
attachments: AttachmentFile[];
}
export interface AttachmentFileProps extends AttachmentProps {
attachment: AttachmentFile;
}
export interface AttachmentUseChunkProps extends AttachmentOption {
useChunk?: boolean;
}
export interface AttachmentChunkProps extends AttachmentFileProps {
chunk: AttachmentFileChunk;
}
export interface AttachmentActionProps extends AttachmentFileProps {
chunk?: AttachmentFileChunk | undefined;
}
export declare type TemplateUrlType = string | Function | undefined;
export interface AttachmentConfig {
defaultFileKey: string;
defaultFileSize: number;
defaultChunkSize: number;
defaultChunkThreads: number;
downloadAllMode?: DownloadAllMode;
action?: AxiosRequestConfig | ((props: AttachmentActionProps) => AxiosRequestConfig);
batchFetchCount?: AttachmentBatchFetchCount;
fetchFileSize?: (props: AttachmentOption) => Promise<number>;
fetchList?: (props: AttachmentValue) => Promise<FileLike[]>;
getPreviewUrl?: (props: AttachmentFileProps) => (string | (() => string | Promise<string>) | undefined);
getDownloadUrl?: (props: AttachmentFileProps) => string | Function | undefined;
getTemplateDownloadUrl?: (props: AttachmentValue) => TemplateUrlType | Promise<TemplateUrlType>;
getDownloadAllUrl?: (props: AttachmentValue) => string | Function | undefined;
getAttachmentUUID?: (props: {
isPublic?: boolean;
}) => Promise<string> | string;
onBeforeUpload?: (attachment: AttachmentFile, attachments: AttachmentFile[], props: AttachmentUseChunkProps) => boolean | undefined | PromiseLike<boolean | undefined>;
onBeforeUploadChunk?: (props: AttachmentChunkProps) => boolean | undefined | PromiseLike<boolean | undefined>;
onUploadSuccess?: (response: any, attachment: AttachmentFile, props: AttachmentUseChunkProps) => void;
onUploadError?: (error: AxiosError, attachment: AttachmentFile) => void;
onOrderChange?: (props: AttachmentsProps) => Promise<void>;
onRemove?: (props: AttachmentFileProps, multiple: boolean) => Promise<boolean>;
}
export interface Config {
cacheRecords?: boolean;
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;
useLookupBatch?: (code: string, field?: Field) => boolean;
lovDefineUrl?: string | ((code: string) => string);
lovDefineAxiosConfig?: AxiosRequestConfig | ((code: string, field?: Field) => AxiosRequestConfig);
lovDefineBatchAxiosConfig?: (codes: string[]) => AxiosRequestConfig;
useLovDefineBatch?: (code: string, field?: Field) => boolean;
lovQueryUrl?: string | ((code: string, lovConfig: LovConfig | undefined, props: TransportHookProps) => string);
lovQueryAxiosConfig?: AxiosRequestConfig | ((code: string, lovConfig: LovConfig | undefined, props: TransportHookProps) => AxiosRequestConfig);
axios?: AxiosInstance;
feedback?: FeedBack;
autoCount?: boolean;
dataKey?: string;
totalKey?: string;
countKey?: string;
statusKey?: string;
tlsKey?: string;
status?: Status;
exportMode?: ExportMode;
defaultValidationMessages?: ValidationMessages;
validationMessageFormatter?: ValidationMessageFormatter;
validationMessageReportFormatter?: ValidationMessageReportFormatter;
transport?: TransportProps;
generatePageQuery?: (pageParams: {
page?: number;
pageSize?: number;
count?: 'Y' | 'N';
defaultCount?: 'Y' | 'N';
onlyCount?: 'Y' | 'N';
totalCount?: number;
sortName?: string;
sortOrder?: string;
sort?: string[];
}) => object;
formatter?: Formatter;
attachment?: AttachmentConfig;
numberFieldNonStrictStep?: boolean;
confirm?: (message: any, dataSet?: DataSet, source?: string) => Promise<boolean>;
min?: (type: FieldType) => number | MomentInput | string | null;
max?: (type: FieldType) => number | MomentInput | string | null;
xlsx?: () => Promise<any>;
}
export declare type ConfigKeys = keyof Config;
declare const defaultConfig: {
lookupCache: CacheOptions<string, AxiosPromise<any>>;
lookupUrl: (code: any) => string;
lookupAxiosMethod: Method;
lovDefineUrl: (code: any) => string;
lovQueryUrl: (code: any) => string;
dataKey: string;
totalKey: string;
countKey: string;
statusKey: string;
tlsKey: string;
status: Status;
feedback: Required<FeedBack>;
formatter: Formatter;
attachment: AttachmentConfig;
confirm: (_message: any, _dataSet?: DataSet | undefined, _source?: string | undefined) => Promise<boolean>;
validationMessageFormatter: typeof defaultValidationMessageFormatter;
validationMessageReportFormatter: typeof defaultValidationMessageReportFormatter;
xlsx: typeof noop;
useLookupBatch: typeof noop;
useLovDefineBatch: typeof noop;
};
export declare type DefaultConfig = typeof defaultConfig;
export declare function getConfig<C extends Config, T extends keyof C, D extends DefaultConfig>(key: T): T extends keyof D ? D[T] : C[T];
export declare function overwriteDefaultConfig<T extends Config>(config: T, mergeProps?: (keyof T)[] | null): void;
export declare function overwriteConfigMergeProps<T extends Config>(customMergeProps: (keyof T)[]): void;
export default function configure<T extends Config>(config: T, mergeProps?: (keyof T)[] | null): void;
export {};