beer-network 1.1.1-alpha.9 → 1.2.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/api.d.ts +103 -2
- package/api.js +185 -37
- package/elementUtils.d.ts +7 -2
- package/elementUtils.js +14 -2
- package/package.json +3 -3
- package/session.js +11 -1
package/api.d.ts
CHANGED
|
@@ -24,13 +24,31 @@ export type Option = {
|
|
|
24
24
|
* 中止信号量.
|
|
25
25
|
*/
|
|
26
26
|
signal?: AbortSignal;
|
|
27
|
+
/**
|
|
28
|
+
* NextJS 缓存.
|
|
29
|
+
*/
|
|
30
|
+
next?: {
|
|
31
|
+
revalidate: number;
|
|
32
|
+
};
|
|
27
33
|
};
|
|
28
34
|
export default class Fetch {
|
|
29
35
|
/**
|
|
30
36
|
* 请求地址.
|
|
31
37
|
*/
|
|
32
38
|
private readonly pathPrefix;
|
|
33
|
-
constructor(pathPrefix
|
|
39
|
+
constructor(pathPrefix?: string);
|
|
40
|
+
private sendBody;
|
|
41
|
+
private sendForm;
|
|
42
|
+
private sendFormData;
|
|
43
|
+
private send;
|
|
44
|
+
/**
|
|
45
|
+
* 发送POST 请求.
|
|
46
|
+
* @param path 路径.
|
|
47
|
+
* @param params 参数.
|
|
48
|
+
* @param header 头部.
|
|
49
|
+
* @param option 选项.
|
|
50
|
+
*/
|
|
51
|
+
post<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
34
52
|
/**
|
|
35
53
|
* 发送POST/JSON 请求.
|
|
36
54
|
* @param path 路径.
|
|
@@ -39,7 +57,7 @@ export default class Fetch {
|
|
|
39
57
|
* @param header 头部.
|
|
40
58
|
* @param option 选项.
|
|
41
59
|
*/
|
|
42
|
-
|
|
60
|
+
postBody<T>(path: string, params?: any, body?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
43
61
|
/**
|
|
44
62
|
* 发送POST/Form 请求.
|
|
45
63
|
* @param path 路径.
|
|
@@ -49,6 +67,85 @@ export default class Fetch {
|
|
|
49
67
|
* @param option 选项.
|
|
50
68
|
*/
|
|
51
69
|
postForm<T>(path: string, params?: any, form?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
70
|
+
/**
|
|
71
|
+
* 发送POST/FormData 请求.
|
|
72
|
+
* @param path 路径.
|
|
73
|
+
* @param params 参数.
|
|
74
|
+
* @param formData Form参数.
|
|
75
|
+
* @param header 头部.
|
|
76
|
+
* @param option 选项.
|
|
77
|
+
*/
|
|
78
|
+
postFormData<T>(path: string, params?: any, formData?: FormData, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
79
|
+
/**
|
|
80
|
+
* 发送PUT 请求.
|
|
81
|
+
* @param path 路径.
|
|
82
|
+
* @param params 参数.
|
|
83
|
+
* @param header 头部.
|
|
84
|
+
* @param option 选项.
|
|
85
|
+
*/
|
|
86
|
+
put<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
87
|
+
/**
|
|
88
|
+
* 发送PUT/JSON 请求.
|
|
89
|
+
* @param path 路径.
|
|
90
|
+
* @param params 参数.
|
|
91
|
+
* @param body 内容体.
|
|
92
|
+
* @param header 头部.
|
|
93
|
+
* @param option 选项.
|
|
94
|
+
*/
|
|
95
|
+
putBody<T>(path: string, params?: any, body?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
96
|
+
/**
|
|
97
|
+
* 发送PUT/Form 请求.
|
|
98
|
+
* @param path 路径.
|
|
99
|
+
* @param params 参数.
|
|
100
|
+
* @param form Form参数.
|
|
101
|
+
* @param header 头部.
|
|
102
|
+
* @param option 选项.
|
|
103
|
+
*/
|
|
104
|
+
putForm<T>(path: string, params?: any, form?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
105
|
+
/**
|
|
106
|
+
* 发送PUT/FormData 请求.
|
|
107
|
+
* @param path 路径.
|
|
108
|
+
* @param params 参数.
|
|
109
|
+
* @param formData Form参数.
|
|
110
|
+
* @param header 头部.
|
|
111
|
+
* @param option 选项.
|
|
112
|
+
*/
|
|
113
|
+
putFormData<T>(path: string, params?: any, formData?: FormData, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
114
|
+
/**
|
|
115
|
+
* 发送DELETE 请求.
|
|
116
|
+
* @param path 路径.
|
|
117
|
+
* @param params 参数.
|
|
118
|
+
* @param header 头部.
|
|
119
|
+
* @param option 选项.
|
|
120
|
+
*/
|
|
121
|
+
delete<T>(path: string, params?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
122
|
+
/**
|
|
123
|
+
* 发送DELETE/JSON 请求.
|
|
124
|
+
* @param path 路径.
|
|
125
|
+
* @param params 参数.
|
|
126
|
+
* @param body 内容体.
|
|
127
|
+
* @param header 头部.
|
|
128
|
+
* @param option 选项.
|
|
129
|
+
*/
|
|
130
|
+
deleteBody<T>(path: string, params?: any, body?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
131
|
+
/**
|
|
132
|
+
* 发送DELETE/Form 请求.
|
|
133
|
+
* @param path 路径.
|
|
134
|
+
* @param params 参数.
|
|
135
|
+
* @param form Form参数.
|
|
136
|
+
* @param header 头部.
|
|
137
|
+
* @param option 选项.
|
|
138
|
+
*/
|
|
139
|
+
deleteForm<T>(path: string, params?: any, form?: any, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
140
|
+
/**
|
|
141
|
+
* 发送DELETE/FormData 请求.
|
|
142
|
+
* @param path 路径.
|
|
143
|
+
* @param params 参数.
|
|
144
|
+
* @param formData Form参数.
|
|
145
|
+
* @param header 头部.
|
|
146
|
+
* @param option 选项.
|
|
147
|
+
*/
|
|
148
|
+
deleteFormData<T>(path: string, params?: any, formData?: FormData, header?: any, option?: Option): Promise<JsonResponse<T>>;
|
|
52
149
|
/**
|
|
53
150
|
* 发送Get 请求.
|
|
54
151
|
* @param path 路径.
|
|
@@ -74,6 +171,10 @@ export default class Fetch {
|
|
|
74
171
|
* @param response 响应数据.
|
|
75
172
|
*/
|
|
76
173
|
responseJson<T>(response: Response): Promise<JsonResponse<T>>;
|
|
174
|
+
/**
|
|
175
|
+
* 获取路径前缀.
|
|
176
|
+
*/
|
|
177
|
+
getPathPrefix(): string;
|
|
77
178
|
pageParams(params: any): any;
|
|
78
179
|
pageTable<T>(response: JsonResponse<any>): Promise<Partial<RequestData<T>>>;
|
|
79
180
|
sleep(value: number): Promise<unknown>;
|
package/api.js
CHANGED
|
@@ -1,43 +1,28 @@
|
|
|
1
1
|
import { Session } from './session';
|
|
2
2
|
export default class Fetch {
|
|
3
3
|
constructor(pathPrefix) {
|
|
4
|
-
this.pathPrefix = pathPrefix;
|
|
4
|
+
this.pathPrefix = pathPrefix || '';
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
* 发送POST/JSON 请求.
|
|
8
|
-
* @param path 路径.
|
|
9
|
-
* @param params 参数.
|
|
10
|
-
* @param body 内容体.
|
|
11
|
-
* @param header 头部.
|
|
12
|
-
* @param option 选项.
|
|
13
|
-
*/
|
|
14
|
-
async post(path, params, body, header, option) {
|
|
6
|
+
async sendBody(method, path, params, body, header, option) {
|
|
15
7
|
const paramQuery = new URLSearchParams();
|
|
16
8
|
Object.keys(params || {})
|
|
17
9
|
.forEach(key => {
|
|
18
10
|
paramQuery.append(key, params[key]);
|
|
19
11
|
});
|
|
20
|
-
const response = await fetch(this.
|
|
21
|
-
method
|
|
12
|
+
const response = await fetch(this.getPathPrefix() + path + (paramQuery.toString() === '' ? '' : '?') + paramQuery.toString(), {
|
|
13
|
+
method,
|
|
22
14
|
headers: {
|
|
23
15
|
...this.authorization(),
|
|
24
16
|
...(header || {}),
|
|
25
17
|
'Content-Type': 'application/json'
|
|
26
18
|
},
|
|
27
19
|
body: JSON.stringify(body || {}),
|
|
28
|
-
signal: option?.signal || null
|
|
20
|
+
signal: option?.signal || null,
|
|
21
|
+
next: option?.next
|
|
29
22
|
});
|
|
30
23
|
return this.responseJson(response);
|
|
31
24
|
}
|
|
32
|
-
|
|
33
|
-
* 发送POST/Form 请求.
|
|
34
|
-
* @param path 路径.
|
|
35
|
-
* @param params 参数.
|
|
36
|
-
* @param form Form参数.
|
|
37
|
-
* @param header 头部.
|
|
38
|
-
* @param option 选项.
|
|
39
|
-
*/
|
|
40
|
-
async postForm(path, params, form, header, option) {
|
|
25
|
+
async sendForm(method, path, params, form, header, option) {
|
|
41
26
|
const paramQuery = new URLSearchParams();
|
|
42
27
|
Object.keys(params || {})
|
|
43
28
|
.forEach(key => {
|
|
@@ -62,41 +47,193 @@ export default class Fetch {
|
|
|
62
47
|
}
|
|
63
48
|
};
|
|
64
49
|
appendFormData(form);
|
|
65
|
-
const response = await fetch(this.
|
|
66
|
-
method
|
|
50
|
+
const response = await fetch(this.getPathPrefix() + path + (paramQuery.toString() === '' ? '' : '?') + paramQuery.toString(), {
|
|
51
|
+
method,
|
|
67
52
|
headers: {
|
|
68
53
|
...this.authorization(),
|
|
69
54
|
...(header || {}),
|
|
70
55
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
71
56
|
},
|
|
72
57
|
body: formData,
|
|
73
|
-
signal: option?.signal || null
|
|
58
|
+
signal: option?.signal || null,
|
|
59
|
+
next: option?.next
|
|
74
60
|
});
|
|
75
61
|
return this.responseJson(response);
|
|
76
62
|
}
|
|
77
|
-
|
|
78
|
-
* 发送Get 请求.
|
|
79
|
-
* @param path 路径.
|
|
80
|
-
* @param params 参数.
|
|
81
|
-
* @param header 头部.
|
|
82
|
-
* @param option 选项.
|
|
83
|
-
*/
|
|
84
|
-
async get(path, params, header, option) {
|
|
63
|
+
async sendFormData(method, path, params, formData, header, option) {
|
|
85
64
|
const paramQuery = new URLSearchParams();
|
|
86
65
|
Object.keys(params || {})
|
|
87
66
|
.forEach(key => {
|
|
88
67
|
paramQuery.append(key, params[key]);
|
|
89
68
|
});
|
|
90
|
-
const response = await fetch(this.
|
|
91
|
-
method
|
|
69
|
+
const response = await fetch(this.getPathPrefix() + path + (paramQuery.toString() === '' ? '' : '?') + paramQuery.toString(), {
|
|
70
|
+
method,
|
|
92
71
|
headers: {
|
|
93
72
|
...this.authorization(),
|
|
94
73
|
...(header || {})
|
|
95
74
|
},
|
|
96
|
-
|
|
75
|
+
body: formData,
|
|
76
|
+
signal: option?.signal || null,
|
|
77
|
+
next: option?.next
|
|
97
78
|
});
|
|
98
79
|
return this.responseJson(response);
|
|
99
80
|
}
|
|
81
|
+
async send(method, path, params, header, option) {
|
|
82
|
+
const paramQuery = new URLSearchParams();
|
|
83
|
+
Object.keys(params || {})
|
|
84
|
+
.forEach(key => {
|
|
85
|
+
paramQuery.append(key, params[key]);
|
|
86
|
+
});
|
|
87
|
+
const response = await fetch(this.getPathPrefix() + path + '?' + paramQuery.toString(), {
|
|
88
|
+
method,
|
|
89
|
+
headers: {
|
|
90
|
+
...this.authorization(),
|
|
91
|
+
...(header || {})
|
|
92
|
+
},
|
|
93
|
+
signal: option?.signal || null,
|
|
94
|
+
next: option?.next
|
|
95
|
+
});
|
|
96
|
+
return this.responseJson(response);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 发送POST 请求.
|
|
100
|
+
* @param path 路径.
|
|
101
|
+
* @param params 参数.
|
|
102
|
+
* @param header 头部.
|
|
103
|
+
* @param option 选项.
|
|
104
|
+
*/
|
|
105
|
+
async post(path, params, header, option) {
|
|
106
|
+
return this.send('POST', path, params, header, option);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 发送POST/JSON 请求.
|
|
110
|
+
* @param path 路径.
|
|
111
|
+
* @param params 参数.
|
|
112
|
+
* @param body 内容体.
|
|
113
|
+
* @param header 头部.
|
|
114
|
+
* @param option 选项.
|
|
115
|
+
*/
|
|
116
|
+
async postBody(path, params, body, header, option) {
|
|
117
|
+
return this.sendBody('POST', path, params, body, header, option);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 发送POST/Form 请求.
|
|
121
|
+
* @param path 路径.
|
|
122
|
+
* @param params 参数.
|
|
123
|
+
* @param form Form参数.
|
|
124
|
+
* @param header 头部.
|
|
125
|
+
* @param option 选项.
|
|
126
|
+
*/
|
|
127
|
+
async postForm(path, params, form, header, option) {
|
|
128
|
+
return this.sendForm('POST', path, params, form, header, option);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 发送POST/FormData 请求.
|
|
132
|
+
* @param path 路径.
|
|
133
|
+
* @param params 参数.
|
|
134
|
+
* @param formData Form参数.
|
|
135
|
+
* @param header 头部.
|
|
136
|
+
* @param option 选项.
|
|
137
|
+
*/
|
|
138
|
+
async postFormData(path, params, formData, header, option) {
|
|
139
|
+
return this.sendFormData('POST', path, params, formData, header, option);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 发送PUT 请求.
|
|
143
|
+
* @param path 路径.
|
|
144
|
+
* @param params 参数.
|
|
145
|
+
* @param header 头部.
|
|
146
|
+
* @param option 选项.
|
|
147
|
+
*/
|
|
148
|
+
async put(path, params, header, option) {
|
|
149
|
+
return this.send('PUT', path, params, header, option);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 发送PUT/JSON 请求.
|
|
153
|
+
* @param path 路径.
|
|
154
|
+
* @param params 参数.
|
|
155
|
+
* @param body 内容体.
|
|
156
|
+
* @param header 头部.
|
|
157
|
+
* @param option 选项.
|
|
158
|
+
*/
|
|
159
|
+
async putBody(path, params, body, header, option) {
|
|
160
|
+
return this.sendBody('PUT', path, params, body, header, option);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 发送PUT/Form 请求.
|
|
164
|
+
* @param path 路径.
|
|
165
|
+
* @param params 参数.
|
|
166
|
+
* @param form Form参数.
|
|
167
|
+
* @param header 头部.
|
|
168
|
+
* @param option 选项.
|
|
169
|
+
*/
|
|
170
|
+
async putForm(path, params, form, header, option) {
|
|
171
|
+
return this.sendForm('PUT', path, params, form, header, option);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 发送PUT/FormData 请求.
|
|
175
|
+
* @param path 路径.
|
|
176
|
+
* @param params 参数.
|
|
177
|
+
* @param formData Form参数.
|
|
178
|
+
* @param header 头部.
|
|
179
|
+
* @param option 选项.
|
|
180
|
+
*/
|
|
181
|
+
async putFormData(path, params, formData, header, option) {
|
|
182
|
+
return this.sendFormData('PUT', path, params, formData, header, option);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* 发送DELETE 请求.
|
|
186
|
+
* @param path 路径.
|
|
187
|
+
* @param params 参数.
|
|
188
|
+
* @param header 头部.
|
|
189
|
+
* @param option 选项.
|
|
190
|
+
*/
|
|
191
|
+
async delete(path, params, header, option) {
|
|
192
|
+
return this.send('DELETE', path, params, header, option);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 发送DELETE/JSON 请求.
|
|
196
|
+
* @param path 路径.
|
|
197
|
+
* @param params 参数.
|
|
198
|
+
* @param body 内容体.
|
|
199
|
+
* @param header 头部.
|
|
200
|
+
* @param option 选项.
|
|
201
|
+
*/
|
|
202
|
+
async deleteBody(path, params, body, header, option) {
|
|
203
|
+
return this.sendBody('DELETE', path, params, body, header, option);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* 发送DELETE/Form 请求.
|
|
207
|
+
* @param path 路径.
|
|
208
|
+
* @param params 参数.
|
|
209
|
+
* @param form Form参数.
|
|
210
|
+
* @param header 头部.
|
|
211
|
+
* @param option 选项.
|
|
212
|
+
*/
|
|
213
|
+
async deleteForm(path, params, form, header, option) {
|
|
214
|
+
return this.sendForm('DELETE', path, params, form, header, option);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* 发送DELETE/FormData 请求.
|
|
218
|
+
* @param path 路径.
|
|
219
|
+
* @param params 参数.
|
|
220
|
+
* @param formData Form参数.
|
|
221
|
+
* @param header 头部.
|
|
222
|
+
* @param option 选项.
|
|
223
|
+
*/
|
|
224
|
+
async deleteFormData(path, params, formData, header, option) {
|
|
225
|
+
return this.sendFormData('DELETE', path, params, formData, header, option);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* 发送Get 请求.
|
|
229
|
+
* @param path 路径.
|
|
230
|
+
* @param params 参数.
|
|
231
|
+
* @param header 头部.
|
|
232
|
+
* @param option 选项.
|
|
233
|
+
*/
|
|
234
|
+
async get(path, params, header, option) {
|
|
235
|
+
return this.send('GET', path, params, header, option);
|
|
236
|
+
}
|
|
100
237
|
/**
|
|
101
238
|
* 缓存.
|
|
102
239
|
* @param key 缓存Key.
|
|
@@ -139,12 +276,23 @@ export default class Fetch {
|
|
|
139
276
|
*/
|
|
140
277
|
async responseJson(response) {
|
|
141
278
|
const result = await response.json();
|
|
279
|
+
if (typeof window === 'undefined') {
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
const redirect = encodeURIComponent(window.location.href);
|
|
142
283
|
if (result?.code === '401') {
|
|
143
|
-
|
|
284
|
+
const link = (window?.authLogin || '/auth/login') + '?redirect=' + redirect;
|
|
285
|
+
setTimeout(() => window.location.replace(link), 500);
|
|
144
286
|
return result;
|
|
145
287
|
}
|
|
146
288
|
return result;
|
|
147
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* 获取路径前缀.
|
|
292
|
+
*/
|
|
293
|
+
getPathPrefix() {
|
|
294
|
+
return this.pathPrefix || '';
|
|
295
|
+
}
|
|
148
296
|
pageParams(params) {
|
|
149
297
|
return {
|
|
150
298
|
...params,
|
package/elementUtils.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
export default class ElementUtils {
|
|
2
2
|
/**
|
|
3
3
|
* 选择文件本地文件.
|
|
4
|
+
* @param multiple 是否多选.
|
|
4
5
|
*/
|
|
5
|
-
static selectFile(): Promise<FileList | null>;
|
|
6
|
+
static selectFile(multiple?: boolean | undefined): Promise<FileList | null>;
|
|
7
|
+
/**
|
|
8
|
+
* 选择文件夹.
|
|
9
|
+
*/
|
|
10
|
+
static selectDirectory(): Promise<FileSystemDirectoryHandle | undefined>;
|
|
6
11
|
/**
|
|
7
12
|
* 下载文件.
|
|
8
13
|
* @param url 文件下载地址.
|
|
9
14
|
* @param fileName 文件名称.
|
|
10
15
|
*/
|
|
11
|
-
static download(url: string, fileName
|
|
16
|
+
static download(url: string, fileName?: string): void;
|
|
12
17
|
}
|
package/elementUtils.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export default class ElementUtils {
|
|
2
2
|
/**
|
|
3
3
|
* 选择文件本地文件.
|
|
4
|
+
* @param multiple 是否多选.
|
|
4
5
|
*/
|
|
5
|
-
static selectFile() {
|
|
6
|
+
static selectFile(multiple) {
|
|
6
7
|
return new Promise((resolve) => {
|
|
7
8
|
const fileInput = document.createElement('input');
|
|
8
9
|
fileInput.type = 'file';
|
|
10
|
+
fileInput.multiple = multiple || false;
|
|
9
11
|
fileInput.style.display = 'none';
|
|
10
12
|
document.body.appendChild(fileInput);
|
|
11
13
|
fileInput.addEventListener('change', () => {
|
|
@@ -15,6 +17,16 @@ export default class ElementUtils {
|
|
|
15
17
|
fileInput.click();
|
|
16
18
|
});
|
|
17
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* 选择文件夹.
|
|
22
|
+
*/
|
|
23
|
+
static async selectDirectory() {
|
|
24
|
+
if (!window.showDirectoryPicker) {
|
|
25
|
+
alert('您的浏览器不支持文件夹选择功能');
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return await window.showDirectoryPicker();
|
|
29
|
+
}
|
|
18
30
|
/**
|
|
19
31
|
* 下载文件.
|
|
20
32
|
* @param url 文件下载地址.
|
|
@@ -23,7 +35,7 @@ export default class ElementUtils {
|
|
|
23
35
|
static download(url, fileName) {
|
|
24
36
|
const link = document.createElement('a');
|
|
25
37
|
link.href = url;
|
|
26
|
-
link.download = fileName;
|
|
38
|
+
link.download = fileName || '';
|
|
27
39
|
document.body.appendChild(link);
|
|
28
40
|
link.click();
|
|
29
41
|
document.body.removeChild(link);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beer-network",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.
|
|
5
|
-
"type": "module",
|
|
4
|
+
"version": "1.2.1",
|
|
6
5
|
"scripts": {
|
|
7
|
-
"pub-w": "tsc && copy package.json .\\dist\\package.json && npm publish ./dist"
|
|
6
|
+
"pub-w": "tsc && copy package.json .\\dist\\package.json && npm publish ./dist",
|
|
7
|
+
"pub-m": "tsc && cp package.json ./dist/package.json && npm publish ./dist"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
},
|
package/session.js
CHANGED
|
@@ -6,6 +6,9 @@ export class Session {
|
|
|
6
6
|
* <li>window.accessToken 设置身份令牌, 直接返回.</li>
|
|
7
7
|
*/
|
|
8
8
|
static getBearer() {
|
|
9
|
+
if (typeof window === 'undefined') {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
9
12
|
if (window.accessToken !== undefined && window.accessToken !== '') {
|
|
10
13
|
return window.accessToken;
|
|
11
14
|
}
|
|
@@ -20,6 +23,9 @@ export class Session {
|
|
|
20
23
|
* 检查令牌是否存在.
|
|
21
24
|
*/
|
|
22
25
|
static checkAccessTokenExist() {
|
|
26
|
+
if (typeof window === 'undefined') {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
23
29
|
const bearer = Session.getBearer();
|
|
24
30
|
return !(bearer === undefined || bearer === '');
|
|
25
31
|
}
|
|
@@ -28,7 +34,11 @@ export class Session {
|
|
|
28
34
|
* @param url 退出之后的地址.
|
|
29
35
|
*/
|
|
30
36
|
static logout(url) {
|
|
31
|
-
|
|
37
|
+
if (typeof window === 'undefined') {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
localStorage?.clear();
|
|
41
|
+
sessionStorage?.clear();
|
|
32
42
|
if (url !== undefined && url !== '') {
|
|
33
43
|
window.location.href = url;
|
|
34
44
|
}
|