@hzab/utils 1.1.6 → 1.1.7
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/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/dist/index.cjs +1532 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +741 -0
- package/dist/index.d.ts +741 -0
- package/dist/index.js +1423 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -49
- package/src/color.ts +8 -8
- package/src/file/file.ts +4 -3
- package/src/file/fileType.ts +1 -1
- package/src/formily/field.ts +142 -0
- package/src/global.d.ts +9 -0
- package/src/idCardVerify.ts +1 -1
- package/src/img-utils.ts +9 -9
- package/src/index.ts +43 -0
- package/src/nanoid.ts +19 -19
- package/src/options.ts +248 -226
- package/src/upload/OfflineUpload.ts +2 -2
- package/src/upload/OssUploadUtil.ts +1 -1
- package/src/upload/fileDataNormalization.ts +3 -3
- package/src/upload/ossUpload.ts +2 -1
- package/src/url.ts +181 -155
- package/README.md +0 -137
- package/changelog.md +0 -56
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取数组格式数据
|
|
3
|
+
* @param value
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
declare function getArr(value: any): any[];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 是否是 base64 字符串
|
|
10
|
+
* @param {*} str
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
declare const isBase64Str: (str: any) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 从 base64 字符串获取文件类型
|
|
16
|
+
* @param base64Str
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
declare function getFileTypeFromBase64(base64Str: any): any;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 通过 Blob 的文件签名判断文件类型
|
|
23
|
+
* @param {Blob} blob - 待检测的 Blob 对象
|
|
24
|
+
* @returns {Promise<string>} - 匹配的 MIME 类型或 'unknown'
|
|
25
|
+
*/
|
|
26
|
+
declare function getFileTypeFromBlob(blob: Blob): Promise<string>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 计算颜色的亮度
|
|
30
|
+
* @param r
|
|
31
|
+
* @param g
|
|
32
|
+
* @param b
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
declare function luminance(r: any, g: any, b: any): number;
|
|
36
|
+
/**
|
|
37
|
+
* 计算两个颜色之间的对比度
|
|
38
|
+
* @param l1
|
|
39
|
+
* @param l2
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
declare function contrast(l1: any, l2: any): number;
|
|
43
|
+
/**
|
|
44
|
+
* 计算对比度
|
|
45
|
+
* @param luminance1
|
|
46
|
+
* @param luminance2
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
declare function contrastRatio(luminance1: any, luminance2: any): number;
|
|
50
|
+
/**
|
|
51
|
+
* 十六进制颜色转 RGB
|
|
52
|
+
* @param hex
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
declare function hexToRGB(hex: any): number[];
|
|
56
|
+
/**
|
|
57
|
+
* rgb 数值限制
|
|
58
|
+
* @param val
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
declare function rgbNumLimit(val: any): any;
|
|
62
|
+
/**
|
|
63
|
+
* RGB 转十六进制颜色
|
|
64
|
+
* @param r
|
|
65
|
+
* @param g
|
|
66
|
+
* @param b
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
declare function rgbToHex(r: any, g: any, b: any): string;
|
|
70
|
+
/**
|
|
71
|
+
* RGB 转 HSL
|
|
72
|
+
* @param r
|
|
73
|
+
* @param g
|
|
74
|
+
* @param b
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
declare function rgbToHsl(r: any, g: any, b: any): number[];
|
|
78
|
+
/**
|
|
79
|
+
* HSL 转 RGB
|
|
80
|
+
* @param h
|
|
81
|
+
* @param s
|
|
82
|
+
* @param l
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
declare function hslToRgb(h: any, s: any, l: any): number[];
|
|
86
|
+
/**
|
|
87
|
+
* 判断是否为灰色背景
|
|
88
|
+
* @param r
|
|
89
|
+
* @param g
|
|
90
|
+
* @param b
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
declare function isGray(r: any, g: any, b: any, opt?: {
|
|
94
|
+
tolerance: number;
|
|
95
|
+
}): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* 根据背景颜色选择合适的文本颜色(十六进制格式)
|
|
98
|
+
* @param backgroundColor
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
declare function getTextColor(backgroundColor: any): "#ffffff" | "#000000";
|
|
102
|
+
/**
|
|
103
|
+
* 根据背景亮度调整文字颜色深浅
|
|
104
|
+
* @param bgR
|
|
105
|
+
* @param bgG
|
|
106
|
+
* @param bgB
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
declare function adjustTextColor(hexColor: any): string;
|
|
110
|
+
/**
|
|
111
|
+
* 调整颜色深浅
|
|
112
|
+
* @param hexColor
|
|
113
|
+
* @param amount
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
declare function adjustColor(hexColor: any, amount: any): string;
|
|
117
|
+
|
|
118
|
+
interface ICheckEmptyOpt {
|
|
119
|
+
/** 【废弃】空值占位符 */
|
|
120
|
+
emptyStr?: string;
|
|
121
|
+
/** 空值占位符 */
|
|
122
|
+
emptySymbol?: string;
|
|
123
|
+
checkEmptyArr?: boolean;
|
|
124
|
+
}
|
|
125
|
+
interface IHandleEmptyValOpt extends ICheckEmptyOpt {
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 空数据判断
|
|
129
|
+
* @param {*} val
|
|
130
|
+
* @param {*} opt
|
|
131
|
+
* @returns
|
|
132
|
+
*/
|
|
133
|
+
declare function checkEmpty(val: any, opt?: ICheckEmptyOpt): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* 处理空数据显示占位符
|
|
136
|
+
* @param val
|
|
137
|
+
* @param opt
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
declare const handleEmptyVal: (val: any, opt?: IHandleEmptyValOpt) => any;
|
|
141
|
+
|
|
142
|
+
/** 获取全局配置(url、是否显示缩略图地址) */
|
|
143
|
+
declare function getGlobalServeConfig(): Record<string, any>;
|
|
144
|
+
/** 设置全局配置(url、是否显示缩略图地址)*/
|
|
145
|
+
declare function setGlobalServeConfigs(data: any): Record<string, any>;
|
|
146
|
+
/** 设置全局单个配置(url、是否显示缩略图地址)*/
|
|
147
|
+
declare function setGlobalServeConfig(key: any, data: any): Record<string, any>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 身份证号码合法性校验
|
|
151
|
+
* @param {string} idCard 身份证号码
|
|
152
|
+
* @param {Object} opt 校验选项
|
|
153
|
+
* @param {boolean} opt.validBirthDate 是否校验出生日期
|
|
154
|
+
* @returns {boolean} 是否合法
|
|
155
|
+
*/
|
|
156
|
+
declare function isValidIdCard(idCard: any, opt?: any): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* 校验出生日期是否合法且在一定范围内
|
|
159
|
+
* @param {string} id18 18位身份证号码
|
|
160
|
+
* @returns {boolean} 出生日期是否合法
|
|
161
|
+
*/
|
|
162
|
+
declare function isValidBirthDate(id18: any): boolean;
|
|
163
|
+
/**
|
|
164
|
+
* 获取指定月份的天数
|
|
165
|
+
* @param {number} year 年份
|
|
166
|
+
* @param {number} month 月份(1-12)
|
|
167
|
+
* @returns {number} 该月的天数
|
|
168
|
+
*/
|
|
169
|
+
declare function getDaysInMonth(year: any, month: any): number;
|
|
170
|
+
/**
|
|
171
|
+
* 15位身份证转18位
|
|
172
|
+
* @param {string} id15 15位身份证号码
|
|
173
|
+
* @returns {string} 18位身份证号码
|
|
174
|
+
*/
|
|
175
|
+
declare function convert15to18(id15: any): string;
|
|
176
|
+
/**
|
|
177
|
+
* 计算18位身份证的校验码
|
|
178
|
+
* @param {string} id17 身份证前17位
|
|
179
|
+
* @returns {string} 校验码(0-9或X)
|
|
180
|
+
*/
|
|
181
|
+
declare function calculateCheckCode(id17: any): string;
|
|
182
|
+
/**
|
|
183
|
+
* 校验18位身份证的校验码
|
|
184
|
+
* @param {string} id18 18位身份证号码
|
|
185
|
+
* @returns {boolean} 校验码是否正确
|
|
186
|
+
*/
|
|
187
|
+
declare function verifyCheckCode(id18: any): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* 计算年龄
|
|
190
|
+
* @param {number} year 出生年份
|
|
191
|
+
* @param {number} month 出生月份
|
|
192
|
+
* @param {number} day 出生日期
|
|
193
|
+
* @returns {number} 年龄
|
|
194
|
+
*/
|
|
195
|
+
declare function calculateAge(year: any, month: any, day: any): number;
|
|
196
|
+
/**
|
|
197
|
+
* 获取身份证详细信息
|
|
198
|
+
* @param {string} idCard 身份证号码
|
|
199
|
+
* @returns {object|null} 详细信息对象,校验失败返回null
|
|
200
|
+
*/
|
|
201
|
+
declare function getIdCardInfo(idCard: any): {
|
|
202
|
+
province: any;
|
|
203
|
+
birthDate: Date;
|
|
204
|
+
birthYear: number;
|
|
205
|
+
birthMonth: number;
|
|
206
|
+
birthDay: number;
|
|
207
|
+
age: number;
|
|
208
|
+
gender: string;
|
|
209
|
+
isValid: boolean;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
declare class IMAGE_TYPES {
|
|
213
|
+
static JPEG: string;
|
|
214
|
+
static PNG: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* 检测空图片
|
|
218
|
+
* @param img
|
|
219
|
+
* @returns
|
|
220
|
+
*/
|
|
221
|
+
declare function checkEmptyImg(img: HTMLImageElement): boolean;
|
|
222
|
+
/**
|
|
223
|
+
* 获取dom元素宽高
|
|
224
|
+
* @param d dom元素
|
|
225
|
+
* @returns {{width: number, height: number}}
|
|
226
|
+
*/
|
|
227
|
+
declare function getDomWH(d: HTMLElement | HTMLImageElement | HTMLCanvasElement): {
|
|
228
|
+
width: number;
|
|
229
|
+
height: number;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* 设置dom元素宽高
|
|
233
|
+
* @param d dom元素
|
|
234
|
+
* @param w 宽
|
|
235
|
+
* @param h 高
|
|
236
|
+
*/
|
|
237
|
+
declare function setDomWH(dom: HTMLElement, w: number, h: number): void;
|
|
238
|
+
/**
|
|
239
|
+
* 获取当前 canvas 图片 Blob 对象
|
|
240
|
+
* @param canvas
|
|
241
|
+
* @returns {Promise<Blob>}
|
|
242
|
+
*/
|
|
243
|
+
declare function getCanvasPic(canvas: HTMLCanvasElement): Blob;
|
|
244
|
+
/**
|
|
245
|
+
* base64 字符串转 blob
|
|
246
|
+
* @param base64
|
|
247
|
+
* @returns
|
|
248
|
+
*/
|
|
249
|
+
declare function dataURItoBlob(base64: string): Blob;
|
|
250
|
+
/**
|
|
251
|
+
* 获取图片元素
|
|
252
|
+
* @param imgSrc
|
|
253
|
+
* @returns
|
|
254
|
+
*/
|
|
255
|
+
declare function getImgEle(imgSrc: string): Promise<HTMLImageElement>;
|
|
256
|
+
/**
|
|
257
|
+
* 获取图片 Base64 字符串
|
|
258
|
+
* @param imgSrc
|
|
259
|
+
* @returns
|
|
260
|
+
*/
|
|
261
|
+
declare function getImgBase64(imgSrc: string): Promise<string>;
|
|
262
|
+
/**
|
|
263
|
+
* 通过图片地址获取对应 canvas
|
|
264
|
+
* @param imgSrc
|
|
265
|
+
* @returns
|
|
266
|
+
*/
|
|
267
|
+
declare function getCanvas(imgSrc: string): Promise<HTMLCanvasElement>;
|
|
268
|
+
/**
|
|
269
|
+
* 通过图片地址获取对应 canvas
|
|
270
|
+
* @param img
|
|
271
|
+
* @returns
|
|
272
|
+
*/
|
|
273
|
+
declare function getCanvasByImg(img: HTMLImageElement): HTMLCanvasElement;
|
|
274
|
+
/**
|
|
275
|
+
* 截取图片
|
|
276
|
+
* @param img
|
|
277
|
+
* @param opt
|
|
278
|
+
* @param opt.startX
|
|
279
|
+
* @param opt.startY
|
|
280
|
+
* @param opt.width
|
|
281
|
+
* @param opt.height
|
|
282
|
+
* @returns Promise<string>
|
|
283
|
+
*/
|
|
284
|
+
declare function cropImage(img: HTMLImageElement | HTMLCanvasElement, opt: {
|
|
285
|
+
startX: number;
|
|
286
|
+
startY: number;
|
|
287
|
+
width: number;
|
|
288
|
+
height: number;
|
|
289
|
+
}): string;
|
|
290
|
+
/**
|
|
291
|
+
* 截取图片
|
|
292
|
+
* @param img
|
|
293
|
+
* @param opt
|
|
294
|
+
* @param opt.startX
|
|
295
|
+
* @param opt.startY
|
|
296
|
+
* @param opt.width
|
|
297
|
+
* @param opt.height
|
|
298
|
+
* @returns Promise<HTMLCanvasElement>
|
|
299
|
+
*/
|
|
300
|
+
declare function cropImageToCanvas(img: HTMLImageElement | HTMLCanvasElement, opt: {
|
|
301
|
+
startX: number;
|
|
302
|
+
startY: number;
|
|
303
|
+
width: number;
|
|
304
|
+
height: number;
|
|
305
|
+
}): HTMLCanvasElement;
|
|
306
|
+
/**
|
|
307
|
+
* 绘制图片
|
|
308
|
+
* @param img
|
|
309
|
+
* @param opt
|
|
310
|
+
* @param opt.startX
|
|
311
|
+
* @param opt.startY
|
|
312
|
+
* @param opt.width
|
|
313
|
+
* @param opt.height
|
|
314
|
+
* @returns Promise<string>
|
|
315
|
+
*/
|
|
316
|
+
declare function imgToCanvas(img: HTMLImageElement): HTMLCanvasElement;
|
|
317
|
+
/**
|
|
318
|
+
* 缩放图片
|
|
319
|
+
* @param img
|
|
320
|
+
* @param opt
|
|
321
|
+
* @returns base64
|
|
322
|
+
*/
|
|
323
|
+
declare function scaleImage(img: HTMLImageElement | HTMLCanvasElement, opt?: {
|
|
324
|
+
scaleFactor: number;
|
|
325
|
+
}): string;
|
|
326
|
+
/**
|
|
327
|
+
* 缩放图片,返回 canvas
|
|
328
|
+
* @param img
|
|
329
|
+
* @param opt
|
|
330
|
+
* @returns canvas
|
|
331
|
+
*/
|
|
332
|
+
declare function scaleImageToCanvas(img: HTMLImageElement | HTMLCanvasElement, opt?: {
|
|
333
|
+
scaleFactor: number;
|
|
334
|
+
}): HTMLCanvasElement;
|
|
335
|
+
/**
|
|
336
|
+
* 图片转为 base64
|
|
337
|
+
* @param img
|
|
338
|
+
* @returns
|
|
339
|
+
*/
|
|
340
|
+
declare function imgToBase64(img: string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement): Promise<string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement>;
|
|
341
|
+
/**
|
|
342
|
+
* 图片转为 Blob
|
|
343
|
+
* @param img
|
|
344
|
+
* @returns
|
|
345
|
+
*/
|
|
346
|
+
declare function imgToBlob(img: string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement): Promise<Blob>;
|
|
347
|
+
/**
|
|
348
|
+
* 获取图片的 base64、blob 格式
|
|
349
|
+
* @param img
|
|
350
|
+
*/
|
|
351
|
+
declare function getAllTypeImg(img: string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement): Promise<{
|
|
352
|
+
base64: string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;
|
|
353
|
+
blob: Blob;
|
|
354
|
+
}>;
|
|
355
|
+
/**
|
|
356
|
+
* 等比缩放图片尺寸(不裁切、不变形)
|
|
357
|
+
* @param {HTMLImageElement} img
|
|
358
|
+
* @param {number} scale 缩放比例 0~1
|
|
359
|
+
* @returns {Promise<Blob>}
|
|
360
|
+
*/
|
|
361
|
+
declare function drawScaleImage(img: any, scale: any): Promise<unknown>;
|
|
362
|
+
/**
|
|
363
|
+
* JPG/WebP 仅动态降画质(不改尺寸)
|
|
364
|
+
* @param {Blob} blob
|
|
365
|
+
* @param {HTMLImageElement} img
|
|
366
|
+
* @returns {Promise<Blob>}
|
|
367
|
+
*/
|
|
368
|
+
declare function compressByQuality(blob: any, img: any, maxSize: any): Promise<unknown>;
|
|
369
|
+
/**
|
|
370
|
+
* 智能压缩入口
|
|
371
|
+
* 1. 小于10M直接返回原图
|
|
372
|
+
* 2. JPG/WebP:只降画质,不改尺寸
|
|
373
|
+
* 3. PNG:不转格式、只等比缩分辨率,不裁切
|
|
374
|
+
* @param {Blob} blob
|
|
375
|
+
* @returns {Promise<Blob>}
|
|
376
|
+
*/
|
|
377
|
+
declare function smartImageCompress(blob: any, maxSize: any): Promise<any>;
|
|
378
|
+
|
|
379
|
+
declare const DEFAULT_POSITION: {
|
|
380
|
+
lon: number;
|
|
381
|
+
lat: number;
|
|
382
|
+
addr: string;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* 获取当前定位
|
|
386
|
+
* @param config
|
|
387
|
+
* @returns
|
|
388
|
+
*/
|
|
389
|
+
declare function getCurrentPosition(config?: any): Promise<any>;
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* 指定 nanoid 字符集合
|
|
393
|
+
* 数字和大小写字母
|
|
394
|
+
*/
|
|
395
|
+
declare const numALetters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
396
|
+
/** nanoid 数字和大小写字母 */
|
|
397
|
+
declare const nanoidNumALetters: (size?: number) => string;
|
|
398
|
+
/**
|
|
399
|
+
* 指定 nanoid 字符集合
|
|
400
|
+
* 数字和大小写字母
|
|
401
|
+
*/
|
|
402
|
+
declare const numALettersAUrl = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_~";
|
|
403
|
+
/** nanoid url 参数规范 */
|
|
404
|
+
declare const nanoidUrl: (size?: number) => string;
|
|
405
|
+
|
|
406
|
+
interface IFieldNames {
|
|
407
|
+
value?: string;
|
|
408
|
+
label?: string;
|
|
409
|
+
children?: string;
|
|
410
|
+
}
|
|
411
|
+
interface IFindOptionOpt extends IHandleEmptyValOpt {
|
|
412
|
+
fieldNames?: IFieldNames;
|
|
413
|
+
isPathList?: boolean;
|
|
414
|
+
pathList?: Array<any>;
|
|
415
|
+
labelList?: Array<string>;
|
|
416
|
+
parent?: any;
|
|
417
|
+
}
|
|
418
|
+
interface IGetArrayLabels extends IFindOptionOpt {
|
|
419
|
+
split?: string;
|
|
420
|
+
}
|
|
421
|
+
interface IGetValLabelOpt extends IHandleEmptyValOpt {
|
|
422
|
+
showEmpty?: boolean;
|
|
423
|
+
}
|
|
424
|
+
type formatOptionsOptT = {
|
|
425
|
+
fieldNames?: IFieldNames;
|
|
426
|
+
sourceFieldNames?: IFieldNames;
|
|
427
|
+
/**
|
|
428
|
+
* 是否清除其他参数
|
|
429
|
+
*/
|
|
430
|
+
isClear?: boolean;
|
|
431
|
+
};
|
|
432
|
+
declare const DEF_FIELD_NAMES: {
|
|
433
|
+
value: string;
|
|
434
|
+
label: string;
|
|
435
|
+
children: string;
|
|
436
|
+
};
|
|
437
|
+
/**
|
|
438
|
+
* 获取无限级数据的选中项
|
|
439
|
+
* @param val
|
|
440
|
+
* @param options
|
|
441
|
+
* @param opt
|
|
442
|
+
* @returns
|
|
443
|
+
*/
|
|
444
|
+
declare const findOptionByVal: (val: any, options: any, opt?: IFindOptionOpt) => any;
|
|
445
|
+
/**
|
|
446
|
+
* 在命中项上写出标准 value / label / children(保留原字段)。
|
|
447
|
+
* 与 `getOptItByVal` 的归一化语义一致;供 `normalizeOption(findOptionByVal(...))` 组合使用。
|
|
448
|
+
* @param item 命中的 option 项
|
|
449
|
+
* @param fieldNames 自定义字段名映射
|
|
450
|
+
*/
|
|
451
|
+
declare function normalizeOption<T extends Record<string, any>>(item: T, fieldNames?: IFieldNames): T & {
|
|
452
|
+
value: unknown;
|
|
453
|
+
label: unknown;
|
|
454
|
+
children: unknown;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* 获取 options 中 val 对应的 label
|
|
458
|
+
* @param {*} val
|
|
459
|
+
* @param {Array<Object>} options
|
|
460
|
+
* @param {Object} opt
|
|
461
|
+
* @returns
|
|
462
|
+
*/
|
|
463
|
+
declare const getOptionLabel: (val: any, options?: any[], opt?: IFindOptionOpt) => any;
|
|
464
|
+
/**
|
|
465
|
+
* 获取 options 中的指定项 的 label
|
|
466
|
+
* @param {*} val
|
|
467
|
+
* @param {*} options
|
|
468
|
+
* @param {*} opt
|
|
469
|
+
* @returns
|
|
470
|
+
*/
|
|
471
|
+
declare function getValLabel(val: any, options?: any[], opt?: IGetValLabelOpt): any;
|
|
472
|
+
/**
|
|
473
|
+
* 获取 options 中的指定项 的 label 数组
|
|
474
|
+
* @param {*} values
|
|
475
|
+
* @param {*} options
|
|
476
|
+
* @param {*} opt
|
|
477
|
+
* @returns
|
|
478
|
+
*/
|
|
479
|
+
declare function getArrayLabels(values: any, options: any, opt?: IGetArrayLabels): any;
|
|
480
|
+
/**
|
|
481
|
+
* 格式化 options 数组
|
|
482
|
+
*/
|
|
483
|
+
declare const formatOptions: (options: any, opt?: formatOptionsOptT) => any;
|
|
484
|
+
/**
|
|
485
|
+
* 根据 val 获取对应的 options 项数据,并进行数据归一化处理
|
|
486
|
+
* value, label, children
|
|
487
|
+
* @param {string|number|boolean} val
|
|
488
|
+
* @param {Object} field
|
|
489
|
+
*/
|
|
490
|
+
declare const getOptItByVal: (val: any, options: any, opt: any) => any;
|
|
491
|
+
|
|
492
|
+
interface CodeOptProps {
|
|
493
|
+
baseUrl?: string;
|
|
494
|
+
env: "test" | "prod";
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* 获取二维码信息
|
|
498
|
+
* @param id 二维码ID(字符串或数字类型)
|
|
499
|
+
* @param opt 配置项
|
|
500
|
+
* @returns Promise 对象,便于外部处理异步逻辑
|
|
501
|
+
*/
|
|
502
|
+
declare const getCodeInfo: (id: string | number, opt: CodeOptProps) => Promise<unknown>;
|
|
503
|
+
/**
|
|
504
|
+
* 设置二维码信息
|
|
505
|
+
* @param value 二维码信息对象
|
|
506
|
+
* @param opt 配置项
|
|
507
|
+
* @returns Promise 对象,便于外部处理异步逻辑
|
|
508
|
+
*/
|
|
509
|
+
declare const setCodeInfo: (value: object, opt: CodeOptProps) => Promise<unknown>;
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* 获取视窗宽高
|
|
513
|
+
* @returns
|
|
514
|
+
*/
|
|
515
|
+
declare function getClientStyle(): {
|
|
516
|
+
width: number;
|
|
517
|
+
height: number;
|
|
518
|
+
};
|
|
519
|
+
/**
|
|
520
|
+
* 视窗宽高
|
|
521
|
+
*/
|
|
522
|
+
declare const clientStyle: {
|
|
523
|
+
width: number;
|
|
524
|
+
height: number;
|
|
525
|
+
};
|
|
526
|
+
/**
|
|
527
|
+
* 获取当前视窗 1vw、1vh 对应的 px
|
|
528
|
+
*/
|
|
529
|
+
declare function getViewportPX(): {
|
|
530
|
+
wPx: number;
|
|
531
|
+
hPx: number;
|
|
532
|
+
};
|
|
533
|
+
declare const DEFAULT_SIZE: {
|
|
534
|
+
width: number;
|
|
535
|
+
height: number;
|
|
536
|
+
};
|
|
537
|
+
declare function setDefaultSize(width: any, height: any): void;
|
|
538
|
+
/**
|
|
539
|
+
* 获取视窗与视觉稿的比例
|
|
540
|
+
* @param current
|
|
541
|
+
* @param defaultVal
|
|
542
|
+
* @returns
|
|
543
|
+
*/
|
|
544
|
+
declare function getClientRate(current: any, defaultVal: any): number;
|
|
545
|
+
/**
|
|
546
|
+
* 获取默认宽度对应的 vw 值
|
|
547
|
+
*/
|
|
548
|
+
declare function getVW(pxNum?: number): string;
|
|
549
|
+
/**
|
|
550
|
+
* 获取默认高度对应的 vh 值
|
|
551
|
+
*/
|
|
552
|
+
declare function getVH(pxNum?: number): string;
|
|
553
|
+
/**
|
|
554
|
+
* 获取默认宽度对应的 px 值
|
|
555
|
+
* 适用于必须传入 px 值的情况,如 ECharts
|
|
556
|
+
*/
|
|
557
|
+
declare function getWpx(pxNum?: number): number;
|
|
558
|
+
/**
|
|
559
|
+
* 获取默认高度对应的 px 值
|
|
560
|
+
* 适用于必须传入 px 值的情况,如 ECharts
|
|
561
|
+
*/
|
|
562
|
+
declare function getHpx(pxNum?: number): number;
|
|
563
|
+
/**
|
|
564
|
+
* 通过 vw 获取对应的 px
|
|
565
|
+
* @param {number} vw
|
|
566
|
+
*/
|
|
567
|
+
declare function getHPxByVW(vw?: number): number;
|
|
568
|
+
/**
|
|
569
|
+
* 通过 vh 获取对应的 px
|
|
570
|
+
* @param {number} vh
|
|
571
|
+
*/
|
|
572
|
+
declare function getWPxByVH(vh?: number): number;
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* 字符串中划线转为小驼峰
|
|
576
|
+
* @param s
|
|
577
|
+
* @returns
|
|
578
|
+
*/
|
|
579
|
+
declare const convertToCamelCase: (s: any) => any;
|
|
580
|
+
/**
|
|
581
|
+
* 对象字符串转为对象
|
|
582
|
+
* @param objStr
|
|
583
|
+
*/
|
|
584
|
+
declare const objStrToObj: (objStr: any) => any;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* 替换 search 字符串
|
|
588
|
+
* @param url
|
|
589
|
+
* @param search
|
|
590
|
+
* @returns
|
|
591
|
+
*/
|
|
592
|
+
declare function replaceSearch(url: string, search: string): any;
|
|
593
|
+
/**
|
|
594
|
+
* 把对象转为 query 参数
|
|
595
|
+
* @param query
|
|
596
|
+
*/
|
|
597
|
+
declare function objToSearch(query: any, opt: any): string;
|
|
598
|
+
/**
|
|
599
|
+
* 修复 query,解决 query 在 hash 后面的情况
|
|
600
|
+
* @param url
|
|
601
|
+
* @returns
|
|
602
|
+
* 源数据:/#/login?a=1&b=2
|
|
603
|
+
* 结果:/?a=1&b=2#/login
|
|
604
|
+
*/
|
|
605
|
+
declare function fixUrlQuery(url: any): any;
|
|
606
|
+
/**
|
|
607
|
+
* 获取 url 中的 query 值的对象
|
|
608
|
+
* 支持:完整 URL、`?a=1`、`&a=1`、纯 `a=1&b=2`
|
|
609
|
+
* @param query
|
|
610
|
+
*/
|
|
611
|
+
declare function searchToObj(url: any): {};
|
|
612
|
+
/**
|
|
613
|
+
* 添加 url 中的 query 的参数
|
|
614
|
+
* @param url
|
|
615
|
+
* @param params
|
|
616
|
+
* @param opt.isEncode 是否对 key/value 做 encodeURIComponent(默认 false,保持 1.x 既有输出)
|
|
617
|
+
* @returns url string
|
|
618
|
+
*/
|
|
619
|
+
declare function addQuery(url: any, params: any, opt?: {
|
|
620
|
+
isEncode?: boolean;
|
|
621
|
+
}): any;
|
|
622
|
+
/**
|
|
623
|
+
* 添加 url 中的 query 参数,返回 search
|
|
624
|
+
* @param url
|
|
625
|
+
* @param params
|
|
626
|
+
* @param opt.isEncode 是否对 key/value 做 encodeURIComponent(默认 false,保持 1.x 既有输出)
|
|
627
|
+
* @returns search string
|
|
628
|
+
*/
|
|
629
|
+
declare function addSearch(url: string, params: Record<string, unknown>, opt?: {
|
|
630
|
+
isEncode?: boolean;
|
|
631
|
+
}): string;
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* 获取文件后缀
|
|
635
|
+
* @param fileUrl
|
|
636
|
+
* @returns
|
|
637
|
+
*/
|
|
638
|
+
declare function getFileExt(fileUrl: any): string;
|
|
639
|
+
/**
|
|
640
|
+
* 从 url 获取文件名称,不包含后缀
|
|
641
|
+
* @param {string} fileName
|
|
642
|
+
* @param {string} str
|
|
643
|
+
* @returns
|
|
644
|
+
*/
|
|
645
|
+
declare function getFileName(fileUrl: any): string;
|
|
646
|
+
/**
|
|
647
|
+
* 从 url 获取文件名称,包含后缀
|
|
648
|
+
* @param {string} fileName
|
|
649
|
+
* @param {string} str
|
|
650
|
+
* @returns
|
|
651
|
+
*/
|
|
652
|
+
declare function getFullFileName(fileUrl: any): string;
|
|
653
|
+
/**
|
|
654
|
+
* 合并文件名称,自动处理后缀
|
|
655
|
+
* @param {string} fileName
|
|
656
|
+
* @param {string} str
|
|
657
|
+
* @returns
|
|
658
|
+
*/
|
|
659
|
+
declare const mergeFileName: (fileName: any, str?: string) => string;
|
|
660
|
+
/**
|
|
661
|
+
* 获取唯一的文件名
|
|
662
|
+
* @param {string} fileName
|
|
663
|
+
* @returns
|
|
664
|
+
*/
|
|
665
|
+
declare const getUFileName: (fileName: any) => string;
|
|
666
|
+
/**
|
|
667
|
+
* 获取文件名的后缀
|
|
668
|
+
* @param fileName
|
|
669
|
+
* @returns
|
|
670
|
+
*/
|
|
671
|
+
declare const getFileNameExt: (fileName: any) => {
|
|
672
|
+
mainPart: any;
|
|
673
|
+
ext: any;
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
declare const TYPE_VIDEO = "video";
|
|
677
|
+
declare const TYPE_IMG = "image";
|
|
678
|
+
declare const TYPE_AUDIO = "audio";
|
|
679
|
+
/**
|
|
680
|
+
* 检查 url 是否带有指定后缀
|
|
681
|
+
* @param {string} url url 地址
|
|
682
|
+
* @param {Array} types 后缀数组
|
|
683
|
+
* @returns
|
|
684
|
+
*/
|
|
685
|
+
declare function checkUrlSuffix(url: any, types?: any[], caseSensitive?: boolean): boolean;
|
|
686
|
+
/**
|
|
687
|
+
* 获取文件类型(文件自身类型,如:video/mp4、image/jpeg)
|
|
688
|
+
* @param file
|
|
689
|
+
* @returns
|
|
690
|
+
*/
|
|
691
|
+
declare function getFileType(file: any): any;
|
|
692
|
+
/**
|
|
693
|
+
* 判断 url 是否带有指定图片后缀
|
|
694
|
+
* @param {string} url
|
|
695
|
+
* @returns
|
|
696
|
+
*/
|
|
697
|
+
declare function checkImageUrl(url: any): boolean;
|
|
698
|
+
/**
|
|
699
|
+
* 判断是否是合法的媒体类型
|
|
700
|
+
* @param {String} input
|
|
701
|
+
* @returns
|
|
702
|
+
*/
|
|
703
|
+
declare function isValidMediaType(input: any): boolean;
|
|
704
|
+
/**
|
|
705
|
+
* 判断 url 是否带有指定视频后缀
|
|
706
|
+
* @param {string} url
|
|
707
|
+
* @returns
|
|
708
|
+
*/
|
|
709
|
+
declare function checkVideoUrl(url: any): boolean;
|
|
710
|
+
/**
|
|
711
|
+
* 判断 url 是否带有指定音频后缀
|
|
712
|
+
* @param {string} url
|
|
713
|
+
* @returns
|
|
714
|
+
*/
|
|
715
|
+
declare function checkAudioUrl(url: any): boolean;
|
|
716
|
+
/**
|
|
717
|
+
* 获取文件类型(项目内部枚举,如:图片-image、视频-video)
|
|
718
|
+
* @param file
|
|
719
|
+
* @returns
|
|
720
|
+
*/
|
|
721
|
+
declare function getFileTypeStr(file: any): any;
|
|
722
|
+
/**
|
|
723
|
+
* 根据文件的 MIME 类型 (file.type) 获取对应的文件后缀名
|
|
724
|
+
* @param {string} mimeType - 文件的 MIME 类型(如 'image/jpeg'、'application/pdf')
|
|
725
|
+
* @returns {string} 返回文件后缀名(带点,如 '.jpg'),未知类型返回 '.unknown'
|
|
726
|
+
*/
|
|
727
|
+
declare const getFileTypeExt: (mimeType: any) => any;
|
|
728
|
+
|
|
729
|
+
interface IFile extends File {
|
|
730
|
+
file?: IFile;
|
|
731
|
+
url?: string;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* 建立一个可以存取该 file 的 url
|
|
735
|
+
* @param {Object} file 文件
|
|
736
|
+
* @returns {string} url
|
|
737
|
+
* blob:http://localhost:8000/c9950644-5118-4231-9be7-8183bde1fdc7
|
|
738
|
+
*/
|
|
739
|
+
declare function getFileURL(file: IFile): string;
|
|
740
|
+
|
|
741
|
+
export { DEFAULT_POSITION, DEFAULT_SIZE, DEF_FIELD_NAMES, type ICheckEmptyOpt, type IFieldNames, type IFile, type IFindOptionOpt, type IGetArrayLabels, type IGetValLabelOpt, type IHandleEmptyValOpt, IMAGE_TYPES, TYPE_AUDIO, TYPE_IMG, TYPE_VIDEO, addQuery, addSearch, adjustColor, adjustTextColor, calculateAge, calculateCheckCode, checkAudioUrl, checkEmpty, checkEmptyImg, checkImageUrl, checkUrlSuffix, checkVideoUrl, clientStyle, compressByQuality, contrast, contrastRatio, convert15to18, convertToCamelCase, cropImage, cropImageToCanvas, dataURItoBlob, drawScaleImage, findOptionByVal, fixUrlQuery, formatOptions, type formatOptionsOptT, getAllTypeImg, getArr, getArrayLabels, getCanvas, getCanvasByImg, getCanvasPic, getClientRate, getClientStyle, getCodeInfo, getCurrentPosition, getDaysInMonth, getDomWH, getFileExt, getFileName, getFileNameExt, getFileType, getFileTypeExt, getFileTypeFromBase64, getFileTypeFromBlob, getFileTypeStr, getFileURL, getFullFileName, getGlobalServeConfig, getHPxByVW, getHpx, getIdCardInfo, getImgBase64, getImgEle, getOptItByVal, getOptionLabel, getTextColor, getUFileName, getVH, getVW, getValLabel, getViewportPX, getWPxByVH, getWpx, handleEmptyVal, hexToRGB, hslToRgb, imgToBase64, imgToBlob, imgToCanvas, isBase64Str, isGray, isValidBirthDate, isValidIdCard, isValidMediaType, luminance, mergeFileName, nanoidNumALetters, nanoidUrl, normalizeOption, numALetters, numALettersAUrl, objStrToObj, objToSearch, replaceSearch, rgbNumLimit, rgbToHex, rgbToHsl, scaleImage, scaleImageToCanvas, searchToObj, setCodeInfo, setDefaultSize, setDomWH, setGlobalServeConfig, setGlobalServeConfigs, smartImageCompress, verifyCheckCode };
|