beer-network 1.1.1-alpha.7 → 1.1.1-alpha.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/api.d.ts +15 -3
- package/api.js +13 -7
- package/package.json +2 -2
package/api.d.ts
CHANGED
|
@@ -16,6 +16,15 @@ export type RequestData<T> = {
|
|
|
16
16
|
total: number;
|
|
17
17
|
success: boolean;
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* 其它菜单.
|
|
21
|
+
*/
|
|
22
|
+
export type Option = {
|
|
23
|
+
/**
|
|
24
|
+
* 中止信号量.
|
|
25
|
+
*/
|
|
26
|
+
signal: AbortSignal;
|
|
27
|
+
};
|
|
19
28
|
export default class Fetch {
|
|
20
29
|
/**
|
|
21
30
|
* 请求地址.
|
|
@@ -28,23 +37,26 @@ export default class Fetch {
|
|
|
28
37
|
* @param params 参数.
|
|
29
38
|
* @param body 内容体.
|
|
30
39
|
* @param header 头部.
|
|
40
|
+
* @param option 选项.
|
|
31
41
|
*/
|
|
32
|
-
post<T>(path: string, params?: any, body?: any, header?: any): Promise<JsonResponse<T>>;
|
|
42
|
+
post<T>(path: string, params?: any, body?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
33
43
|
/**
|
|
34
44
|
* 发送POST/Form 请求.
|
|
35
45
|
* @param path 路径.
|
|
36
46
|
* @param params 参数.
|
|
37
47
|
* @param form Form参数.
|
|
38
48
|
* @param header 头部.
|
|
49
|
+
* @param option 选项.
|
|
39
50
|
*/
|
|
40
|
-
postForm<T>(path: string, params?: any, form?: any, header?: any): Promise<JsonResponse<T>>;
|
|
51
|
+
postForm<T>(path: string, params?: any, form?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
41
52
|
/**
|
|
42
53
|
* 发送Get 请求.
|
|
43
54
|
* @param path 路径.
|
|
44
55
|
* @param params 参数.
|
|
45
56
|
* @param header 头部.
|
|
57
|
+
* @param option 选项.
|
|
46
58
|
*/
|
|
47
|
-
get<T>(path: string, params?: any, header?: any): Promise<JsonResponse<T>>;
|
|
59
|
+
get<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
48
60
|
/**
|
|
49
61
|
* 缓存.
|
|
50
62
|
* @param key 缓存Key.
|
package/api.js
CHANGED
|
@@ -9,8 +9,9 @@ export default class Fetch {
|
|
|
9
9
|
* @param params 参数.
|
|
10
10
|
* @param body 内容体.
|
|
11
11
|
* @param header 头部.
|
|
12
|
+
* @param option 选项.
|
|
12
13
|
*/
|
|
13
|
-
async post(path, params, body, header) {
|
|
14
|
+
async post(path, params, body, header, option) {
|
|
14
15
|
const paramQuery = new URLSearchParams();
|
|
15
16
|
Object.keys(params || {})
|
|
16
17
|
.forEach(key => {
|
|
@@ -23,7 +24,8 @@ export default class Fetch {
|
|
|
23
24
|
...(header || {}),
|
|
24
25
|
'Content-Type': 'application/json'
|
|
25
26
|
},
|
|
26
|
-
body: JSON.stringify(body || {})
|
|
27
|
+
body: JSON.stringify(body || {}),
|
|
28
|
+
signal: option?.signal || null
|
|
27
29
|
});
|
|
28
30
|
return this.responseJson(response);
|
|
29
31
|
}
|
|
@@ -33,8 +35,9 @@ export default class Fetch {
|
|
|
33
35
|
* @param params 参数.
|
|
34
36
|
* @param form Form参数.
|
|
35
37
|
* @param header 头部.
|
|
38
|
+
* @param option 选项.
|
|
36
39
|
*/
|
|
37
|
-
async postForm(path, params, form, header) {
|
|
40
|
+
async postForm(path, params, form, header, option) {
|
|
38
41
|
const paramQuery = new URLSearchParams();
|
|
39
42
|
Object.keys(params || {})
|
|
40
43
|
.forEach(key => {
|
|
@@ -42,7 +45,7 @@ export default class Fetch {
|
|
|
42
45
|
});
|
|
43
46
|
const formData = new FormData();
|
|
44
47
|
const appendFormData = (data, parentKey = '') => {
|
|
45
|
-
for (const key
|
|
48
|
+
for (const key of data) {
|
|
46
49
|
const currentKey = parentKey ? `${parentKey}[${key}]` : key;
|
|
47
50
|
if (typeof data[key] === 'object' && data[key] !== null) {
|
|
48
51
|
appendFormData(data[key], currentKey);
|
|
@@ -66,7 +69,8 @@ export default class Fetch {
|
|
|
66
69
|
...(header || {}),
|
|
67
70
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
68
71
|
},
|
|
69
|
-
body: formData
|
|
72
|
+
body: formData,
|
|
73
|
+
signal: option?.signal || null
|
|
70
74
|
});
|
|
71
75
|
return this.responseJson(response);
|
|
72
76
|
}
|
|
@@ -75,8 +79,9 @@ export default class Fetch {
|
|
|
75
79
|
* @param path 路径.
|
|
76
80
|
* @param params 参数.
|
|
77
81
|
* @param header 头部.
|
|
82
|
+
* @param option 选项.
|
|
78
83
|
*/
|
|
79
|
-
async get(path, params, header) {
|
|
84
|
+
async get(path, params, header, option) {
|
|
80
85
|
const paramQuery = new URLSearchParams();
|
|
81
86
|
Object.keys(params || {})
|
|
82
87
|
.forEach(key => {
|
|
@@ -87,7 +92,8 @@ export default class Fetch {
|
|
|
87
92
|
headers: {
|
|
88
93
|
...this.authorization(),
|
|
89
94
|
...(header || {})
|
|
90
|
-
}
|
|
95
|
+
},
|
|
96
|
+
signal: option?.signal || null
|
|
91
97
|
});
|
|
92
98
|
return this.responseJson(response);
|
|
93
99
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beer-network",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.1.1-alpha.
|
|
4
|
+
"version": "1.1.1-alpha.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"pub-w": "copy package.json .\\dist\\package.json && npm publish ./dist"
|
|
7
|
+
"pub-w": "tsc && copy package.json .\\dist\\package.json && npm publish ./dist"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
},
|