ph-utils 0.16.0 → 0.16.1
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/lib/web.d.ts +4 -1
- package/lib/web.js +17 -8
- package/package.json +1 -1
package/lib/web.d.ts
CHANGED
@@ -24,4 +24,7 @@ export declare function throttle<R extends any[], T>(fn: (...args: R) => T, wait
|
|
24
24
|
* @param interval 间隔时间段
|
25
25
|
* @returns
|
26
26
|
*/
|
27
|
-
export declare function debounce<R extends any[], T>(fn: (...args: R) => T, interval?: number):
|
27
|
+
export declare function debounce<R extends any[], T>(fn: (...args: R) => T, interval?: number): {
|
28
|
+
(...args: R): void;
|
29
|
+
cancel(): void;
|
30
|
+
};
|
package/lib/web.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* web(浏览器) 端工具类
|
3
3
|
*/
|
4
|
-
import { isBlank } from
|
4
|
+
import { isBlank } from "./index.js";
|
5
5
|
/**
|
6
6
|
* 解析 Form 表单中的 input 元素的数据为 JSON 格式,key: input-name;value: input-value
|
7
7
|
* @param form {object} Form 节点对象
|
@@ -12,16 +12,17 @@ export const formJson = function (form) {
|
|
12
12
|
for (let i = 0, len = elems.length; i < len; i++) {
|
13
13
|
let item = elems[i];
|
14
14
|
if (!isBlank(item.name)) {
|
15
|
-
if ((item.tagName ===
|
16
|
-
|
17
|
-
|
15
|
+
if ((item.tagName === "INPUT" || item.tagName === "TEXTAREA") &&
|
16
|
+
!isBlank(item.value)) {
|
17
|
+
let dataType = item.getAttribute("data-type");
|
18
|
+
if (dataType === "number") {
|
18
19
|
value[item.name] = Number(item.value);
|
19
20
|
}
|
20
21
|
else {
|
21
22
|
value[item.name] = item.value;
|
22
23
|
}
|
23
24
|
}
|
24
|
-
else if (item.tagName ===
|
25
|
+
else if (item.tagName === "SELECT") {
|
25
26
|
value[item.name] = item.options[item.selectedIndex].value;
|
26
27
|
}
|
27
28
|
}
|
@@ -80,11 +81,19 @@ export function throttle(fn, wait = 500) {
|
|
80
81
|
* @returns
|
81
82
|
*/
|
82
83
|
export function debounce(fn, interval = 500) {
|
83
|
-
let _t
|
84
|
-
|
85
|
-
|
84
|
+
let _t;
|
85
|
+
const handle = (...args) => {
|
86
|
+
if (_t)
|
87
|
+
clearTimeout(_t);
|
86
88
|
_t = setTimeout(() => {
|
87
89
|
fn(...args);
|
88
90
|
}, interval);
|
89
91
|
};
|
92
|
+
handle.cancel = function () {
|
93
|
+
if (_t) {
|
94
|
+
clearTimeout(_t);
|
95
|
+
_t = null;
|
96
|
+
}
|
97
|
+
};
|
98
|
+
return handle;
|
90
99
|
}
|