@whitesev/utils 2.3.6 → 2.3.8
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.amd.js +37 -22
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +37 -22
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +37 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +37 -22
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +37 -22
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +37 -22
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +3 -3
- package/package.json +1 -1
- package/src/Utils.ts +48 -38
- package/src/indexedDB.ts +12 -10
|
@@ -963,7 +963,7 @@ declare class Utils {
|
|
|
963
963
|
* Utils.parseObjectToArray({"工具类":"jsonToArray","return","Array"});
|
|
964
964
|
* > ['jsonToArray', 'Array']
|
|
965
965
|
**/
|
|
966
|
-
parseObjectToArray(target:
|
|
966
|
+
parseObjectToArray<T extends any>(target: T): T[keyof T][];
|
|
967
967
|
/**
|
|
968
968
|
* 自动锁对象,用于循环判断运行的函数,在循环外new后使用,注意,如果函数内部存在异步操作,需要使用await
|
|
969
969
|
* @example
|
|
@@ -1014,7 +1014,7 @@ declare class Utils {
|
|
|
1014
1014
|
* Utils.mergeArrayToString([{"name":"数组内数据部分字段合并成字符串->"},{"name":"mergeToString"}],(item)=>{return item["name"]});
|
|
1015
1015
|
* > '数组内数据部分字段合并成字符串->mergeToString'
|
|
1016
1016
|
**/
|
|
1017
|
-
mergeArrayToString(data:
|
|
1017
|
+
mergeArrayToString<T extends any>(data: T[], handleFunc?: ((val: T) => T) | keyof T): string;
|
|
1018
1018
|
/**
|
|
1019
1019
|
* 监听页面元素改变并处理
|
|
1020
1020
|
* @param target 需要监听的元素,如果不存在,可以等待它出现
|
|
@@ -1142,7 +1142,7 @@ declare class Utils {
|
|
|
1142
1142
|
* Utils.parseInt(["aaaaaaa"],"aa");
|
|
1143
1143
|
* > NaN
|
|
1144
1144
|
**/
|
|
1145
|
-
parseInt(matchList?: any[], defaultValue?: number): number;
|
|
1145
|
+
parseInt(matchList?: any[] | null | undefined | RegExpMatchArray, defaultValue?: number): number;
|
|
1146
1146
|
/**
|
|
1147
1147
|
* blob转File对象
|
|
1148
1148
|
* @param blobUrl 需要转换的blob的链接
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -53,7 +53,7 @@ class Utils {
|
|
|
53
53
|
this.windowApi = new WindowApi(option);
|
|
54
54
|
}
|
|
55
55
|
/** 版本号 */
|
|
56
|
-
version = "2024.10.
|
|
56
|
+
version = "2024.10.19";
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
|
|
@@ -291,37 +291,38 @@ class Utils {
|
|
|
291
291
|
"Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型"
|
|
292
292
|
);
|
|
293
293
|
}
|
|
294
|
-
let
|
|
295
|
-
|
|
296
|
-
)
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
294
|
+
let clickEvent = UtilsContext.windowApi.window.event as PointerEvent;
|
|
295
|
+
let touchEvent = UtilsContext.windowApi.window.event as TouchEvent;
|
|
296
|
+
let $click = clickEvent?.composedPath()?.[0] as HTMLElement;
|
|
297
|
+
|
|
298
|
+
// 点击的x坐标
|
|
299
|
+
let clickPosX =
|
|
300
|
+
clickEvent?.clientX != null
|
|
301
|
+
? clickEvent.clientX
|
|
302
|
+
: touchEvent.touches[0].clientX;
|
|
303
|
+
// 点击的y坐标
|
|
304
|
+
let clickPosY =
|
|
305
|
+
clickEvent?.clientY != null
|
|
306
|
+
? clickEvent.clientY
|
|
307
|
+
: touchEvent.touches[0].clientY;
|
|
308
|
+
let {
|
|
309
|
+
/* 要检测的元素的相对屏幕的横坐标最左边 */
|
|
310
|
+
left: elementPosXLeft,
|
|
311
|
+
/* 要检测的元素的相对屏幕的横坐标最右边 */
|
|
312
|
+
right: elementPosXRight,
|
|
313
|
+
/* 要检测的元素的相对屏幕的纵坐标最上边 */
|
|
314
|
+
top: elementPosYTop,
|
|
315
|
+
/* 要检测的元素的相对屏幕的纵坐标最下边 */
|
|
316
|
+
bottom: elementPosYBottom,
|
|
317
|
+
} = (element as HTMLElement).getBoundingClientRect();
|
|
314
318
|
if (
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
+
clickPosX >= elementPosXLeft &&
|
|
320
|
+
clickPosX <= elementPosXRight &&
|
|
321
|
+
clickPosY >= elementPosYTop &&
|
|
322
|
+
clickPosY <= elementPosYBottom
|
|
319
323
|
) {
|
|
320
324
|
return true;
|
|
321
|
-
} else if (
|
|
322
|
-
clickNodeHTML &&
|
|
323
|
-
(element as HTMLElement).innerHTML.includes(clickNodeHTML)
|
|
324
|
-
) {
|
|
325
|
+
} else if (($click && element.contains($click)) || $click == element) {
|
|
325
326
|
/* 这种情况是应对在界面中隐藏的元素,getBoundingClientRect获取的都是0 */
|
|
326
327
|
return true;
|
|
327
328
|
} else {
|
|
@@ -2378,16 +2379,16 @@ class Utils {
|
|
|
2378
2379
|
* Utils.parseObjectToArray({"工具类":"jsonToArray","return","Array"});
|
|
2379
2380
|
* > ['jsonToArray', 'Array']
|
|
2380
2381
|
**/
|
|
2381
|
-
parseObjectToArray(target:
|
|
2382
|
-
parseObjectToArray(target:
|
|
2382
|
+
parseObjectToArray<T extends any>(target: T): T[keyof T][];
|
|
2383
|
+
parseObjectToArray<T extends any>(target: T) {
|
|
2383
2384
|
if (typeof target !== "object") {
|
|
2384
2385
|
throw new Error(
|
|
2385
2386
|
"Utils.parseObjectToArray 参数 target 必须为 object 类型"
|
|
2386
2387
|
);
|
|
2387
2388
|
}
|
|
2388
|
-
let result:
|
|
2389
|
-
Object.keys(target).forEach(function (keyName) {
|
|
2390
|
-
result = result.concat(target[keyName]);
|
|
2389
|
+
let result: T[keyof T][] = [];
|
|
2390
|
+
Object.keys(target!).forEach(function (keyName) {
|
|
2391
|
+
result = result.concat(target![keyName as any as keyof T]);
|
|
2391
2392
|
});
|
|
2392
2393
|
return result;
|
|
2393
2394
|
}
|
|
@@ -2441,8 +2442,14 @@ class Utils {
|
|
|
2441
2442
|
* Utils.mergeArrayToString([{"name":"数组内数据部分字段合并成字符串->"},{"name":"mergeToString"}],(item)=>{return item["name"]});
|
|
2442
2443
|
* > '数组内数据部分字段合并成字符串->mergeToString'
|
|
2443
2444
|
**/
|
|
2444
|
-
mergeArrayToString
|
|
2445
|
-
|
|
2445
|
+
mergeArrayToString<T extends any>(
|
|
2446
|
+
data: T[],
|
|
2447
|
+
handleFunc?: ((val: T) => T) | keyof T
|
|
2448
|
+
): string;
|
|
2449
|
+
mergeArrayToString<T extends any>(
|
|
2450
|
+
data: T[],
|
|
2451
|
+
handleFunc?: ((val: T) => T) | keyof T
|
|
2452
|
+
): string {
|
|
2446
2453
|
if (!(data instanceof Array)) {
|
|
2447
2454
|
throw new Error("Utils.mergeArrayToString 参数 data 必须为 Array 类型");
|
|
2448
2455
|
}
|
|
@@ -2457,7 +2464,7 @@ class Utils {
|
|
|
2457
2464
|
});
|
|
2458
2465
|
} else {
|
|
2459
2466
|
data.forEach((item) => {
|
|
2460
|
-
Object.values(item)
|
|
2467
|
+
Object.values(item as any)
|
|
2461
2468
|
.filter((item2) => typeof item2 === "string")
|
|
2462
2469
|
.forEach((item3) => {
|
|
2463
2470
|
content += item3;
|
|
@@ -2914,7 +2921,10 @@ class Utils {
|
|
|
2914
2921
|
* Utils.parseInt(["aaaaaaa"],"aa");
|
|
2915
2922
|
* > NaN
|
|
2916
2923
|
**/
|
|
2917
|
-
parseInt(
|
|
2924
|
+
parseInt(
|
|
2925
|
+
matchList?: any[] | null | undefined | RegExpMatchArray,
|
|
2926
|
+
defaultValue?: number
|
|
2927
|
+
): number;
|
|
2918
2928
|
parseInt(matchList: any[] = [], defaultValue = 0): number {
|
|
2919
2929
|
if (matchList == null) {
|
|
2920
2930
|
return parseInt(defaultValue.toString());
|
package/src/indexedDB.ts
CHANGED
|
@@ -35,6 +35,10 @@ class indexedDB {
|
|
|
35
35
|
code: 401,
|
|
36
36
|
msg: "操作失败",
|
|
37
37
|
},
|
|
38
|
+
empty: {
|
|
39
|
+
code: 201,
|
|
40
|
+
msg: "操作成功,但是没有数据",
|
|
41
|
+
},
|
|
38
42
|
openFailed: { code: 91001, msg: "打开数据库失败" },
|
|
39
43
|
saveFailed: { code: 91002, msg: "保存数据失败" },
|
|
40
44
|
getFailed: { code: 91003, msg: "获取数据失败" },
|
|
@@ -287,23 +291,21 @@ class indexedDB {
|
|
|
287
291
|
/* result 返回的是 {key: string, value: any} */
|
|
288
292
|
/* 键值对存储 */
|
|
289
293
|
let data = result ? result.value : void 0;
|
|
290
|
-
if (data) {
|
|
294
|
+
if (data == null) {
|
|
291
295
|
resolve({
|
|
292
296
|
success: true,
|
|
293
|
-
code: that.#statusCode.
|
|
294
|
-
msg: that.#statusCode.
|
|
295
|
-
data: data
|
|
296
|
-
|
|
297
|
+
code: that.#statusCode.empty.code,
|
|
298
|
+
msg: that.#statusCode.empty.msg,
|
|
299
|
+
data: data!,
|
|
297
300
|
event: event,
|
|
298
301
|
result: result,
|
|
299
302
|
});
|
|
300
303
|
} else {
|
|
301
304
|
resolve({
|
|
302
|
-
success:
|
|
303
|
-
code: that.#statusCode.
|
|
304
|
-
msg: that.#statusCode.
|
|
305
|
-
data:
|
|
306
|
-
|
|
305
|
+
success: true,
|
|
306
|
+
code: that.#statusCode.operationSuccess.code,
|
|
307
|
+
msg: that.#statusCode.operationSuccess.msg,
|
|
308
|
+
data: data,
|
|
307
309
|
event: event,
|
|
308
310
|
result: result,
|
|
309
311
|
});
|