@zero-library/common 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1527 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.css +120 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +356 -0
- package/dist/index.d.ts +356 -0
- package/dist/index.esm.js +1402 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +78 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import dayjs from 'dayjs';
|
|
5
|
+
import Decimal from 'decimal.js';
|
|
6
|
+
import { ResponseType } from 'axios';
|
|
7
|
+
import { ThemeConfig } from 'antd/lib';
|
|
8
|
+
|
|
9
|
+
interface Props$9 {
|
|
10
|
+
fileUrl: string;
|
|
11
|
+
}
|
|
12
|
+
declare const _default$b: ({ fileUrl }: Props$9) => react_jsx_runtime.JSX.Element;
|
|
13
|
+
|
|
14
|
+
interface Props$8 {
|
|
15
|
+
suffix?: string;
|
|
16
|
+
fontSize?: number;
|
|
17
|
+
}
|
|
18
|
+
declare const _default$a: ({ suffix, fontSize }: Props$8) => react_jsx_runtime.JSX.Element;
|
|
19
|
+
|
|
20
|
+
interface Props$7 {
|
|
21
|
+
fileUrl: string;
|
|
22
|
+
suffix?: string;
|
|
23
|
+
password?: string;
|
|
24
|
+
searchValue?: string;
|
|
25
|
+
pdfParams?: {
|
|
26
|
+
pageNo?: number;
|
|
27
|
+
scale?: number;
|
|
28
|
+
isHasThumbnails?: boolean;
|
|
29
|
+
onSetPageNo?: (pageNo: number) => void;
|
|
30
|
+
};
|
|
31
|
+
fileParams?: ObjectType<string>;
|
|
32
|
+
onSetPassSuccess?: () => void;
|
|
33
|
+
}
|
|
34
|
+
declare const _default$9: ({ suffix, fileUrl, pdfParams, password, searchValue }: Props$7) => react_jsx_runtime.JSX.Element;
|
|
35
|
+
|
|
36
|
+
interface Props$6 {
|
|
37
|
+
open: boolean;
|
|
38
|
+
onClose: () => void;
|
|
39
|
+
title?: string;
|
|
40
|
+
fileUrl: string;
|
|
41
|
+
suffix?: string;
|
|
42
|
+
password?: string;
|
|
43
|
+
fileParams?: ObjectType<string>;
|
|
44
|
+
pdfParams?: {
|
|
45
|
+
pageNo?: number;
|
|
46
|
+
scale?: number;
|
|
47
|
+
isHasThumbnails?: boolean;
|
|
48
|
+
onSetPageNo?: (pageNo: number) => void;
|
|
49
|
+
};
|
|
50
|
+
onSetPassSuccess?: () => void;
|
|
51
|
+
}
|
|
52
|
+
declare const _default$8: ({ open, fileUrl, suffix, title, onClose, password, fileParams, pdfParams, onSetPassSuccess }: Props$6) => react_jsx_runtime.JSX.Element;
|
|
53
|
+
|
|
54
|
+
interface Props$5 {
|
|
55
|
+
fileUrl: string;
|
|
56
|
+
searchValue?: string;
|
|
57
|
+
}
|
|
58
|
+
declare const _default$7: ({ fileUrl, searchValue }: Props$5) => react_jsx_runtime.JSX.Element;
|
|
59
|
+
|
|
60
|
+
interface Props$4 {
|
|
61
|
+
fileUrl: string;
|
|
62
|
+
pageNo?: number;
|
|
63
|
+
scale?: number;
|
|
64
|
+
isHasThumbnails?: boolean;
|
|
65
|
+
password?: string;
|
|
66
|
+
onSetPassword?: (password: string) => void;
|
|
67
|
+
onSetPageNo?: (pageNo: number) => void;
|
|
68
|
+
}
|
|
69
|
+
declare const _default$6: ({ password, fileUrl, pageNo, scale, isHasThumbnails, onSetPassword, onSetPageNo }: Props$4) => react_jsx_runtime.JSX.Element;
|
|
70
|
+
|
|
71
|
+
interface Props$3 {
|
|
72
|
+
fileUrl: string;
|
|
73
|
+
}
|
|
74
|
+
declare const _default$5: ({ fileUrl }: Props$3) => react_jsx_runtime.JSX.Element;
|
|
75
|
+
|
|
76
|
+
interface IframeProps {
|
|
77
|
+
id?: string;
|
|
78
|
+
src: string;
|
|
79
|
+
className?: string;
|
|
80
|
+
onLoad?: () => void;
|
|
81
|
+
}
|
|
82
|
+
declare const _default$4: react.ForwardRefExoticComponent<IframeProps & react.RefAttributes<HTMLIFrameElement>>;
|
|
83
|
+
|
|
84
|
+
type ComponentMapType = Record<string, () => Promise<{
|
|
85
|
+
default: React.ComponentType<any>;
|
|
86
|
+
}>>;
|
|
87
|
+
type Props$2 = {
|
|
88
|
+
type: string;
|
|
89
|
+
customComponents?: ComponentMapType;
|
|
90
|
+
[key: string]: any;
|
|
91
|
+
};
|
|
92
|
+
declare const _default$3: ({ type, customComponents, ...rest }: Props$2) => react_jsx_runtime.JSX.Element;
|
|
93
|
+
|
|
94
|
+
interface Props$1 {
|
|
95
|
+
content?: string;
|
|
96
|
+
searchValue?: string;
|
|
97
|
+
customComponents?: ComponentMapType;
|
|
98
|
+
onChange?: (value: string) => void;
|
|
99
|
+
onPartialChange?: (oldValue: string, newValue: string) => void;
|
|
100
|
+
}
|
|
101
|
+
declare const _default$2: ({ content, searchValue, customComponents, onChange, onPartialChange }: Props$1) => react_jsx_runtime.JSX.Element;
|
|
102
|
+
|
|
103
|
+
type RenderControl<C, P = ObjectType<any>> = boolean | {
|
|
104
|
+
visible?: boolean;
|
|
105
|
+
render?: (ctx: C) => React.ReactNode;
|
|
106
|
+
props?: P;
|
|
107
|
+
};
|
|
108
|
+
interface RenderWrapperProps<C, P> {
|
|
109
|
+
control?: RenderControl<C, P> | null;
|
|
110
|
+
ctx?: C;
|
|
111
|
+
DefaultComponent?: React.ReactNode | ((props: P) => React.ReactNode);
|
|
112
|
+
}
|
|
113
|
+
declare function RenderWrapper<C = any, P = any>({ control, ctx, DefaultComponent }: RenderWrapperProps<C, P>): string | number | boolean | react_jsx_runtime.JSX.Element | Iterable<react.ReactNode>;
|
|
114
|
+
declare const shouldRender: (control?: RenderControl<any, any> | null) => boolean;
|
|
115
|
+
declare function propsMerge(control?: RenderControl<any, any> | null, props?: ObjectType<any>): {
|
|
116
|
+
props: any;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
interface Props {
|
|
120
|
+
avatarSrc?: string;
|
|
121
|
+
userName?: string;
|
|
122
|
+
size?: number;
|
|
123
|
+
}
|
|
124
|
+
declare const _default$1: ({ size, avatarSrc, userName }: Props) => react_jsx_runtime.JSX.Element;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 通用的 Valtio Context 工厂
|
|
128
|
+
* 支持:
|
|
129
|
+
* - useStore() 获取 store 实例
|
|
130
|
+
*/
|
|
131
|
+
declare function createValtioContext<T extends object>(): {
|
|
132
|
+
ValtioProvider: ({ store, children }: {
|
|
133
|
+
store: T;
|
|
134
|
+
children?: ReactNode;
|
|
135
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
136
|
+
useValtioStore: () => T;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
type Params = Record<string, any>;
|
|
140
|
+
/**
|
|
141
|
+
* 通知当前页面的父页面或者顶级窗口
|
|
142
|
+
*/
|
|
143
|
+
declare function emit(type: string, data?: Params, to?: 'parent' | 'top'): void;
|
|
144
|
+
/**
|
|
145
|
+
* 通知某个子 iframe 窗口(必须传入 iframe.contentWindow)
|
|
146
|
+
*/
|
|
147
|
+
declare function emitToChild(iframeWindow: Window | null, type: string, data?: Params, origin?: string): void;
|
|
148
|
+
|
|
149
|
+
type Handler<P = Params> = (params: P, source?: MessageEventSource | null, origin?: string) => void;
|
|
150
|
+
declare function useIframeRelayBridge(allowedOrigins?: string[]): {
|
|
151
|
+
on: (type: string, handler: Handler<Params>) => void;
|
|
152
|
+
off: (type: string, handler: Handler<Params>) => void;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 防抖hook
|
|
157
|
+
* @param func 需要执行的函数
|
|
158
|
+
* @param wait 延迟时间
|
|
159
|
+
*/
|
|
160
|
+
declare function useDebounce<A extends Array<any>, R = void>(func: (..._args: A) => R, wait?: number): {
|
|
161
|
+
(..._args: A): Promise<R>;
|
|
162
|
+
flush: () => any;
|
|
163
|
+
cancel: () => void;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* useDeepEffect
|
|
168
|
+
* 深层对比依赖项的 useEffect
|
|
169
|
+
*/
|
|
170
|
+
declare function useDeepEffect(effect: React.EffectCallback, deps: any[]): void;
|
|
171
|
+
|
|
172
|
+
declare function useRefState<T>(init: T): readonly [T, (newVal: T) => void, () => T];
|
|
173
|
+
|
|
174
|
+
declare const useSyncInput: <T>(storeValue: T, setStoreValue: (value: T) => void) => {
|
|
175
|
+
inputValue: T;
|
|
176
|
+
setInputValue: (value: T) => void;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 节流hook
|
|
181
|
+
* @param func 需要执行的函数
|
|
182
|
+
* @param wait 延迟时间
|
|
183
|
+
*/
|
|
184
|
+
declare function useThrottle<A extends Array<any>, R = void>(func: (..._args: A) => R, wait: number): {
|
|
185
|
+
(..._args: A): Promise<R>;
|
|
186
|
+
flush: () => any;
|
|
187
|
+
cancel: () => void;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
interface UseWebSocketParams {
|
|
191
|
+
url: string;
|
|
192
|
+
onMessage: (message: any) => void;
|
|
193
|
+
onClose?: () => void;
|
|
194
|
+
heartbeatInterval?: number;
|
|
195
|
+
heartbeatMessage?: string;
|
|
196
|
+
clientHeartbeat?: boolean;
|
|
197
|
+
reconnectInterval?: number;
|
|
198
|
+
maxReconnectAttempts?: number;
|
|
199
|
+
isReconnect?: boolean;
|
|
200
|
+
}
|
|
201
|
+
interface UseWebSocketReturn {
|
|
202
|
+
sendMessage: (message: string) => void;
|
|
203
|
+
socketReadyState: number | null;
|
|
204
|
+
}
|
|
205
|
+
declare const useWebSocket: ({ url, onMessage, onClose, heartbeatInterval, heartbeatMessage, clientHeartbeat, reconnectInterval, maxReconnectAttempts, isReconnect }: UseWebSocketParams) => UseWebSocketReturn;
|
|
206
|
+
|
|
207
|
+
declare const deepCopy: <T>(arg: T, isJson?: boolean) => T;
|
|
208
|
+
declare function deepEqual(a: any, b: any): boolean;
|
|
209
|
+
declare const deepMerge: <T extends Record<string, any>>(base: T, override: Partial<T>) => T;
|
|
210
|
+
declare const objToOptions: (obj: ObjectType<string>) => {
|
|
211
|
+
label: string;
|
|
212
|
+
value: number;
|
|
213
|
+
}[];
|
|
214
|
+
declare const arrToObj: <T>(arr: T[], key: string) => {
|
|
215
|
+
[key: string]: T;
|
|
216
|
+
};
|
|
217
|
+
interface NsSetIntervalReturnType {
|
|
218
|
+
isRun: () => boolean;
|
|
219
|
+
cancel: () => void;
|
|
220
|
+
}
|
|
221
|
+
declare const nsSetInterval: (fn: () => void, t: number) => NsSetIntervalReturnType;
|
|
222
|
+
declare const genNonDuplicateID: () => string;
|
|
223
|
+
declare const copyText: (text: string) => Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* 把后台接口字段,返回的关于金额的数字,转换为千分符号分隔的数字
|
|
226
|
+
* return string
|
|
227
|
+
*/
|
|
228
|
+
declare function formatNumberWithCommas(number: number | string): string | number;
|
|
229
|
+
declare const generateRandomNumbers: (min: number, max: number, count: number) => number[];
|
|
230
|
+
declare const getFileName: (filePath: string) => string;
|
|
231
|
+
declare const textAreaView: (con?: string) => string;
|
|
232
|
+
/**
|
|
233
|
+
* 将对象转换为 URL 查询参数字符串
|
|
234
|
+
* @param obj - 要转换的对象
|
|
235
|
+
* @param url - 要拼接的 URL,如果未提供,则返回查询参数字符串
|
|
236
|
+
* @returns URL 查询参数字符串
|
|
237
|
+
*/
|
|
238
|
+
declare const buildUrlParams: (obj: Record<string, any>, url?: string) => string;
|
|
239
|
+
declare const downloadFile: (url: string, name?: string) => void;
|
|
240
|
+
/**
|
|
241
|
+
* 给URL路径最后加/
|
|
242
|
+
*/
|
|
243
|
+
declare const addUrlLastSlash: (url?: string) => string;
|
|
244
|
+
/**
|
|
245
|
+
* 给url增加mainSource参数
|
|
246
|
+
*/
|
|
247
|
+
declare const getUrlMainSource: (url: string, preHref?: string) => string;
|
|
248
|
+
/**
|
|
249
|
+
* 获取 WebSocket 地址
|
|
250
|
+
* @param path WebSocket 服务路径,比如 "/ws" 或 "/socket"
|
|
251
|
+
* @param customHost 可选,指定 host:port;默认取当前 window.location.host
|
|
252
|
+
*/
|
|
253
|
+
declare const getWebSocketUrl: (path: string, customHost?: string) => string;
|
|
254
|
+
|
|
255
|
+
type DateType = string | number | Date | dayjs.Dayjs | null;
|
|
256
|
+
declare const DateFormatType = "YYYY-MM-DD HH:mm:ss";
|
|
257
|
+
declare const DateFormatType2 = "YYYY-MM-DD";
|
|
258
|
+
/**
|
|
259
|
+
* 获取一天的最早时间 '2023/10/17 00:00:00' 的时间戳
|
|
260
|
+
*/
|
|
261
|
+
declare const getStartOfTimestamp: (date?: DateType, unit?: dayjs.OpUnitType) => number;
|
|
262
|
+
/**
|
|
263
|
+
* 获取一天的最晚时间 '2023/10/17 23:59:59' 的时间戳
|
|
264
|
+
*/
|
|
265
|
+
declare const getEndOfTimestamp: (date?: DateType, unit?: dayjs.OpUnitType) => number;
|
|
266
|
+
declare const formatDate: (date: Date | number | string, fmt?: string) => string;
|
|
267
|
+
declare const getTimestamp: (date?: DateType) => number;
|
|
268
|
+
declare const isExpire: (date?: DateType) => boolean;
|
|
269
|
+
|
|
270
|
+
declare function is(val: unknown, type: string): boolean;
|
|
271
|
+
declare function isUnDef<T = unknown>(val?: T): val is T;
|
|
272
|
+
declare function isDef<T = unknown>(val?: T): val is T;
|
|
273
|
+
declare function isObject(val: any): val is Record<any, any>;
|
|
274
|
+
declare function isEmptyObj<T = unknown>(val: T): boolean;
|
|
275
|
+
declare function isDate(val: unknown): val is Date;
|
|
276
|
+
declare function isNull(val: unknown): val is null;
|
|
277
|
+
declare function isNullOrUnDef(val: unknown): val is null | undefined;
|
|
278
|
+
declare function isNumber(val: unknown): val is number;
|
|
279
|
+
declare function isNumberNoNaN(val: unknown): val is number;
|
|
280
|
+
declare function isString(val: unknown): val is string;
|
|
281
|
+
declare function isFunction(val: unknown): boolean;
|
|
282
|
+
declare function isPromise<T = any>(val: unknown): val is Promise<T>;
|
|
283
|
+
declare function isBoolean(val: unknown): val is boolean;
|
|
284
|
+
declare function isRegExp(val: unknown): val is RegExp;
|
|
285
|
+
declare function isArray(val: any): val is Array<any>;
|
|
286
|
+
declare function isEmpty<T = unknown>(val: T): val is T;
|
|
287
|
+
declare function isWindow(val: any): val is Window;
|
|
288
|
+
declare function isElement(val: unknown): val is Element;
|
|
289
|
+
declare function isMap(val: unknown): val is Map<any, any>;
|
|
290
|
+
declare const isServer: boolean;
|
|
291
|
+
declare const isClient: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* 判断是否是外链
|
|
294
|
+
* @param {string} path
|
|
295
|
+
* @returns {Boolean}
|
|
296
|
+
* @author LiQingSong
|
|
297
|
+
*/
|
|
298
|
+
declare const isExternal: (path: string) => boolean;
|
|
299
|
+
declare const isBlob: (val: unknown) => boolean;
|
|
300
|
+
|
|
301
|
+
declare function setCurrentUser(userInfo: any): void;
|
|
302
|
+
declare function getCurrentUser(): any;
|
|
303
|
+
declare function clearCurrentUser(): void;
|
|
304
|
+
declare function getDeviceId(): string;
|
|
305
|
+
|
|
306
|
+
type OperatorType = '+' | '-' | '*' | '/';
|
|
307
|
+
declare const calculate: (operator: OperatorType, ...args: Decimal.Value[]) => string;
|
|
308
|
+
declare const plus: (...args: Decimal.Value[]) => string;
|
|
309
|
+
declare const minus: (...args: Decimal.Value[]) => string;
|
|
310
|
+
declare const times: (...args: Decimal.Value[]) => string;
|
|
311
|
+
declare const dividedBy: (...args: Decimal.Value[]) => string;
|
|
312
|
+
declare const decimalPlaces: (arg1: Decimal.Value) => number;
|
|
313
|
+
declare const precision: (arg1: Decimal.Value) => number;
|
|
314
|
+
declare const absVal: (arg1: Decimal.Value) => string;
|
|
315
|
+
declare const compareNum: (arg1: Decimal.Value, arg2: Decimal.Value, type: string) => boolean;
|
|
316
|
+
declare const toFixed: (num: Decimal.Value, decimals?: number, fill?: boolean) => string;
|
|
317
|
+
declare const isInteger: (num: Decimal.Value) => boolean;
|
|
318
|
+
declare const isNegative: (num: Decimal.Value) => boolean;
|
|
319
|
+
|
|
320
|
+
declare const OK = 200;
|
|
321
|
+
declare const OK2 = "S0000";
|
|
322
|
+
declare const ERROR = 500;
|
|
323
|
+
declare const MISSING_PARAMETER = 400;
|
|
324
|
+
declare const UNAUTHORIZED = 401;
|
|
325
|
+
declare const FORBIDDEN = 403;
|
|
326
|
+
declare const NOT_FOUND = 404;
|
|
327
|
+
declare const ILLEGAL_PARAMETER = 901;
|
|
328
|
+
declare const PERMISSION_DENIED = 13001;
|
|
329
|
+
declare const LoginPastCode = 11200;
|
|
330
|
+
declare const FacePastCode = 11201;
|
|
331
|
+
declare const formType = "form";
|
|
332
|
+
declare const jsonType = "json";
|
|
333
|
+
interface Options {
|
|
334
|
+
reqType?: 'json' | 'form';
|
|
335
|
+
timeout?: number;
|
|
336
|
+
responseType?: ResponseType;
|
|
337
|
+
showError?: boolean;
|
|
338
|
+
}
|
|
339
|
+
declare const _default: {
|
|
340
|
+
get: (url: string, params?: any, options?: Options) => Promise<any>;
|
|
341
|
+
post: (url: string, data?: any, options?: Options) => Promise<any>;
|
|
342
|
+
put: (url: string, data?: any, options?: Options) => Promise<any>;
|
|
343
|
+
delete: (url: string, data?: any, options?: Options) => Promise<any>;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
declare const TOKEN_KEY = "NS-TOKEN";
|
|
347
|
+
declare function setToken(accessToken: string): void;
|
|
348
|
+
declare function getUrlToken(): string;
|
|
349
|
+
declare function getToken(): string;
|
|
350
|
+
declare function clearToken(): void;
|
|
351
|
+
declare function getSignPath(): string;
|
|
352
|
+
|
|
353
|
+
declare const LgPrimaryColor: string;
|
|
354
|
+
declare const themeConfig: ThemeConfig;
|
|
355
|
+
|
|
356
|
+
export { _default$b as AudioPlayer, DateFormatType, DateFormatType2, ERROR, FORBIDDEN, FacePastCode, _default$a as FileIcon, _default$9 as FilePreview, _default$8 as FilePreviewDrawer, ILLEGAL_PARAMETER, _default$4 as Iframe, _default$3 as LazyComponent, LgPrimaryColor, LoginPastCode, MISSING_PARAMETER, _default$7 as MarkdownPreview, NOT_FOUND, type NsSetIntervalReturnType, OK, OK2, PERMISSION_DENIED, type Params, _default$6 as PdfPreview, type RenderControl, _default$2 as RenderMarkdown, RenderWrapper, TOKEN_KEY, UNAUTHORIZED, _default$1 as UserAvatar, _default$5 as VideoPlayer, absVal, addUrlLastSlash, arrToObj, buildUrlParams, calculate, clearCurrentUser, clearToken, compareNum, copyText, createValtioContext, decimalPlaces, deepCopy, deepEqual, deepMerge, dividedBy, downloadFile, emit, emitToChild, formType, formatDate, formatNumberWithCommas, genNonDuplicateID, generateRandomNumbers, getCurrentUser, getDeviceId, getEndOfTimestamp, getFileName, getSignPath, getStartOfTimestamp, getTimestamp, getToken, getUrlMainSource, getUrlToken, getWebSocketUrl, is, isArray, isBlob, isBoolean, isClient, isDate, isDef, isElement, isEmpty, isEmptyObj, isExpire, isExternal, isFunction, isInteger, isMap, isNegative, isNull, isNullOrUnDef, isNumber, isNumberNoNaN, isObject, isPromise, isRegExp, isServer, isString, isUnDef, isWindow, jsonType, minus, nsSetInterval, objToOptions, plus, precision, propsMerge, _default as request, setCurrentUser, setToken, shouldRender, textAreaView, themeConfig, times, toFixed, useDebounce, useDeepEffect, useIframeRelayBridge, useRefState, useSyncInput, useThrottle, useWebSocket };
|