UNPKG

@rwsbillyang/preact-usecache

Version:

preact hooks use cache before client fetch data from remote server, likes cache in server side before database I/O

651 lines (634 loc) 29.9 kB
import * as preact_hooks from 'preact/hooks'; declare const Cache: { /** * find one from cache * @param shortKey * @param id * @param idKey * @param storageType default configed in UseCacheConfig.defaultStorageType * @returns */ findOne: <T>(shortKey: string, id?: string | number, idKey?: string, storageType?: number) => T | undefined; findMany: <T_1>(shortKey: string, ids: (string | number)[], key?: string, storageType?: number) => T_1[] | undefined; /** * add new one into list * @param shortKey * @param e * @param storageType * @returns */ onAddOne: <T_2>(shortKey: string, e: T_2, storageType?: number) => boolean; onAddOneInList: <T_3>(e: T_3, arry?: T_3[] | undefined) => T_3[]; /** * call it when update one successully * @param shortKey cachekey = UseCacheConfig.cacheKeyPrefix() + shortKey * @param e entity * @param id find one by which key, default:"_id" * @param storageType * @returns return true if update one successfully, or else false */ onEditOne: <T_4>(shortKey: string, e: T_4, idKey?: string, storageType?: number) => boolean; onEditOneInList: <T_5>(e: T_5, arry?: T_5[] | undefined, idKey?: string) => boolean; /** * call it after batch update * @param shortKey cachekey = UseCacheConfig.cacheKeyPrefix() + shortKey * @param list entity * @param key find one by which key, default:"_id" * @param storageType * @returns update none return false, return true if update any one success */ onEditMany: <T_6>(shortKey: string, list: T_6[], key?: string, storageType?: number) => boolean; onEditManyInList: <T_7>(list: T_7[], arry?: T_7[] | undefined, key?: string) => boolean; /** * call it when delete one successfully * @param shortKey cachekey = UseCacheConfig.cacheKeyPrefix() + shortKey * @param id value of key * @param key find one by which key, default:"_id" * @param storageType * @returns true if successful */ onDelOneById: <T_8>(shortKey: string, id?: string | number, key?: string, storageType?: number) => boolean; onDelOneByIdInList: <T_9>(id?: string | number, arry?: T_9[] | undefined, key?: string) => boolean; /** * call it when delete one successfully * @param shortKey cachekey = UseCacheConfig.cacheKeyPrefix() + shortKey * @param e entity, item of list * @param key find one by which key, default:"_id" * @param storageType * @returns true if successful */ onDelOne: <T_10>(shortKey: string, e: T_10, key?: string, storageType?: number) => boolean; onDelOneInList: <T_11>(e: T_11, arry?: T_11[] | undefined, key?: string) => boolean; /** * call it when batch delete manys successfully * @param shortKey cachekey = UseCacheConfig.cacheKeyPrefix() + shortKey * @param ids values of key * @param key find one by which key, default:"_id" * @param storageType * @returns true if successful */ onDelManyByIds: <T_12>(shortKey: string, ids?: (string | number)[], key?: string, storageType?: number) => boolean; onDelManyByIdsInList: <T_13>(ids?: (string | number)[], arry?: T_13[] | undefined, key?: string) => boolean; /** * call it when batch delete manys successfully * @param shortKey cachekey = UseCacheConfig.cacheKeyPrefix() + shortKey * @param list entity list * @param key find one by which key, default:"_id" * @param storageType * @returns true if successful */ onDelMany: <T_14>(shortKey: string, list: T_14[], key?: string, storageType?: number) => boolean; onDelManyInList: <T_15>(toDelList: T_15[], arry?: T_15[] | undefined, key?: string) => boolean; /** * evict given key cache with storageType * @param shortKey * @param storageType */ evictCache: (shortKey: string, storageType?: number) => void; /** * evict all cache with storageType * @param storageType */ evictAllCaches: (storageType?: number) => void; }; /** * cache type */ declare const StorageType: { OnlySessionStorage: number; OnlyLocalStorage: number; BothStorage: number; NONE: number; }; /** * */ interface IRequest { get: (url: string, data?: object) => Promise<Response>; post: (url: string, data?: object) => Promise<Response>; upload: (url: string, data: ArrayBuffer | Blob) => Promise<Response>; getWithoutAuth: (url: string, data?: object, crossDomain?: boolean) => Promise<Response>; postWithoutAuth: (url: string, data?: object, crossDomain?: boolean) => Promise<Response>; } interface IUseCacheConfig { EnableLog: boolean; cacheSpace: () => string; defaultIdentiyKey: string; defaultStorageType: number; PageSize: number; request: IRequest; authheaders: () => {} | undefined; /** * show loading when load data, eg: () => f7.preloader.show() */ showLoading?: (text?: string) => void; /** * hide loading, eg: () => f7.preloader.hide() */ hideLoading?: () => void; /** * show toast, eg: (msg) => f7.toast.show({ text: msg || "操作成功" }), */ showToast?: (msg?: string) => void; } /** * Should provide authheaders */ declare const UseCacheConfig: IUseCacheConfig; declare const CacheStorage: { /** * * @param shortKey cachekey = UseCacheConfig.cacheKeyPrefix() + shortKey * @param storageType localStorage or sessionStorage, or both, or none * @param defaultValue default value * @returns string or undefined */ getItem: (shortKey: string, storageType?: number, defaultValue?: string) => string | undefined; /** * * @param shortKey cachekey = UseCacheConfig.cacheKeyPrefix() + shortKey * @param storageType localStorage or sessionStorage, or both, or none * @param defaultValue default value * @returns object after JSON.parse */ getObject: (shortKey: string, storageType?: number, defaultValue?: object) => any; /** * * @param shortKey cachekey = UseCacheConfig.cacheKeyPrefix() + shortKey * @param v string value * @param storageType ocalStorage or sessionStorage, or both * @returns */ saveItem: (shortKey: string, v: string, storageType?: number) => void; /** * * @param shortKey cachekey = UseCacheConfig.cacheKeyPrefix() + shortKey * @param v object after JSON.stringify and save it * @param storageType ocalStorage or sessionStorage, or both */ saveObject: (shortKey: string, v: object, storageType?: number) => void; remove: (shortKey: string, storageType?: number) => void; }; /** * code definition in payload from server */ declare enum CODE { OK = "OK", KO = "KO", NewUser = "NewUser", TokenExpired = "TokenExpired" } /** * response from remote server * @param code OK if correct, KO or others if wrong * @param msg error msg * @param type refer to import { ErrorShowType } from 'umi'; * <code> * export enum ErrorShowType { * SILENT = 0, // 不提示错误 * WARN_MESSAGE = 1, // 警告信息提示 * ERROR_MESSAGE = 2, // 错误信息提示 * NOTIFICATION = 4, // 通知提示 * REDIRECT = 9, // 页面跳转 * } * </code> * @param tId traceId from remote server, for debug * @param host host of remote server, for debug */ interface DataBoxBase { code: string; msg?: string; type: number; tId?: string; host?: string; } /** * databox responsed from remote server * @param data payload data */ interface DataBox<T> extends DataBoxBase { data?: T; } /** * databox include total count responsed from remote server * @param data list data * @param total total count */ interface DataBoxTableList<T> extends DataBoxBase { data?: T[]; total: number; } /** * extract data from databox * @param box DataBox */ declare function getDataFromBox<T>(box: DataBox<T>): T | undefined; /** * base interface for pagination * pagination 将被转化成umi字符串 */ interface BasePageQuery { pagination?: QueryPagination; umi?: string; } /** * pagination parameters * @field pageSize default 10 若为-1则表示全部数据 * @field current 从1起步,若指定了大于0的值,则优先使用页码分页,而不采用lastId. 对于某些排序值不唯一的场景,不适合用lastId进行分页,应指定current为1 * @field sKey sortKey * @field sKeyType 排序的健不一定都是ObjectID类型,亦即lastId的后端类型,有可能是number或string类型,后端定义了三种类型: TypeNumber TypeString TypeObjectId * @field sort 1用于升序,而-1用于降序 * @field lastId current为空时,将使用lastId,该值必须存在列表项中,否则导致取得最后一项的值为空 * @field fKey filter key 暂未用上 * @field filters 暂未用上 */ interface QueryPagination { pageSize?: number; current?: number; sKey?: string; sKeyType?: "TypeObjectId" | "TypeString" | "TypeNumber"; sort?: number; lastId?: string; fKey?: string; filters?: string[]; } declare const encodeUmi: (umi: QueryPagination) => string; /** * * @param url load data from url * @param shortKey load and cache data if provide * @param withouAuth request withou auth headers * @param showLoading //wheter show loading when load data from remote if configed in ConfigRequest * @param storageType // storage type, default: UseCacheConfig.defaultStorageType * @returns { loading, entity, errMsg } */ declare function useCache<T>(url: string, shortKey?: string, withouAuth?: boolean, showLoading?: boolean, storageType?: number, transformDataBoxFromResponseJson?: (json: any) => DataBox<T>): { loading: boolean; entity: T | undefined; errMsg: string | undefined; }; /** * hook which loads list data from cache or remote with pagination * * * fetch from remote: pull-refresh, click loadMore button(need merge into old data) * after load from remote, the useCache is set true, so next time load from cache * * load from local(include but not limit): enter firstly, re-enter, tabs switch,first try to load from cache, if not found then load from remote. * * @param url request url * @param shortKey if undefined, not use cache * @param initalQuery initial query parameters that extends PaginationQueryBase * @param needLoadMore enable load more button, true when enable pagination. If load all data, not need loadMore, set it false. default is true * @param storageType cache storage type, default: sessionStorage * @return isLoading, isError, errMsg, list, loadMoreState, setQuery */ declare function useCacheList<T, Q extends BasePageQuery>(url: string, shortKey?: string, initalQuery?: Q, needLoadMore?: boolean, //是否需要加载更多按钮,分页数据为true,全部数据为false storageType?: number, transformDataBoxFromResponseJson?: (json: any) => DataBox<T[]>): { isLoading: boolean; isError: boolean; errMsg: string | undefined; loadMoreState: boolean; list: T[]; refreshCount: number; setList: preact_hooks.Dispatch<preact_hooks.StateUpdater<T[]>>; setQuery: (query?: Q) => void; setRefresh: () => void; setUseCache: (useLocalCache: boolean) => void; setIsLoadMore: (toLoadMore: boolean) => void; }; /** * @return protocol + "//"+ host, eg: https://www.example.com */ declare const currentHref: () => string; /** * 将对象obj转换成 key1=value1&key2=value2形式的字符串,会对key值进行排序; * 若obj内无key,将返回undefined * @param obj * @param enableEmptyLog 为true时,将日志输出obj中的空值字段 */ declare const serializeObject: (obj?: object, enableEmptyLog?: boolean) => string | undefined; /** * 去除无效参数化后,排序,同时将Pagination转换为umi字符串, * 然后生成:?key1=xx&key2=yy&key3=zz 形式的字符串,无参数化返回空字符”“ * */ declare function query2Params<Q extends BasePageQuery>(query?: Q): string; /** * 基于 https://juejin.cn/post/6844904042322198541改进: * 增加忽略的键,该键的值不被deepCopy * @param data * @param ignoreDeepKeys 忽略deepcopy的键数组,该键的值不被深拷贝 * @param hash * @returns */ declare function deepCopy(data: object, ignoreDeepKeys?: string[], hash?: WeakMap<object, any>): any; /** * load data from remote server or local cache depends on shortKey * * @param url url * @param data if GET/DELETE, will be query parameters, if POST/PUT will be body data * @param method * @param attachAuthHeader default true * @param onOK called when biz data is ok * @param onNoData called if no biz data * @param onKO called if biz data is NOT ok * @param onErr called something wrong including request err, response status not 2xx * @param onDone called if request remote server finishe, called before onOK/onNoData/onKO/onErr * @param shortKey use cache firstly if provide shortKey, if undefined load from remote server * @param storageType default is UseCacheConfig.defaultStorageType * @param isShowLoading default true, if false, not show loading ui even if has showLoading function * @param showLoading show loading if provides * @param hideLoading hide loading if provides * @param transformDataBoxFromResponseJson tranformer from response json from remote to DataBox<T> */ interface FetchParams<T> { url: string; data?: object; method: "GET" | "POST" | "PUT" | "DELETE"; attachAuthHeader?: boolean; shortKey?: string; storageType?: number; onOK: (data: T) => void; onNoData?: () => void; onKO?: (code: string, msg?: string) => void; onErr?: (msg: string) => void; onDone?: () => void; isShowLoading?: boolean; showLoading?: () => void; hideLoading?: () => void; transformDataBoxFromResponseJson?: (json: any) => DataBox<T>; } declare function defaultFetchParams<T>(url: string, onOK: (data: T) => void, data?: object, shortKey?: string, isShowLoading?: boolean, attachAuthHeader?: boolean): FetchParams<T>; declare function cachedGet<T>(url: string, onOK: (data: T) => void, data?: object, shortKey?: string, isShowLoading?: boolean, attachAuthHeader?: boolean): boolean; declare function cachedPost<T>(url: string, onOK: (data: T) => void, data?: object, shortKey?: string, isShowLoading?: boolean, attachAuthHeader?: boolean): boolean; /** * 支持缓存的远程请求, 提供对应的回调将被执行, 支持loading的显示 * DATATYPE为biz data类型 * 若提供了shortKey将首先检查key中是否有数据 * 若提供了showLoading/hideLoading 并打开开关,将支持loading的显示隐藏 * 回调类型包括:数据正常、没有数据、业务错误、请求异常等的回调 */ declare function cachedFetch<DATATYPE>(params: FetchParams<DATATYPE>): boolean; /** * 返回一个Promise * 如果正常则resolve后的结果为T类型; 如果错误发生,reject一个string错误信息 * T可以为payload中的biz data,也可为其它任意包裹类型(需提供transfomFromBizData进行转换) * * 若需使用缓存(先从缓存中读取,没有则从远程获取,获取后将结果保存到缓存中),则需提供shortKey,默认的storageType为UseCacheConfig.defaultStorageType,即sessionStorage中 * 若需将biz data转换成其它类型,则需提供transfomFromBizData转换函数; 不提供时,则T为payload biz data * 若远程返回结果格式不为DataBox<T>,则需提供transformDataBoxFromResponseJson进行转换 * 若需自动添加auth认证时,则将attachAuthHeader设置为true * 若需显示loading,则将isShowLoading设置为true,并提供showLoading/hideLoading函数 * @param url remote reuqest url * @param method "GET" | "POST" | "PUT" | "DELETE" * @param data search query parameters * @param shortKey short cache key * @param storageType UseCacheConfig.defaultStorageType * @param transformDataBoxFromResponseJson tranformer from response json from remote to DataBox<T> * @param transfomFromBizData tranformer from payload biz data to T if provided * @param attachAuthHeader add auth header into request headers * @param isShowLoading show loading when request if provide showLoading function * @param showLoading show loading function * @param hideLoading hide loading function */ declare const cachedFetchPromise: <T>(url: string, method: "GET" | "POST" | "PUT" | "DELETE", data?: object, shortKey?: string, storageType?: number, transformDataBoxFromResponseJson?: ((json: any) => DataBox<T>) | undefined, transfomFromBizData?: ((bizData: any) => T) | undefined, attachAuthHeader?: boolean, isShowLoading?: boolean, showLoading?: () => void, hideLoading?: () => void) => Promise<T | undefined>; /** * 列表项值 基类,必须有_id字段 */ interface BaseRecord extends Object { } /** * with _id as primary key */ interface MongoRecord extends BaseRecord { _id?: string; } /** * with id as primary key */ interface SqlRecord extends BaseRecord { id?: number; } declare const TreeCache: { /** * 返回通过path节点id路径,返回缓存中对应的元素数组 * @param shortKey cacheKey * @param posPath 节点id路径 * @param idKey 数组 数组中元素进行相等性比较时,用哪个字段,默认id,若元素的id相同,就认为两个元素相同 * @param childrenFieldName 存储父节点id信息的字符串,默认 children * @param storageType 缓存类型 */ getElementsByPathIdsInTreeFromCache: <T>(shortKey: string, posPath?: (string | number)[], idKey?: string, childrenFieldName?: string, storageType?: number, debug?: boolean) => T[] | undefined; getElementsByPathIdsInTree: <T_1>(array?: T_1[] | undefined, posPath?: (string | number)[], idKey?: string, childrenFieldName?: string, debug?: boolean) => T_1[] | undefined; /** * 从数组array中,根据children字段查找某节点e 返回路径的元素数组 * @param shortKey 存储数组都的cache key, 由其得到待查询的数组 * @param id 待查找的元素id * @param all 是否获取所有,否则只是第一个路径 * @param childrenFieldName 存储父节点id信息的字符串,默认 children * @param idKey 数组 数组中元素进行相等性比较时,用哪个字段,默认id,若元素的id相同,就认为两个元素相同 * @param storageType 缓存类型 * @returns 如果all为true(默认),返回所有path路径数组,否则返回path。 path是从根节点到所寻找叶子节点的数组 */ getPathFromTreeCacheKey: <T_2>(shortKey: string, id: string | number | undefined, all?: boolean, childrenFieldName?: string, idKey?: string, storageType?: number) => T_2[] | T_2[][] | undefined; getPathFromTree: <T_3>(array?: T_3[] | undefined, id?: string | number, all?: boolean, childrenFieldName?: string, idKey?: string) => T_3[] | T_3[][] | undefined; /** * 将数据插入到树上的一个节点中后,然后更新其缓存 * @param shortKey 缓存键 * @param e 待插入的数据 * @param parentPosPath 插入的数据元素e的父节点的路径节点id数组,即用于定位在哪个节点下插入e * @param updateRelation 更新亲子关系 避免对相关节点再次修改时,其亲子关系还是老旧数据,以及在插入子项前,对数据e的parent做一些操作,比如更新其parentPath * eg: currentRow.parentPath = [...parent.parentPath, currentRow[idKey]] * @param idKey 父路径数组元素中取值的key,通常为id * @param childrenFieldName tree节点的children字段名称,默认children * @param storageType * @param debug * @returns */ onAddOneInTreeCache: <T_4>(shortKey: string, e: T_4, parentPosPath: (string | number)[], updateRelation: (parent: T_4, e: T_4, parents: T_4[]) => void, idKey?: string, childrenFieldName?: string, storageType?: number, debug?: boolean) => boolean; /** * 将数据插入到树上的一个节点中后,然后更新treeArray * @param shortKey 缓存键 * @param e 待插入的数据 * @param parentPosPath 插入的数据元素e的父节点的路径节点id数组,即用于定位在哪个节点下插入e * @param treeArray * @param updateRelation 更新亲子关系 避免对相关节点再次修改时,其亲子关系还是老旧数据,以及在插入子项前,对数据e的parent做一些操作,比如更新其parentPath * eg: currentRow.parentPath = [...parent.parentPath, currentRow[idKey]] * @param idKey 父路径数组元素中取值的key,通常为id * @param childrenFieldName tree节点的children字段名称,默认children * @param debug * @returns */ onAddOneInTree: <T_5>(e: T_5, parentPosPath: (string | number)[], updateRelation: (parent: T_5, e: T_5, parents: T_5[]) => void, treeArray?: T_5[] | undefined, idKey?: string, childrenFieldName?: string) => boolean; /** * 修改某项的值后,更新其树形缓存 * @param shortKey 缓存键 * @param e 修改后的值 * @param posPath 数据元素e的id路径path,即指定了e的位置 * @param idKey 父路径数组元素中取值的key,通常为id * @param childrenFieldName tree节点的children字段名称,默认children * @param storageType * @param debug */ onEditOneInTreeCache: <T_6>(shortKey: string, e: T_6, posPath: (string | number)[], idKey?: string, childrenFieldName?: string, storageType?: number, debug?: boolean) => boolean; /** * 修改某项的值后,更新树形数据treeArray * @param e 修改后的值 * @param posPath 数据元素e的id路径path,即指定了e的位置 * @param treeArray 树形结构 * @param idKey 父路径数组元素中取值的key,通常为id * @param childrenFieldName tree节点的children字段名称,默认children * @param debug */ onEditOneInTree: <T_7>(e: T_7, posPath: (string | number)[], treeArray?: T_7[] | undefined, idKey?: string, childrenFieldName?: string, debug?: boolean) => boolean; /** * 从树形结构结构中删除某项,通过idPath指定该项位置,然后更新其缓存 * @param shortKey * @param e 待删除项 * @param posPath 待删除项数据元素e所在id路径 * @param updateRelation 更新亲子关系 避免对相关节点再次修改时,其亲子关系还是老旧数据 * @param idKey 删除比较时所采用的键,通常为id * @param childrenFieldName 树形结构中孩子名称,默认为children * @param storageType * @param debug log开关 * @returns */ onDelOneInTreeCache: <T_8>(shortKey: string, e: T_8, posPath: (string | number)[], updateRelation: (parent: T_8, e: T_8, parents: T_8[]) => void, idKey?: string, childrenFieldName?: string, storageType?: number, debug?: boolean) => boolean; /** * 从树形结构结构中删除某项,通过idPath指定该项位置,然后更新treeArray * @param e 待删除项 * @param posPath 待删除项数据元素e所在id路径 * @param updateRelation 更新亲子关系 避免对相关节点再次修改时,其亲子关系还是老旧数据 * @param treeArray 树形结构 * @param idKey 删除比较时所采用的键,通常为id * @param childrenFieldName 树形结构中孩子名称,默认为children * @param debug log开关 * @returns */ onDelOneInTree: <T_9>(e: T_9, posPath: (string | number)[], updateRelation: (parent: T_9, e: T_9, parents: T_9[]) => void, treeArray?: T_9[] | undefined, idKey?: string, childrenFieldName?: string, debug?: boolean) => boolean; }; /** * 数组工具,支持树形数组 */ declare const ArrayUtil: { /** * 数组array是否包含某个元素 * @param array * @param e */ contains: <T>(array?: T[] | undefined, e?: T | undefined, comparator?: ((e1: T, e2: T) => boolean) | undefined) => boolean; /** * 从数组中找一项 * @param array * @param id * @param idKey * @returns 成功返回该项 */ findOne: <T_1>(array?: T_1[] | undefined, id?: string | number, idKey?: string) => T_1 | undefined; /** * 从数组中找多项 * @param array * @param id * @param idKey * @returns 成功返回数组,要么有值,要么undefined,不返回空数组 */ findMany: <T_2>(array?: T_2[] | undefined, ids?: (string | number)[], idKey?: string) => T_2[] | undefined; /** * 从数组中移除一项 * @param array * @param id * @param idKey * @returns 成功返回true */ removeOne: <T_3>(array?: T_3[] | undefined, id?: string | number, idKey?: string) => boolean; /** * 从数组中移除多项 * @param array * @param id * @param idKey * @param storageType * @returns 有一个被删除就返回true */ removeMany: <T_4>(array?: T_4[] | undefined, ids?: (string | number)[], idKey?: string) => boolean; /** * 通过id path,在树形数组中找到各元素,以数组返回 * 不保证path长度与返回的数组长度一致 * @param tree 树形数组 * @param path 节点id数组,用于定位:根节点id->子节点id * @param idKey 数组 数组中元素进行相等性比较时,用哪个字段,默认id,若元素的id相同,就认为两个元素相同 * @param childrenFieldName 存储父节点id信息的字符串,默认 children * @param debug 是否打开日志输出 默认值UseCacheConfig.EnableLog */ getArrayByPathInTree: <T_5>(tree?: T_5[] | undefined, path?: (string | number)[], idKey?: string, childrenFieldName?: string, debug?: boolean) => T_5[] | undefined; /** * 通过id path,返回根节点,根节点及下面的children只保留搜索路径中的元素,其它的被去除,不影响原tree数据 * 可用于剪除其它无关枝丫 * @param tree 树形数组 * @param path 节点id数组,用于定位:根节点id->子节点id * @param idKey 数组 数组中元素进行相等性比较时,用哪个字段,默认id,若元素的id相同,就认为两个元素相同 * @param childrenFieldName 存储父节点id信息的字符串,默认 children * @param debug 是否打开日志输出 默认值UseCacheConfig.EnableLog */ trimTreeByPath: <T_6>(tree?: T_6[] | undefined, path?: (string | number)[], idKey?: string, childrenFieldName?: string, debug?: boolean) => T_6 | undefined; /** * 搜索id, 从树形数组tree中,找到第一条命中的数组 * @param tree 树形数组数组 * @param id 待查找的元素id * @param childrenFieldName 存储父节点id信息的字符串,默认 children * @param idKey 数组 数组中元素进行相等性比较时,用哪个字段,默认id,若元素的id相同,就认为两个元素相同 * @returns 返回数组:叶节点排最前,根节点最后 */ findOneFromTree: <T_7>(tree?: T_7[] | undefined, id?: string | number | undefined, childrenFieldName?: string, idKey?: string, debug?: boolean) => T_7[] | undefined; /** * 搜索id, 从树形数组rootArray中,找到所有命中路径数组, 结果存放在第一个参数resultPaths中 * @param resultPaths 最后结果保存在该数组中,返回多条路径,每条路径是从根元素到所寻找叶子节点元素的数组 * @param tree 数组 * @param id 待查找的元素id * @param childrenFieldName 存储父节点id信息的字符串,默认 children * @param idKey 数组 数组中元素进行相等性比较时,用哪个字段,默认id,若元素的id相同,就认为两个元素相同 * @param tempPath 临时变量,内部实现使用,不要传递 * @returns */ findAllFromTree: <T_8>(resultPaths: T_8[][], tree: T_8[], id?: string | number, childrenFieldName?: string, idKey?: string, tempPath?: T_8[]) => void; /** * 对tree进行变换,得到新tree,不影响原tree数据 * @param treeData * @param transform * @param childrenName * @param args * @returns */ transformTree: <T_9, R>(treeData: T_9[], transform: (e: T_9, args?: any) => R, childrenName?: string, args?: any) => R[]; /** * 对tree每个节点执行类似于forEach的遍历操作 * @param treeData * @param doSth * @param childrenName * @param args * @returns */ traverseTree: <T_10>(treeData: T_10[], doSth: (e: T_10, args?: any) => void, childrenName?: string, args?: any) => void; }; declare const DateTimeUtil: { dateFormat: (date: Date, fmt: string) => string; /** * 格式UTC时间 输出形如: 2019-12-02 08:09:04 * */ formatYearDateTime: (time?: number) => string; /** * 格式UTC时间 输出形如: 12-02 08:09:04 * */ formatDateTime: (time?: number) => string; /** * * @param time utc long time * @returns */ formatDate: (time?: number) => string; /** * TODO: 格式化 * @param duration 单位秒 */ formatDuration: (duration?: number, attachPrompt?: boolean, prefix?: string) => string; }; export { ArrayUtil, BasePageQuery, BaseRecord, CODE, Cache, CacheStorage, DataBox, DataBoxBase, DataBoxTableList, DateTimeUtil, FetchParams, MongoRecord, QueryPagination, SqlRecord, StorageType, TreeCache, UseCacheConfig, cachedFetch, cachedFetchPromise, cachedGet, cachedPost, currentHref, deepCopy, defaultFetchParams, encodeUmi, getDataFromBox, query2Params, serializeObject, useCache, useCacheList };