@gz-fronted/gz-pc 0.1.3-beta.2 → 0.2.0-beta.0
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/README.md +601 -628
- package/dist/fetch/index.cjs +126 -765
- package/dist/fetch/index.d.cts +3 -23
- package/dist/fetch/index.d.ts +3 -23
- package/dist/fetch/index.js +128 -765
- package/package.json +100 -99
package/dist/fetch/index.js
CHANGED
|
@@ -1,717 +1,10 @@
|
|
|
1
1
|
import axios, { AxiosError, AxiosHeaders } from 'axios';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { Modal, message } from 'gz-ui-web';
|
|
3
|
+
import { parse, isSafeNumber } from 'lossless-json';
|
|
4
|
+
import { useRef, useSyncExternalStore, useEffect, useCallback } from 'react';
|
|
5
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
6
|
|
|
6
7
|
// src/fetch/client.ts
|
|
7
|
-
|
|
8
|
-
// src/fetch/feedback/debug-store.ts
|
|
9
|
-
var EMPTY_DEBUG_DRAWER_SNAPSHOT = {
|
|
10
|
-
activeHostId: void 0,
|
|
11
|
-
errors: [],
|
|
12
|
-
open: false,
|
|
13
|
-
selectedErrorId: void 0
|
|
14
|
-
};
|
|
15
|
-
var debugErrorSequence = 0;
|
|
16
|
-
var snapshot = EMPTY_DEBUG_DRAWER_SNAPSHOT;
|
|
17
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
18
|
-
var drawerHosts = /* @__PURE__ */ new Set();
|
|
19
|
-
var emitChange = () => {
|
|
20
|
-
for (const listener of listeners) {
|
|
21
|
-
listener();
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var setSnapshot = (nextSnapshot) => {
|
|
25
|
-
snapshot = nextSnapshot;
|
|
26
|
-
emitChange();
|
|
27
|
-
};
|
|
28
|
-
var subscribeDebugDrawer = (listener) => {
|
|
29
|
-
listeners.add(listener);
|
|
30
|
-
return () => listeners.delete(listener);
|
|
31
|
-
};
|
|
32
|
-
var getDebugDrawerSnapshot = () => snapshot;
|
|
33
|
-
var getDebugDrawerServerSnapshot = () => EMPTY_DEBUG_DRAWER_SNAPSHOT;
|
|
34
|
-
var registerDebugDrawerHost = (hostId) => {
|
|
35
|
-
drawerHosts.add(hostId);
|
|
36
|
-
if (snapshot.activeHostId === void 0) {
|
|
37
|
-
setSnapshot({ ...snapshot, activeHostId: hostId });
|
|
38
|
-
}
|
|
39
|
-
return () => {
|
|
40
|
-
drawerHosts.delete(hostId);
|
|
41
|
-
if (snapshot.activeHostId !== hostId) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const nextHost = drawerHosts.values().next();
|
|
45
|
-
setSnapshot({
|
|
46
|
-
...snapshot,
|
|
47
|
-
activeHostId: nextHost.done ? void 0 : nextHost.value
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
var appendDebugError = (input) => {
|
|
52
|
-
if (snapshot.activeHostId === void 0) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
debugErrorSequence += 1;
|
|
56
|
-
const error = {
|
|
57
|
-
...input,
|
|
58
|
-
id: `${Date.now()}-${debugErrorSequence}`
|
|
59
|
-
};
|
|
60
|
-
setSnapshot({
|
|
61
|
-
...snapshot,
|
|
62
|
-
errors: [error, ...snapshot.errors],
|
|
63
|
-
open: true,
|
|
64
|
-
selectedErrorId: error.id
|
|
65
|
-
});
|
|
66
|
-
return true;
|
|
67
|
-
};
|
|
68
|
-
var closeDebugDrawer = () => {
|
|
69
|
-
if (snapshot.open) {
|
|
70
|
-
setSnapshot({ ...snapshot, open: false });
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var removeDebugError = (id) => {
|
|
74
|
-
var _a, _b, _c, _d;
|
|
75
|
-
const removedIndex = snapshot.errors.findIndex((error) => error.id === id);
|
|
76
|
-
if (removedIndex === -1) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const errors = snapshot.errors.filter((error) => error.id !== id);
|
|
80
|
-
const selectedErrorId = snapshot.selectedErrorId === id ? (_c = (_a = errors[removedIndex]) == null ? void 0 : _a.id) != null ? _c : (_b = errors[removedIndex - 1]) == null ? void 0 : _b.id : snapshot.selectedErrorId && errors.some((error) => error.id === snapshot.selectedErrorId) ? snapshot.selectedErrorId : (_d = errors[0]) == null ? void 0 : _d.id;
|
|
81
|
-
setSnapshot({
|
|
82
|
-
...snapshot,
|
|
83
|
-
errors,
|
|
84
|
-
selectedErrorId
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
var selectDebugError = (id) => {
|
|
88
|
-
if (snapshot.selectedErrorId === id || !snapshot.errors.some((error) => error.id === id)) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
setSnapshot({ ...snapshot, selectedErrorId: id });
|
|
92
|
-
};
|
|
93
|
-
var clearDebugErrors = () => {
|
|
94
|
-
if (snapshot.errors.length > 0) {
|
|
95
|
-
setSnapshot({ ...snapshot, errors: [], selectedErrorId: void 0 });
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
var feedbackHosts = /* @__PURE__ */ new Map();
|
|
99
|
-
var activeHostId;
|
|
100
|
-
var registerFeedbackHost = (hostId, host) => {
|
|
101
|
-
feedbackHosts.set(hostId, host);
|
|
102
|
-
activeHostId != null ? activeHostId : activeHostId = hostId;
|
|
103
|
-
return () => {
|
|
104
|
-
feedbackHosts.delete(hostId);
|
|
105
|
-
if (activeHostId !== hostId) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const nextHost = feedbackHosts.keys().next();
|
|
109
|
-
activeHostId = nextHost.done ? void 0 : nextHost.value;
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
var showFeedbackErrorMessage = (content) => {
|
|
113
|
-
const activeHost = activeHostId === void 0 ? void 0 : feedbackHosts.get(activeHostId);
|
|
114
|
-
if (activeHost) {
|
|
115
|
-
activeHost.showErrorMessage(content);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
message.error(content);
|
|
119
|
-
};
|
|
120
|
-
var showFeedbackSuccessMessage = (content) => {
|
|
121
|
-
const activeHost = activeHostId === void 0 ? void 0 : feedbackHosts.get(activeHostId);
|
|
122
|
-
if (activeHost == null ? void 0 : activeHost.showSuccessMessage) {
|
|
123
|
-
activeHost.showSuccessMessage(content);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
message.success(content);
|
|
127
|
-
};
|
|
128
|
-
var EMPTY_DEBUG_VALUE = "(无)";
|
|
129
|
-
var formatDebugValue = (value) => {
|
|
130
|
-
if (typeof value === "string") {
|
|
131
|
-
return value;
|
|
132
|
-
}
|
|
133
|
-
if (value === void 0 || value === null) {
|
|
134
|
-
return EMPTY_DEBUG_VALUE;
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
const serialized = JSON.stringify(value, null, 2);
|
|
138
|
-
return serialized != null ? serialized : "(无法序列化)";
|
|
139
|
-
} catch (e) {
|
|
140
|
-
return "(无法序列化)";
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
var formatCompleteDebugResponse = (error) => error.responseData === void 0 ? void 0 : formatDebugValue(error.responseData);
|
|
144
|
-
var copyDebugText = async (text) => {
|
|
145
|
-
var _a;
|
|
146
|
-
try {
|
|
147
|
-
if (typeof navigator !== "undefined" && ((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
|
|
148
|
-
await navigator.clipboard.writeText(text);
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
} catch (e) {
|
|
152
|
-
}
|
|
153
|
-
if (typeof document === "undefined" || !document.body || typeof document.execCommand !== "function") {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
const textarea = document.createElement("textarea");
|
|
157
|
-
textarea.value = text;
|
|
158
|
-
textarea.setAttribute("readonly", "");
|
|
159
|
-
textarea.style.position = "fixed";
|
|
160
|
-
textarea.style.opacity = "0";
|
|
161
|
-
document.body.appendChild(textarea);
|
|
162
|
-
let copied = false;
|
|
163
|
-
try {
|
|
164
|
-
textarea.focus();
|
|
165
|
-
textarea.select();
|
|
166
|
-
copied = document.execCommand("copy");
|
|
167
|
-
} catch (e) {
|
|
168
|
-
copied = false;
|
|
169
|
-
} finally {
|
|
170
|
-
document.body.removeChild(textarea);
|
|
171
|
-
}
|
|
172
|
-
return copied;
|
|
173
|
-
};
|
|
174
|
-
var codeBlockStyle = {
|
|
175
|
-
background: "var(--gz-color-bg-field, rgba(127, 127, 127, 0.08))",
|
|
176
|
-
border: "0",
|
|
177
|
-
borderRadius: 6,
|
|
178
|
-
boxSizing: "border-box",
|
|
179
|
-
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
|
|
180
|
-
lineHeight: 1.5,
|
|
181
|
-
margin: 0,
|
|
182
|
-
minHeight: 0,
|
|
183
|
-
overflow: "auto",
|
|
184
|
-
overflowWrap: "anywhere",
|
|
185
|
-
padding: 16,
|
|
186
|
-
whiteSpace: "pre-wrap"
|
|
187
|
-
};
|
|
188
|
-
var methodTagColors = {
|
|
189
|
-
DELETE: "red",
|
|
190
|
-
GET: "green",
|
|
191
|
-
PATCH: "purple",
|
|
192
|
-
POST: "gold",
|
|
193
|
-
PUT: "blue"
|
|
194
|
-
};
|
|
195
|
-
var getHttpMethodTagColor = (method) => {
|
|
196
|
-
const normalizedMethod = method == null ? void 0 : method.toUpperCase();
|
|
197
|
-
return normalizedMethod === void 0 ? void 0 : methodTagColors[normalizedMethod];
|
|
198
|
-
};
|
|
199
|
-
var HttpMethodTag = ({ method }) => {
|
|
200
|
-
var _a;
|
|
201
|
-
const normalizedMethod = (_a = method == null ? void 0 : method.toUpperCase()) != null ? _a : "--";
|
|
202
|
-
const color = getHttpMethodTagColor(method);
|
|
203
|
-
return color ? /* @__PURE__ */ jsx(Tag, { color, children: normalizedMethod }) : /* @__PURE__ */ jsx(Tag, { children: normalizedMethod });
|
|
204
|
-
};
|
|
205
|
-
var DebugCodeBlock = ({ onCopy, value }) => {
|
|
206
|
-
const canCopy = value !== void 0 && value !== null;
|
|
207
|
-
return /* @__PURE__ */ jsxs(
|
|
208
|
-
"div",
|
|
209
|
-
{
|
|
210
|
-
style: {
|
|
211
|
-
height: "100%",
|
|
212
|
-
minHeight: 0,
|
|
213
|
-
overflow: "auto",
|
|
214
|
-
position: "relative"
|
|
215
|
-
},
|
|
216
|
-
children: [
|
|
217
|
-
canCopy ? /* @__PURE__ */ jsx(Tooltip, { title: "复制", children: /* @__PURE__ */ jsx(
|
|
218
|
-
Button,
|
|
219
|
-
{
|
|
220
|
-
"aria-label": "复制",
|
|
221
|
-
size: "middle",
|
|
222
|
-
style: {
|
|
223
|
-
paddingInline: 12,
|
|
224
|
-
position: "absolute",
|
|
225
|
-
right: 8,
|
|
226
|
-
top: 8,
|
|
227
|
-
zIndex: 1
|
|
228
|
-
},
|
|
229
|
-
type: "primary",
|
|
230
|
-
onClick: onCopy,
|
|
231
|
-
children: "复制"
|
|
232
|
-
}
|
|
233
|
-
) }) : null,
|
|
234
|
-
/* @__PURE__ */ jsx(
|
|
235
|
-
"pre",
|
|
236
|
-
{
|
|
237
|
-
style: {
|
|
238
|
-
...codeBlockStyle,
|
|
239
|
-
paddingRight: canCopy ? 88 : codeBlockStyle.padding
|
|
240
|
-
},
|
|
241
|
-
children: formatDebugValue(value)
|
|
242
|
-
}
|
|
243
|
-
)
|
|
244
|
-
]
|
|
245
|
-
}
|
|
246
|
-
);
|
|
247
|
-
};
|
|
248
|
-
var DebugErrorListItem = ({ error, index, selected, total }) => {
|
|
249
|
-
var _a, _b;
|
|
250
|
-
const handleRemove = (event) => {
|
|
251
|
-
event.stopPropagation();
|
|
252
|
-
removeDebugError(error.id);
|
|
253
|
-
};
|
|
254
|
-
const handleKeyDown = (event) => {
|
|
255
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
256
|
-
event.preventDefault();
|
|
257
|
-
selectDebugError(error.id);
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
return /* @__PURE__ */ jsxs(
|
|
261
|
-
"div",
|
|
262
|
-
{
|
|
263
|
-
"aria-selected": selected,
|
|
264
|
-
role: "button",
|
|
265
|
-
tabIndex: 0,
|
|
266
|
-
title: error.url,
|
|
267
|
-
onClick: () => selectDebugError(error.id),
|
|
268
|
-
onKeyDown: handleKeyDown,
|
|
269
|
-
style: {
|
|
270
|
-
background: selected ? "var(--gz-color-bg-field, rgba(127, 127, 127, 0.12))" : "transparent",
|
|
271
|
-
borderRadius: 6,
|
|
272
|
-
cursor: "pointer",
|
|
273
|
-
display: "flex",
|
|
274
|
-
flexDirection: "column",
|
|
275
|
-
gap: 6,
|
|
276
|
-
margin: "0 8px",
|
|
277
|
-
minWidth: 0,
|
|
278
|
-
padding: "10px 8px",
|
|
279
|
-
position: "relative"
|
|
280
|
-
},
|
|
281
|
-
children: [
|
|
282
|
-
/* @__PURE__ */ jsx(
|
|
283
|
-
"span",
|
|
284
|
-
{
|
|
285
|
-
"aria-hidden": "true",
|
|
286
|
-
style: {
|
|
287
|
-
background: selected ? "var(--gz-color-primary, var(--gz-color-primary-border, rgba(127, 127, 127, 0.24)))" : "transparent",
|
|
288
|
-
borderRadius: 2,
|
|
289
|
-
bottom: 8,
|
|
290
|
-
left: 0,
|
|
291
|
-
pointerEvents: "none",
|
|
292
|
-
position: "absolute",
|
|
293
|
-
top: 8,
|
|
294
|
-
width: 3
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
),
|
|
298
|
-
/* @__PURE__ */ jsxs(
|
|
299
|
-
"div",
|
|
300
|
-
{
|
|
301
|
-
style: {
|
|
302
|
-
alignItems: "center",
|
|
303
|
-
display: "flex",
|
|
304
|
-
gap: 8,
|
|
305
|
-
minWidth: 0
|
|
306
|
-
},
|
|
307
|
-
children: [
|
|
308
|
-
/* @__PURE__ */ jsxs(
|
|
309
|
-
"span",
|
|
310
|
-
{
|
|
311
|
-
style: { color: "var(--gz-color-text-secondary)", flex: "0 0 auto" },
|
|
312
|
-
children: [
|
|
313
|
-
"#",
|
|
314
|
-
total - index
|
|
315
|
-
]
|
|
316
|
-
}
|
|
317
|
-
),
|
|
318
|
-
/* @__PURE__ */ jsx("span", { style: { flex: "0 0 58px", minWidth: 58 }, children: /* @__PURE__ */ jsx(HttpMethodTag, { method: error.method }) }),
|
|
319
|
-
/* @__PURE__ */ jsx(
|
|
320
|
-
"span",
|
|
321
|
-
{
|
|
322
|
-
style: {
|
|
323
|
-
display: "block",
|
|
324
|
-
flex: "1 1 auto",
|
|
325
|
-
minWidth: 0,
|
|
326
|
-
overflow: "hidden"
|
|
327
|
-
},
|
|
328
|
-
children: /* @__PURE__ */ jsx(Tooltip, { title: (_a = error.url) != null ? _a : "--", children: /* @__PURE__ */ jsx(
|
|
329
|
-
"code",
|
|
330
|
-
{
|
|
331
|
-
style: {
|
|
332
|
-
color: "var(--gz-color-text-secondary)",
|
|
333
|
-
direction: "rtl",
|
|
334
|
-
display: "block",
|
|
335
|
-
minWidth: 0,
|
|
336
|
-
overflow: "hidden",
|
|
337
|
-
textAlign: "left",
|
|
338
|
-
textOverflow: "ellipsis",
|
|
339
|
-
whiteSpace: "nowrap"
|
|
340
|
-
},
|
|
341
|
-
children: (_b = error.url) != null ? _b : "--"
|
|
342
|
-
}
|
|
343
|
-
) })
|
|
344
|
-
}
|
|
345
|
-
),
|
|
346
|
-
/* @__PURE__ */ jsx("span", { style: { flex: "0 0 24px", width: 24 }, children: /* @__PURE__ */ jsx(Tooltip, { title: "关闭此条", children: /* @__PURE__ */ jsx(
|
|
347
|
-
Button,
|
|
348
|
-
{
|
|
349
|
-
"aria-label": "关闭此条",
|
|
350
|
-
size: "small",
|
|
351
|
-
style: { padding: 0, width: 24 },
|
|
352
|
-
type: "text",
|
|
353
|
-
onClick: handleRemove,
|
|
354
|
-
children: "×"
|
|
355
|
-
}
|
|
356
|
-
) }) })
|
|
357
|
-
]
|
|
358
|
-
}
|
|
359
|
-
),
|
|
360
|
-
/* @__PURE__ */ jsx(
|
|
361
|
-
"div",
|
|
362
|
-
{
|
|
363
|
-
style: {
|
|
364
|
-
display: "-webkit-box",
|
|
365
|
-
overflow: "hidden",
|
|
366
|
-
overflowWrap: "anywhere",
|
|
367
|
-
WebkitBoxOrient: "vertical",
|
|
368
|
-
WebkitLineClamp: 2
|
|
369
|
-
},
|
|
370
|
-
children: error.message
|
|
371
|
-
}
|
|
372
|
-
)
|
|
373
|
-
]
|
|
374
|
-
}
|
|
375
|
-
);
|
|
376
|
-
};
|
|
377
|
-
var debugTabKeys = ["request", "stackTrace", "mdc"];
|
|
378
|
-
var isDebugTabKey = (value) => debugTabKeys.includes(value);
|
|
379
|
-
var DebugErrorDetails = ({
|
|
380
|
-
error
|
|
381
|
-
}) => {
|
|
382
|
-
var _a, _b;
|
|
383
|
-
const [activeTab, setActiveTab] = useState("request");
|
|
384
|
-
const values = {
|
|
385
|
-
mdc: error.debug.mdc,
|
|
386
|
-
request: error.debug.request,
|
|
387
|
-
stackTrace: error.debug.stackTrace
|
|
388
|
-
};
|
|
389
|
-
const handleCopy = async (value) => {
|
|
390
|
-
if (value === void 0 || value === null) {
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
const copied = await copyDebugText(formatDebugValue(value));
|
|
394
|
-
if (copied) {
|
|
395
|
-
showFeedbackSuccessMessage("已复制");
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
showFeedbackErrorMessage("复制失败");
|
|
399
|
-
};
|
|
400
|
-
const handleCopyCompleteResponse = async () => {
|
|
401
|
-
const responseText = formatCompleteDebugResponse(error);
|
|
402
|
-
if (responseText === void 0) {
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
const copied = await copyDebugText(responseText);
|
|
406
|
-
if (copied) {
|
|
407
|
-
showFeedbackSuccessMessage("完整响应信息已复制");
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
showFeedbackErrorMessage("复制失败");
|
|
411
|
-
};
|
|
412
|
-
return /* @__PURE__ */ jsxs(
|
|
413
|
-
"div",
|
|
414
|
-
{
|
|
415
|
-
style: {
|
|
416
|
-
display: "flex",
|
|
417
|
-
flexDirection: "column",
|
|
418
|
-
height: "100%",
|
|
419
|
-
minHeight: 0,
|
|
420
|
-
minWidth: 0
|
|
421
|
-
},
|
|
422
|
-
children: [
|
|
423
|
-
/* @__PURE__ */ jsxs("div", { style: { flex: "0 0 auto", marginBottom: 16, minWidth: 0 }, children: [
|
|
424
|
-
/* @__PURE__ */ jsxs(
|
|
425
|
-
"div",
|
|
426
|
-
{
|
|
427
|
-
style: {
|
|
428
|
-
alignItems: "flex-start",
|
|
429
|
-
display: "flex",
|
|
430
|
-
gap: 8,
|
|
431
|
-
minWidth: 0
|
|
432
|
-
},
|
|
433
|
-
children: [
|
|
434
|
-
/* @__PURE__ */ jsx(
|
|
435
|
-
"strong",
|
|
436
|
-
{
|
|
437
|
-
style: {
|
|
438
|
-
display: "block",
|
|
439
|
-
flex: "1 1 auto",
|
|
440
|
-
fontSize: 16,
|
|
441
|
-
minWidth: 0,
|
|
442
|
-
overflowWrap: "anywhere"
|
|
443
|
-
},
|
|
444
|
-
children: error.message
|
|
445
|
-
}
|
|
446
|
-
),
|
|
447
|
-
error.responseData === void 0 ? null : /* @__PURE__ */ jsx(Tooltip, { title: "复制完整响应信息", children: /* @__PURE__ */ jsx(
|
|
448
|
-
Button,
|
|
449
|
-
{
|
|
450
|
-
"aria-label": "复制完整响应信息",
|
|
451
|
-
size: "middle",
|
|
452
|
-
style: { flex: "0 0 auto", paddingInline: 12 },
|
|
453
|
-
type: "primary",
|
|
454
|
-
onClick: () => {
|
|
455
|
-
void handleCopyCompleteResponse();
|
|
456
|
-
},
|
|
457
|
-
children: "复制完整响应"
|
|
458
|
-
}
|
|
459
|
-
) })
|
|
460
|
-
]
|
|
461
|
-
}
|
|
462
|
-
),
|
|
463
|
-
/* @__PURE__ */ jsxs(
|
|
464
|
-
"div",
|
|
465
|
-
{
|
|
466
|
-
style: {
|
|
467
|
-
alignItems: "center",
|
|
468
|
-
display: "flex",
|
|
469
|
-
gap: 8,
|
|
470
|
-
marginTop: 8,
|
|
471
|
-
minWidth: 0
|
|
472
|
-
},
|
|
473
|
-
children: [
|
|
474
|
-
/* @__PURE__ */ jsx(HttpMethodTag, { method: error.method }),
|
|
475
|
-
/* @__PURE__ */ jsx(
|
|
476
|
-
"code",
|
|
477
|
-
{
|
|
478
|
-
style: {
|
|
479
|
-
color: "var(--gz-color-text-secondary)",
|
|
480
|
-
display: "block",
|
|
481
|
-
minWidth: 0,
|
|
482
|
-
overflow: "hidden",
|
|
483
|
-
textOverflow: "ellipsis",
|
|
484
|
-
whiteSpace: "nowrap"
|
|
485
|
-
},
|
|
486
|
-
title: (_a = error.url) != null ? _a : "--",
|
|
487
|
-
children: (_b = error.url) != null ? _b : "--"
|
|
488
|
-
}
|
|
489
|
-
)
|
|
490
|
-
]
|
|
491
|
-
}
|
|
492
|
-
)
|
|
493
|
-
] }),
|
|
494
|
-
/* @__PURE__ */ jsx(
|
|
495
|
-
Tabs,
|
|
496
|
-
{
|
|
497
|
-
activeKey: activeTab,
|
|
498
|
-
items: [
|
|
499
|
-
{
|
|
500
|
-
children: /* @__PURE__ */ jsx(
|
|
501
|
-
DebugCodeBlock,
|
|
502
|
-
{
|
|
503
|
-
onCopy: () => {
|
|
504
|
-
void handleCopy(values.request);
|
|
505
|
-
},
|
|
506
|
-
value: values.request
|
|
507
|
-
}
|
|
508
|
-
),
|
|
509
|
-
key: "request",
|
|
510
|
-
label: "Request"
|
|
511
|
-
},
|
|
512
|
-
{
|
|
513
|
-
children: /* @__PURE__ */ jsx(
|
|
514
|
-
DebugCodeBlock,
|
|
515
|
-
{
|
|
516
|
-
onCopy: () => {
|
|
517
|
-
void handleCopy(values.stackTrace);
|
|
518
|
-
},
|
|
519
|
-
value: values.stackTrace
|
|
520
|
-
}
|
|
521
|
-
),
|
|
522
|
-
key: "stackTrace",
|
|
523
|
-
label: "Stack Trace"
|
|
524
|
-
},
|
|
525
|
-
{
|
|
526
|
-
children: /* @__PURE__ */ jsx(
|
|
527
|
-
DebugCodeBlock,
|
|
528
|
-
{
|
|
529
|
-
onCopy: () => {
|
|
530
|
-
void handleCopy(values.mdc);
|
|
531
|
-
},
|
|
532
|
-
value: values.mdc
|
|
533
|
-
}
|
|
534
|
-
),
|
|
535
|
-
key: "mdc",
|
|
536
|
-
label: "MDC"
|
|
537
|
-
}
|
|
538
|
-
],
|
|
539
|
-
style: {
|
|
540
|
-
display: "flex",
|
|
541
|
-
flexDirection: "column",
|
|
542
|
-
height: "100%",
|
|
543
|
-
minHeight: 0
|
|
544
|
-
},
|
|
545
|
-
onChange: (key) => {
|
|
546
|
-
if (isDebugTabKey(key)) {
|
|
547
|
-
setActiveTab(key);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
)
|
|
552
|
-
]
|
|
553
|
-
}
|
|
554
|
-
);
|
|
555
|
-
};
|
|
556
|
-
var DebugErrorDrawer = () => {
|
|
557
|
-
var _a, _b;
|
|
558
|
-
const hostIdRef = useRef(void 0);
|
|
559
|
-
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-debug-feedback-drawer-host");
|
|
560
|
-
const hostId = hostIdRef.current;
|
|
561
|
-
const snapshot3 = useSyncExternalStore(
|
|
562
|
-
subscribeDebugDrawer,
|
|
563
|
-
getDebugDrawerSnapshot,
|
|
564
|
-
getDebugDrawerServerSnapshot
|
|
565
|
-
);
|
|
566
|
-
useEffect(() => registerDebugDrawerHost(hostId), [hostId]);
|
|
567
|
-
if (snapshot3.activeHostId !== hostId) {
|
|
568
|
-
return null;
|
|
569
|
-
}
|
|
570
|
-
const selectedError = (_b = snapshot3.errors.find((error) => error.id === snapshot3.selectedErrorId)) != null ? _b : snapshot3.errors[0];
|
|
571
|
-
return /* @__PURE__ */ jsx(
|
|
572
|
-
Drawer,
|
|
573
|
-
{
|
|
574
|
-
open: snapshot3.open,
|
|
575
|
-
placement: "right",
|
|
576
|
-
styles: { body: { overflow: "hidden", padding: 0 } },
|
|
577
|
-
title: `Debug Error (${snapshot3.errors.length})`,
|
|
578
|
-
extra: /* @__PURE__ */ jsx(
|
|
579
|
-
Button,
|
|
580
|
-
{
|
|
581
|
-
disabled: snapshot3.errors.length === 0,
|
|
582
|
-
size: "middle",
|
|
583
|
-
style: { paddingInline: 12 },
|
|
584
|
-
type: "default",
|
|
585
|
-
onClick: clearDebugErrors,
|
|
586
|
-
children: "清空记录"
|
|
587
|
-
}
|
|
588
|
-
),
|
|
589
|
-
width: "min(calc(100vw - 32px), clamp(720px, 80vw, 1120px))",
|
|
590
|
-
onClose: closeDebugDrawer,
|
|
591
|
-
children: /* @__PURE__ */ jsxs(
|
|
592
|
-
"div",
|
|
593
|
-
{
|
|
594
|
-
style: {
|
|
595
|
-
display: "flex",
|
|
596
|
-
height: "100%",
|
|
597
|
-
minHeight: 0,
|
|
598
|
-
minWidth: 0
|
|
599
|
-
},
|
|
600
|
-
children: [
|
|
601
|
-
/* @__PURE__ */ jsx(
|
|
602
|
-
"aside",
|
|
603
|
-
{
|
|
604
|
-
"aria-label": "Debug Error 列表",
|
|
605
|
-
style: {
|
|
606
|
-
borderRight: "1px solid var(--gz-color-border, rgba(127, 127, 127, 0.24))",
|
|
607
|
-
flex: "0 1 clamp(220px, 24vw, 320px)",
|
|
608
|
-
minHeight: 0,
|
|
609
|
-
overflowY: "auto",
|
|
610
|
-
padding: "6px 0",
|
|
611
|
-
width: "clamp(220px, 24vw, 320px)"
|
|
612
|
-
},
|
|
613
|
-
children: snapshot3.errors.length > 0 ? snapshot3.errors.map((error, index) => /* @__PURE__ */ jsx(
|
|
614
|
-
DebugErrorListItem,
|
|
615
|
-
{
|
|
616
|
-
error,
|
|
617
|
-
index,
|
|
618
|
-
selected: error.id === (selectedError == null ? void 0 : selectedError.id),
|
|
619
|
-
total: snapshot3.errors.length
|
|
620
|
-
},
|
|
621
|
-
error.id
|
|
622
|
-
)) : /* @__PURE__ */ jsx(
|
|
623
|
-
"div",
|
|
624
|
-
{
|
|
625
|
-
style: {
|
|
626
|
-
color: "var(--gz-color-text-secondary)",
|
|
627
|
-
padding: 16,
|
|
628
|
-
textAlign: "center"
|
|
629
|
-
},
|
|
630
|
-
children: "暂无 Debug Error"
|
|
631
|
-
}
|
|
632
|
-
)
|
|
633
|
-
}
|
|
634
|
-
),
|
|
635
|
-
/* @__PURE__ */ jsx(
|
|
636
|
-
"main",
|
|
637
|
-
{
|
|
638
|
-
"aria-label": "Debug Error 详情",
|
|
639
|
-
style: {
|
|
640
|
-
flex: "1 1 auto",
|
|
641
|
-
minHeight: 0,
|
|
642
|
-
minWidth: 0,
|
|
643
|
-
overflow: "hidden",
|
|
644
|
-
padding: 20
|
|
645
|
-
},
|
|
646
|
-
children: selectedError ? /* @__PURE__ */ jsx(DebugErrorDetails, { error: selectedError }, selectedError.id) : /* @__PURE__ */ jsx("div", { style: { color: "var(--gz-color-text-secondary)" }, children: "暂无 Debug Error" })
|
|
647
|
-
}
|
|
648
|
-
)
|
|
649
|
-
]
|
|
650
|
-
}
|
|
651
|
-
)
|
|
652
|
-
}
|
|
653
|
-
);
|
|
654
|
-
};
|
|
655
|
-
DebugErrorDrawer.displayName = "DebugErrorDrawer";
|
|
656
|
-
var DebugErrorDrawer_default = DebugErrorDrawer;
|
|
657
|
-
var GzDebugFeedbackProvider = ({ children }) => {
|
|
658
|
-
var _a;
|
|
659
|
-
const hostIdRef = useRef(void 0);
|
|
660
|
-
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-debug-feedback-host");
|
|
661
|
-
const hostId = hostIdRef.current;
|
|
662
|
-
const [messageApi, messageContextHolder] = message.useMessage();
|
|
663
|
-
const showErrorMessage = useCallback(
|
|
664
|
-
(content) => {
|
|
665
|
-
void messageApi.error(content);
|
|
666
|
-
},
|
|
667
|
-
[messageApi]
|
|
668
|
-
);
|
|
669
|
-
const showSuccessMessage = useCallback(
|
|
670
|
-
(content) => {
|
|
671
|
-
void messageApi.success(content);
|
|
672
|
-
},
|
|
673
|
-
[messageApi]
|
|
674
|
-
);
|
|
675
|
-
useEffect(
|
|
676
|
-
() => registerFeedbackHost(hostId, { showErrorMessage, showSuccessMessage }),
|
|
677
|
-
[hostId, showErrorMessage, showSuccessMessage]
|
|
678
|
-
);
|
|
679
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
680
|
-
messageContextHolder,
|
|
681
|
-
/* @__PURE__ */ jsx(DebugErrorDrawer_default, {}),
|
|
682
|
-
children
|
|
683
|
-
] });
|
|
684
|
-
};
|
|
685
|
-
GzDebugFeedbackProvider.displayName = "GzDebugFeedbackProvider";
|
|
686
|
-
var GzDebugFeedbackProvider_default = GzDebugFeedbackProvider;
|
|
687
|
-
|
|
688
|
-
// src/fetch/feedback/report-debug-error.ts
|
|
689
|
-
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
690
|
-
var getDebugInfo = (value) => isRecord(value) ? value : void 0;
|
|
691
|
-
var getResponseDebugInfo = (responseData) => isRecord(responseData) ? getDebugInfo(responseData.debug) : void 0;
|
|
692
|
-
var isDebugEnabled = () => {
|
|
693
|
-
if (typeof window === "undefined") {
|
|
694
|
-
return false;
|
|
695
|
-
}
|
|
696
|
-
try {
|
|
697
|
-
if (new URLSearchParams(window.location.search).get("showDebug") === "1") {
|
|
698
|
-
return true;
|
|
699
|
-
}
|
|
700
|
-
} catch (e) {
|
|
701
|
-
}
|
|
702
|
-
try {
|
|
703
|
-
return window.localStorage.getItem("showDebug") === "1";
|
|
704
|
-
} catch (e) {
|
|
705
|
-
return false;
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
var reportDebugError = (input) => {
|
|
709
|
-
const debug = getDebugInfo(input.debug);
|
|
710
|
-
if (debug === void 0 || !isDebugEnabled()) {
|
|
711
|
-
return false;
|
|
712
|
-
}
|
|
713
|
-
return appendDebugError({ ...input, debug });
|
|
714
|
-
};
|
|
715
8
|
var GzFetchError = class extends Error {
|
|
716
9
|
constructor(message3, options) {
|
|
717
10
|
super(message3);
|
|
@@ -773,6 +66,28 @@ function toGzFetchError(error) {
|
|
|
773
66
|
originalError: error
|
|
774
67
|
});
|
|
775
68
|
}
|
|
69
|
+
var feedbackHosts = /* @__PURE__ */ new Map();
|
|
70
|
+
var activeHostId;
|
|
71
|
+
var registerFeedbackHost = (hostId, host) => {
|
|
72
|
+
feedbackHosts.set(hostId, host);
|
|
73
|
+
activeHostId != null ? activeHostId : activeHostId = hostId;
|
|
74
|
+
return () => {
|
|
75
|
+
feedbackHosts.delete(hostId);
|
|
76
|
+
if (activeHostId !== hostId) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const nextHost = feedbackHosts.keys().next();
|
|
80
|
+
activeHostId = nextHost.done ? void 0 : nextHost.value;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
var showFetchErrorMessage = (content) => {
|
|
84
|
+
const activeHost = activeHostId === void 0 ? void 0 : feedbackHosts.get(activeHostId);
|
|
85
|
+
if (activeHost) {
|
|
86
|
+
activeHost.showErrorMessage(content);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
message.error(content);
|
|
90
|
+
};
|
|
776
91
|
|
|
777
92
|
// src/fetch/middleware.ts
|
|
778
93
|
async function runRequestMiddlewares(initialConfig, middlewares) {
|
|
@@ -799,23 +114,64 @@ async function runErrorMiddlewares(error, context, middlewares) {
|
|
|
799
114
|
await ((_a = middleware.onError) == null ? void 0 : _a.call(middleware, error, context));
|
|
800
115
|
}
|
|
801
116
|
}
|
|
117
|
+
var JSON_TOKENS = /"(?:\\[\s\S]|[^"\\])*"|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/g;
|
|
118
|
+
function parseNumber(value) {
|
|
119
|
+
const number = Number(value);
|
|
120
|
+
return isSafeNumber(value) && (!Number.isInteger(number) || Number.isSafeInteger(number)) ? number : value;
|
|
121
|
+
}
|
|
122
|
+
var transformResponsePreservingNumbers = function(data, headers, status) {
|
|
123
|
+
if (typeof data !== "string" || data.length === 0 || this.responseType !== void 0 && this.responseType !== "json") {
|
|
124
|
+
return data;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const preservedNumbers = /* @__PURE__ */ new Set();
|
|
128
|
+
parse(data, void 0, {
|
|
129
|
+
parseNumber(value) {
|
|
130
|
+
const parsed = parseNumber(value);
|
|
131
|
+
if (typeof parsed === "string") {
|
|
132
|
+
preservedNumbers.add(value);
|
|
133
|
+
}
|
|
134
|
+
return parsed;
|
|
135
|
+
},
|
|
136
|
+
onDuplicateKey: ({ newValue }) => newValue
|
|
137
|
+
});
|
|
138
|
+
const protectedJson = data.replace(
|
|
139
|
+
JSON_TOKENS,
|
|
140
|
+
(token) => preservedNumbers.has(token) ? JSON.stringify(token) : token
|
|
141
|
+
);
|
|
142
|
+
return JSON.parse(protectedJson);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (!(error instanceof SyntaxError)) {
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const defaults = axios.defaults.transformResponse;
|
|
149
|
+
const transformers = Array.isArray(defaults) ? defaults : [defaults];
|
|
150
|
+
let result = data;
|
|
151
|
+
for (const transform of transformers) {
|
|
152
|
+
if (transform) {
|
|
153
|
+
result = transform.call(this, result, headers, status);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
};
|
|
802
158
|
|
|
803
159
|
// src/fetch/unauthorized.ts
|
|
804
160
|
var DEFAULT_UNAUTHORIZED_LOGIN_URL = "/login";
|
|
805
161
|
var DEFAULT_UNAUTHORIZED_MODAL_TITLE = "登录失效";
|
|
806
162
|
var DEFAULT_UNAUTHORIZED_MODAL_MESSAGE = "当前登录状态已失效,请重新登录。";
|
|
807
163
|
var IDLE_SNAPSHOT = { phase: "idle" };
|
|
808
|
-
var
|
|
809
|
-
var
|
|
164
|
+
var snapshot = IDLE_SNAPSHOT;
|
|
165
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
810
166
|
var modalHosts = /* @__PURE__ */ new Set();
|
|
811
|
-
var
|
|
812
|
-
for (const listener of
|
|
167
|
+
var emitChange = () => {
|
|
168
|
+
for (const listener of listeners) {
|
|
813
169
|
listener();
|
|
814
170
|
}
|
|
815
171
|
};
|
|
816
|
-
var
|
|
817
|
-
|
|
818
|
-
|
|
172
|
+
var setSnapshot = (nextSnapshot) => {
|
|
173
|
+
snapshot = nextSnapshot;
|
|
174
|
+
emitChange();
|
|
819
175
|
};
|
|
820
176
|
var resolveUnauthorizedOptions = (options) => {
|
|
821
177
|
var _a, _b, _c, _d;
|
|
@@ -827,66 +183,66 @@ var resolveUnauthorizedOptions = (options) => {
|
|
|
827
183
|
...(options == null ? void 0 : options.onUnauthorized) === void 0 ? {} : { onUnauthorized: options.onUnauthorized }
|
|
828
184
|
};
|
|
829
185
|
};
|
|
830
|
-
var getUnauthorizedSnapshot = () =>
|
|
186
|
+
var getUnauthorizedSnapshot = () => snapshot;
|
|
831
187
|
var getUnauthorizedServerSnapshot = () => IDLE_SNAPSHOT;
|
|
832
188
|
var subscribeUnauthorized = (listener) => {
|
|
833
|
-
|
|
834
|
-
return () =>
|
|
189
|
+
listeners.add(listener);
|
|
190
|
+
return () => listeners.delete(listener);
|
|
835
191
|
};
|
|
836
192
|
var registerUnauthorizedModalHost = (hostId) => {
|
|
837
193
|
modalHosts.add(hostId);
|
|
838
|
-
if (
|
|
839
|
-
|
|
194
|
+
if (snapshot.activeHostId === void 0) {
|
|
195
|
+
setSnapshot({ ...snapshot, activeHostId: hostId });
|
|
840
196
|
}
|
|
841
197
|
return () => {
|
|
842
198
|
modalHosts.delete(hostId);
|
|
843
|
-
if (
|
|
199
|
+
if (snapshot.activeHostId !== hostId) {
|
|
844
200
|
return;
|
|
845
201
|
}
|
|
846
202
|
const nextHost = modalHosts.values().next();
|
|
847
203
|
const nextHostId = nextHost.done ? void 0 : nextHost.value;
|
|
848
|
-
if (
|
|
849
|
-
|
|
204
|
+
if (snapshot.phase === "closing") {
|
|
205
|
+
setSnapshot(
|
|
850
206
|
nextHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: nextHostId, phase: "idle" }
|
|
851
207
|
);
|
|
852
208
|
return;
|
|
853
209
|
}
|
|
854
210
|
if (nextHostId === void 0) {
|
|
855
|
-
|
|
856
|
-
|
|
211
|
+
setSnapshot(
|
|
212
|
+
snapshot.options === void 0 ? { phase: snapshot.phase } : { options: snapshot.options, phase: snapshot.phase }
|
|
857
213
|
);
|
|
858
214
|
return;
|
|
859
215
|
}
|
|
860
|
-
|
|
216
|
+
setSnapshot({ ...snapshot, activeHostId: nextHostId });
|
|
861
217
|
};
|
|
862
218
|
};
|
|
863
219
|
var openUnauthorizedModal = (options) => {
|
|
864
|
-
if (!options.enabled ||
|
|
220
|
+
if (!options.enabled || snapshot.phase !== "idle") {
|
|
865
221
|
return false;
|
|
866
222
|
}
|
|
867
|
-
|
|
868
|
-
...
|
|
223
|
+
setSnapshot({
|
|
224
|
+
...snapshot.activeHostId === void 0 ? {} : { activeHostId: snapshot.activeHostId },
|
|
869
225
|
options,
|
|
870
226
|
phase: "open"
|
|
871
227
|
});
|
|
872
228
|
return true;
|
|
873
229
|
};
|
|
874
230
|
var beginCloseUnauthorizedModal = () => {
|
|
875
|
-
if (
|
|
231
|
+
if (snapshot.phase !== "open" || snapshot.options === void 0) {
|
|
876
232
|
return void 0;
|
|
877
233
|
}
|
|
878
|
-
const { options } =
|
|
879
|
-
|
|
234
|
+
const { options } = snapshot;
|
|
235
|
+
setSnapshot({ ...snapshot, phase: "closing" });
|
|
880
236
|
return options;
|
|
881
237
|
};
|
|
882
238
|
var cancelUnauthorizedModal = () => beginCloseUnauthorizedModal() !== void 0;
|
|
883
239
|
var confirmUnauthorizedModal = () => beginCloseUnauthorizedModal();
|
|
884
240
|
var completeUnauthorizedModal = () => {
|
|
885
|
-
if (
|
|
241
|
+
if (snapshot.phase !== "closing") {
|
|
886
242
|
return;
|
|
887
243
|
}
|
|
888
|
-
|
|
889
|
-
|
|
244
|
+
setSnapshot(
|
|
245
|
+
snapshot.activeHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: snapshot.activeHostId, phase: "idle" }
|
|
890
246
|
);
|
|
891
247
|
};
|
|
892
248
|
var executeUnauthorizedAction = (options, navigate = (loginUrl) => window.location.assign(loginUrl)) => {
|
|
@@ -920,7 +276,8 @@ function createGzFetch(options = {}) {
|
|
|
920
276
|
const instance = axios.create({
|
|
921
277
|
...options.baseURL === void 0 ? {} : { baseURL: options.baseURL },
|
|
922
278
|
timeout: (_g = options.timeout) != null ? _g : DEFAULT_TIMEOUT,
|
|
923
|
-
validateStatus: (_h = options.validateStatus) != null ? _h : DEFAULT_VALIDATE_STATUS
|
|
279
|
+
validateStatus: (_h = options.validateStatus) != null ? _h : DEFAULT_VALIDATE_STATUS,
|
|
280
|
+
...options.preserveNumberPrecision ? { transformResponse: [transformResponsePreservingNumbers] } : {}
|
|
924
281
|
});
|
|
925
282
|
async function request(initialConfig) {
|
|
926
283
|
var _a2;
|
|
@@ -965,16 +322,7 @@ function createGzFetch(options = {}) {
|
|
|
965
322
|
await runErrorMiddlewares(error, { config: currentConfig }, middlewares);
|
|
966
323
|
const shouldShowError = (_a2 = currentConfig.showErrorMessage) != null ? _a2 : showInstanceErrorMessage;
|
|
967
324
|
if (shouldShowError && error.type !== "CANCELED_ERROR" && !shouldHandleUnauthorized) {
|
|
968
|
-
|
|
969
|
-
debug: getResponseDebugInfo(error.responseData),
|
|
970
|
-
message: error.message,
|
|
971
|
-
method: currentConfig.method,
|
|
972
|
-
responseData: error.responseData,
|
|
973
|
-
url: currentConfig.url
|
|
974
|
-
}) : false;
|
|
975
|
-
if (!didShowDebugError) {
|
|
976
|
-
showFeedbackErrorMessage(error.message);
|
|
977
|
-
}
|
|
325
|
+
showFetchErrorMessage(error.message);
|
|
978
326
|
}
|
|
979
327
|
throw error;
|
|
980
328
|
}
|
|
@@ -1009,18 +357,18 @@ async function gzFetch(config) {
|
|
|
1009
357
|
}
|
|
1010
358
|
return defaultClient(config);
|
|
1011
359
|
}
|
|
1012
|
-
var
|
|
360
|
+
var GzFetchUnauthorizedModal = () => {
|
|
1013
361
|
var _a, _b, _c;
|
|
1014
362
|
const hostIdRef = useRef(void 0);
|
|
1015
363
|
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-unauthorized-modal-host");
|
|
1016
364
|
const hostId = hostIdRef.current;
|
|
1017
|
-
const
|
|
365
|
+
const snapshot2 = useSyncExternalStore(
|
|
1018
366
|
subscribeUnauthorized,
|
|
1019
367
|
getUnauthorizedSnapshot,
|
|
1020
368
|
getUnauthorizedServerSnapshot
|
|
1021
369
|
);
|
|
1022
370
|
useEffect(() => registerUnauthorizedModalHost(hostId), [hostId]);
|
|
1023
|
-
if (
|
|
371
|
+
if (snapshot2.activeHostId !== hostId) {
|
|
1024
372
|
return null;
|
|
1025
373
|
}
|
|
1026
374
|
const handleConfirm = () => {
|
|
@@ -1036,24 +384,39 @@ var GzFetchUnauthorizedModalContent = () => {
|
|
|
1036
384
|
cancelText: "取消",
|
|
1037
385
|
closable: true,
|
|
1038
386
|
okText: "重新登录",
|
|
1039
|
-
open:
|
|
1040
|
-
title: (_b =
|
|
387
|
+
open: snapshot2.phase === "open",
|
|
388
|
+
title: (_b = snapshot2.options) == null ? void 0 : _b.modalTitle,
|
|
1041
389
|
onCancel: cancelUnauthorizedModal,
|
|
1042
390
|
onOk: handleConfirm,
|
|
1043
|
-
children: (_c =
|
|
391
|
+
children: (_c = snapshot2.options) == null ? void 0 : _c.modalMessage
|
|
1044
392
|
}
|
|
1045
393
|
);
|
|
1046
394
|
};
|
|
1047
|
-
GzFetchUnauthorizedModalContent.displayName = "GzFetchUnauthorizedModalContent";
|
|
1048
|
-
var GzFetchUnauthorizedModalContent_default = GzFetchUnauthorizedModalContent;
|
|
1049
|
-
var GzFetchFeedbackProvider = ({ children }) => /* @__PURE__ */ jsxs(GzDebugFeedbackProvider_default, { children: [
|
|
1050
|
-
/* @__PURE__ */ jsx(GzFetchUnauthorizedModalContent_default, {}),
|
|
1051
|
-
children
|
|
1052
|
-
] });
|
|
1053
|
-
GzFetchFeedbackProvider.displayName = "GzFetchFeedbackProvider";
|
|
1054
|
-
var GzFetchFeedbackProvider_default = GzFetchFeedbackProvider;
|
|
1055
|
-
var GzFetchUnauthorizedModal = () => /* @__PURE__ */ jsx(GzFetchUnauthorizedModalContent_default, {});
|
|
1056
395
|
GzFetchUnauthorizedModal.displayName = "GzFetchUnauthorizedModal";
|
|
1057
396
|
var GzFetchUnauthorizedModal_default = GzFetchUnauthorizedModal;
|
|
397
|
+
var GzFetchFeedbackProvider = ({ children }) => {
|
|
398
|
+
var _a;
|
|
399
|
+
const hostIdRef = useRef(void 0);
|
|
400
|
+
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-feedback-host");
|
|
401
|
+
const hostId = hostIdRef.current;
|
|
402
|
+
const [messageApi, messageContextHolder] = message.useMessage();
|
|
403
|
+
const showErrorMessage = useCallback(
|
|
404
|
+
(content) => {
|
|
405
|
+
void messageApi.error(content);
|
|
406
|
+
},
|
|
407
|
+
[messageApi]
|
|
408
|
+
);
|
|
409
|
+
useEffect(
|
|
410
|
+
() => registerFeedbackHost(hostId, { showErrorMessage }),
|
|
411
|
+
[hostId, showErrorMessage]
|
|
412
|
+
);
|
|
413
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
414
|
+
messageContextHolder,
|
|
415
|
+
/* @__PURE__ */ jsx(GzFetchUnauthorizedModal_default, {}),
|
|
416
|
+
children
|
|
417
|
+
] });
|
|
418
|
+
};
|
|
419
|
+
GzFetchFeedbackProvider.displayName = "GzFetchFeedbackProvider";
|
|
420
|
+
var GzFetchFeedbackProvider_default = GzFetchFeedbackProvider;
|
|
1058
421
|
|
|
1059
|
-
export {
|
|
422
|
+
export { GzFetchError, GzFetchFeedbackProvider_default as GzFetchFeedbackProvider, GzFetchUnauthorizedModal_default as GzFetchUnauthorizedModal, configureGzFetch, createGzFetch, getResponseMessage, gzFetch, toGzFetchError };
|