ph-utils 0.2.21 → 0.2.22
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 +3 -4
- package/lib/web.js +13 -24
- package/package.json +1 -1
package/lib/web.d.ts
CHANGED
@@ -3,15 +3,14 @@
|
|
3
3
|
* @param form {object} Form 节点对象
|
4
4
|
*/
|
5
5
|
export declare const formJson: <T>(form: HTMLFormElement) => T;
|
6
|
-
interface QueryRes {
|
7
|
-
[index: string]: number | boolean | string | string[];
|
8
|
-
}
|
9
6
|
/**
|
10
7
|
* 获取 url query 参数 (get 请求的参数)
|
11
8
|
* @param search 如果是 React 应用就需要传递 useLocation().search
|
12
9
|
* @returns
|
13
10
|
*/
|
14
|
-
export declare function query(search?: string):
|
11
|
+
export declare function query(search?: string): {
|
12
|
+
[index: string]: string;
|
13
|
+
};
|
15
14
|
interface RandomOpts {
|
16
15
|
/** 生成的随机数是整形还是小数形 */
|
17
16
|
isInt?: boolean;
|
package/lib/web.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* web(浏览器) 端工具类
|
3
3
|
*/
|
4
|
-
import { isBlank
|
4
|
+
import { isBlank } from './index_m';
|
5
5
|
/**
|
6
6
|
* 解析 Form 表单中的 input 元素的数据为 JSON 格式,key: input-name;value: input-value
|
7
7
|
* @param form {object} Form 节点对象
|
@@ -38,32 +38,21 @@ export function query(search) {
|
|
38
38
|
if (isBlank(search)) {
|
39
39
|
search = location.search;
|
40
40
|
}
|
41
|
+
const searchParams = new URLSearchParams(search);
|
41
42
|
let query = {};
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
if (isBoolean(value)) {
|
50
|
-
value = Boolean(value);
|
51
|
-
}
|
52
|
-
else if (isNumeric(value)) {
|
53
|
-
value = Number(value);
|
43
|
+
for (const [key, value] of searchParams) {
|
44
|
+
let oldValue = query[key];
|
45
|
+
let newValue = value;
|
46
|
+
if (oldValue != null) {
|
47
|
+
if (oldValue instanceof Array) {
|
48
|
+
oldValue.push(value);
|
49
|
+
newValue = oldValue;
|
54
50
|
}
|
55
|
-
|
56
|
-
|
57
|
-
oldValue.push(value);
|
58
|
-
value = oldValue;
|
59
|
-
}
|
60
|
-
else {
|
61
|
-
value = [value, oldValue];
|
62
|
-
}
|
51
|
+
else {
|
52
|
+
newValue = [value, oldValue];
|
63
53
|
}
|
64
|
-
|
65
|
-
|
66
|
-
});
|
54
|
+
}
|
55
|
+
query[key] = newValue;
|
67
56
|
}
|
68
57
|
return query;
|
69
58
|
}
|