vue-api-request-builder 0.1.0 → 0.2.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/dist/index.d.ts +8 -2
- package/dist/index.es.js +427 -302
- package/dist/index.umd.js +5 -5
- package/dist/vue-api-request-builder.css +1 -1
- package/lib/index.ts +2 -0
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -24,9 +24,9 @@ export declare const defaultRequestSchema: RequestSchema;
|
|
|
24
24
|
|
|
25
25
|
export declare function executeRequest(schema: RequestSchema, method?: RequestMethod): Promise<ResponseData>;
|
|
26
26
|
|
|
27
|
-
export declare const KeyValueInput: DefineComponent<
|
|
27
|
+
export declare const KeyValueInput: DefineComponent<Props_3, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
|
|
28
28
|
"update:modelValue": (value: KeyValueItem[]) => any;
|
|
29
|
-
}, string, PublicProps, Readonly<
|
|
29
|
+
}, string, PublicProps, Readonly<Props_3> & Readonly<{
|
|
30
30
|
"onUpdate:modelValue"?: ((value: KeyValueItem[]) => any) | undefined;
|
|
31
31
|
}>, {
|
|
32
32
|
addButtonText: string;
|
|
@@ -49,6 +49,10 @@ declare interface Props {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
declare interface Props_2 {
|
|
52
|
+
modelValue: RequestSchema;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare interface Props_3 {
|
|
52
56
|
modelValue: KeyValueItem[];
|
|
53
57
|
addButtonText?: string;
|
|
54
58
|
showPreview?: boolean;
|
|
@@ -81,4 +85,6 @@ export declare interface ResponseData {
|
|
|
81
85
|
timing?: number;
|
|
82
86
|
}
|
|
83
87
|
|
|
88
|
+
export declare const ResponseSection: DefineComponent<Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<Props_2> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
89
|
+
|
|
84
90
|
export { }
|
package/dist/index.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
const
|
|
1
|
+
import { defineComponent as H, ref as w, watch as C, resolveComponent as c, createElementBlock as $, openBlock as _, createElementVNode as p, createCommentVNode as R, createBlock as O, createVNode as s, withCtx as r, createTextVNode as b, toDisplayString as z, Fragment as F, renderList as K, computed as J } from "vue";
|
|
2
|
+
const le = { class: "key-value-input flex flex-col gap-1" }, se = { class: "flex gap-2" }, ne = {
|
|
3
3
|
key: 0,
|
|
4
4
|
class: "flex flex-col gap-1"
|
|
5
|
-
}, ue = { class: "flex w-full gap-1 items-center" }, re = /* @__PURE__ */
|
|
5
|
+
}, ue = { class: "flex w-full gap-1 items-center" }, re = /* @__PURE__ */ H({
|
|
6
6
|
__name: "KeyValueInput",
|
|
7
7
|
props: {
|
|
8
8
|
modelValue: {},
|
|
@@ -11,59 +11,59 @@ const oe = { class: "key-value-input flex flex-col gap-1" }, se = { class: "flex
|
|
|
11
11
|
previewText: { default: "" }
|
|
12
12
|
},
|
|
13
13
|
emits: ["update:modelValue"],
|
|
14
|
-
setup(
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
() =>
|
|
18
|
-
(
|
|
19
|
-
n.value =
|
|
14
|
+
setup(a, { emit: g }) {
|
|
15
|
+
const d = a, o = g, n = w(d.modelValue);
|
|
16
|
+
C(
|
|
17
|
+
() => d.modelValue,
|
|
18
|
+
(u) => {
|
|
19
|
+
n.value = u;
|
|
20
20
|
}
|
|
21
|
-
),
|
|
21
|
+
), C(
|
|
22
22
|
n,
|
|
23
|
-
(
|
|
24
|
-
|
|
23
|
+
(u) => {
|
|
24
|
+
o("update:modelValue", u);
|
|
25
25
|
},
|
|
26
26
|
{ deep: !0 }
|
|
27
27
|
);
|
|
28
|
-
const
|
|
28
|
+
const y = () => {
|
|
29
29
|
n.value.push({ key: "", value: "" });
|
|
30
|
-
},
|
|
31
|
-
n.value.splice(
|
|
32
|
-
},
|
|
30
|
+
}, l = (u) => {
|
|
31
|
+
n.value.splice(u, 1);
|
|
32
|
+
}, f = () => {
|
|
33
33
|
n.value = [];
|
|
34
34
|
};
|
|
35
|
-
return (
|
|
36
|
-
const
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
return (u, t) => {
|
|
36
|
+
const v = c("a-button"), x = c("a-popconfirm"), j = c("a-input"), B = c("a-typography-paragraph"), U = c("a-typography");
|
|
37
|
+
return _(), $("div", le, [
|
|
38
|
+
p("div", se, [
|
|
39
|
+
s(v, {
|
|
40
40
|
type: "primary",
|
|
41
|
-
onClick:
|
|
41
|
+
onClick: y,
|
|
42
42
|
class: "w-40 max-w-full",
|
|
43
43
|
size: "small"
|
|
44
44
|
}, {
|
|
45
|
-
default:
|
|
46
|
-
|
|
45
|
+
default: r(() => [
|
|
46
|
+
b(z(u.addButtonText), 1)
|
|
47
47
|
]),
|
|
48
48
|
_: 1
|
|
49
49
|
}),
|
|
50
|
-
|
|
50
|
+
s(x, {
|
|
51
51
|
title: "确认清空",
|
|
52
52
|
description: "确定要清空所有参数吗?",
|
|
53
53
|
"ok-text": "确认",
|
|
54
54
|
"cancel-text": "取消",
|
|
55
|
-
onConfirm:
|
|
55
|
+
onConfirm: f
|
|
56
56
|
}, {
|
|
57
|
-
default:
|
|
58
|
-
|
|
57
|
+
default: r(() => [
|
|
58
|
+
s(v, {
|
|
59
59
|
type: "primary",
|
|
60
60
|
danger: "",
|
|
61
61
|
class: "w-40 max-w-full",
|
|
62
62
|
size: "small",
|
|
63
63
|
disabled: n.value.length === 0
|
|
64
64
|
}, {
|
|
65
|
-
default:
|
|
66
|
-
|
|
65
|
+
default: r(() => t[0] || (t[0] = [
|
|
66
|
+
b(" 清空 ")
|
|
67
67
|
])),
|
|
68
68
|
_: 1
|
|
69
69
|
}, 8, ["disabled"])
|
|
@@ -71,64 +71,64 @@ const oe = { class: "key-value-input flex flex-col gap-1" }, se = { class: "flex
|
|
|
71
71
|
_: 1
|
|
72
72
|
})
|
|
73
73
|
]),
|
|
74
|
-
n.value.length > 0 ? (
|
|
75
|
-
(
|
|
74
|
+
n.value.length > 0 ? (_(), $("div", ne, [
|
|
75
|
+
(_(!0), $(F, null, K(n.value, (k, S) => (_(), $("div", {
|
|
76
76
|
key: S,
|
|
77
77
|
class: "flex"
|
|
78
78
|
}, [
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
p("div", ue, [
|
|
80
|
+
s(v, {
|
|
81
81
|
type: "primary",
|
|
82
82
|
danger: "",
|
|
83
|
-
onClick: (
|
|
83
|
+
onClick: (h) => l(S),
|
|
84
84
|
class: "w-16",
|
|
85
85
|
size: "small"
|
|
86
86
|
}, {
|
|
87
|
-
default:
|
|
88
|
-
|
|
87
|
+
default: r(() => t[1] || (t[1] = [
|
|
88
|
+
b(" 删除 ")
|
|
89
89
|
])),
|
|
90
90
|
_: 2
|
|
91
91
|
}, 1032, ["onClick"]),
|
|
92
|
-
|
|
92
|
+
s(j, {
|
|
93
93
|
value: k.key,
|
|
94
|
-
"onUpdate:value": (
|
|
94
|
+
"onUpdate:value": (h) => k.key = h,
|
|
95
95
|
placeholder: "键",
|
|
96
96
|
style: { width: "60%" },
|
|
97
97
|
size: "small"
|
|
98
98
|
}, null, 8, ["value", "onUpdate:value"]),
|
|
99
|
-
|
|
99
|
+
s(j, {
|
|
100
100
|
value: k.value,
|
|
101
|
-
"onUpdate:value": (
|
|
101
|
+
"onUpdate:value": (h) => k.value = h,
|
|
102
102
|
placeholder: "值",
|
|
103
103
|
style: { width: "100%" },
|
|
104
104
|
size: "small"
|
|
105
105
|
}, null, 8, ["value", "onUpdate:value"])
|
|
106
106
|
])
|
|
107
107
|
]))), 128))
|
|
108
|
-
])) :
|
|
109
|
-
|
|
108
|
+
])) : R("", !0),
|
|
109
|
+
u.showPreview ? (_(), O(U, {
|
|
110
110
|
key: 1,
|
|
111
111
|
class: "m-0"
|
|
112
112
|
}, {
|
|
113
|
-
default:
|
|
114
|
-
|
|
115
|
-
default:
|
|
116
|
-
|
|
113
|
+
default: r(() => [
|
|
114
|
+
s(B, { class: "!m-0" }, {
|
|
115
|
+
default: r(() => [
|
|
116
|
+
p("pre", null, z(u.previewText), 1)
|
|
117
117
|
]),
|
|
118
118
|
_: 1
|
|
119
119
|
})
|
|
120
120
|
]),
|
|
121
121
|
_: 1
|
|
122
|
-
})) :
|
|
122
|
+
})) : R("", !0)
|
|
123
123
|
]);
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
|
-
}),
|
|
127
|
-
const
|
|
128
|
-
for (const [
|
|
129
|
-
|
|
130
|
-
return
|
|
131
|
-
},
|
|
126
|
+
}), M = (a, g) => {
|
|
127
|
+
const d = a.__vccOpts || a;
|
|
128
|
+
for (const [o, n] of g)
|
|
129
|
+
d[o] = n;
|
|
130
|
+
return d;
|
|
131
|
+
}, L = /* @__PURE__ */ M(re, [["__scopeId", "data-v-1e5ef051"]]), de = {
|
|
132
132
|
method: "GET",
|
|
133
133
|
url: "https://yesno.wtf",
|
|
134
134
|
path: "/api",
|
|
@@ -140,61 +140,61 @@ const oe = { class: "key-value-input flex flex-col gap-1" }, se = { class: "flex
|
|
|
140
140
|
body: {
|
|
141
141
|
type: "application/json"
|
|
142
142
|
}
|
|
143
|
-
},
|
|
143
|
+
}, ie = { class: "request-form" }, pe = { class: "flex flex-col gap-1" }, ve = { class: "flex flex-row gap-1" }, me = { class: "flex flex-row gap-1" }, fe = { class: "mt-1" }, ce = {
|
|
144
144
|
key: 0,
|
|
145
145
|
class: "flex flex-col gap-1 mt-2"
|
|
146
|
-
}, ye = { class: "flex flex-row gap-1 h-6" },
|
|
146
|
+
}, ye = { class: "flex flex-row gap-1 h-6" }, _e = { class: "flex flex-row gap-1" }, be = {
|
|
147
147
|
key: 1,
|
|
148
148
|
class: "flex flex-col gap-1 mt-1"
|
|
149
|
-
}, xe = { class: "flex flex-row gap-1 items-center" },
|
|
149
|
+
}, xe = { class: "flex flex-row gap-1 items-center" }, we = /* @__PURE__ */ H({
|
|
150
150
|
__name: "RequestForm",
|
|
151
151
|
props: {
|
|
152
152
|
modelValue: { default: () => de }
|
|
153
153
|
},
|
|
154
154
|
emits: ["update:modelValue"],
|
|
155
|
-
setup(
|
|
156
|
-
const
|
|
157
|
-
function
|
|
158
|
-
let
|
|
159
|
-
return function(...
|
|
160
|
-
clearTimeout(
|
|
155
|
+
setup(a, { emit: g }) {
|
|
156
|
+
const d = a, o = g, n = w(d.modelValue.method), y = w(d.modelValue.url), l = w(d.modelValue.auth.type), f = w(d.modelValue.path), u = w(d.modelValue.auth.username || ""), t = w(d.modelValue.auth.password || ""), v = w(d.modelValue.auth.token || ""), x = w(d.modelValue.params), j = w(d.modelValue.headers), B = w(d.modelValue.body.formData || []), U = w(d.modelValue.body.type), k = w(d.modelValue.body.json || ""), S = w(d.modelValue.body.raw || ""), h = w("");
|
|
157
|
+
function N(i, e) {
|
|
158
|
+
let T;
|
|
159
|
+
return function(...E) {
|
|
160
|
+
clearTimeout(T), T = setTimeout(() => i.apply(this, E), e);
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
|
-
const
|
|
163
|
+
const A = () => ({
|
|
164
164
|
method: n.value,
|
|
165
|
-
url:
|
|
166
|
-
path:
|
|
165
|
+
url: y.value,
|
|
166
|
+
path: f.value,
|
|
167
167
|
auth: {
|
|
168
|
-
type:
|
|
169
|
-
...
|
|
170
|
-
username:
|
|
171
|
-
password:
|
|
172
|
-
} :
|
|
173
|
-
token:
|
|
168
|
+
type: l.value,
|
|
169
|
+
...l.value === "Basic" ? {
|
|
170
|
+
username: u.value,
|
|
171
|
+
password: t.value
|
|
172
|
+
} : l.value === "Bearer" ? {
|
|
173
|
+
token: v.value
|
|
174
174
|
} : {}
|
|
175
175
|
},
|
|
176
|
-
params:
|
|
177
|
-
headers:
|
|
176
|
+
params: x.value,
|
|
177
|
+
headers: j.value,
|
|
178
178
|
body: {
|
|
179
179
|
type: U.value,
|
|
180
|
-
...U.value === "application/json" ? { json: k.value } : U.value === "multipart/form-data" ? { formData:
|
|
180
|
+
...U.value === "application/json" ? { json: k.value } : U.value === "multipart/form-data" ? { formData: B.value } : { raw: S.value }
|
|
181
181
|
}
|
|
182
|
-
}), W =
|
|
183
|
-
|
|
182
|
+
}), W = N(() => {
|
|
183
|
+
o("update:modelValue", A());
|
|
184
184
|
}, 100);
|
|
185
|
-
|
|
185
|
+
C(
|
|
186
186
|
[
|
|
187
187
|
n,
|
|
188
|
+
y,
|
|
188
189
|
f,
|
|
189
|
-
|
|
190
|
-
a,
|
|
191
|
-
i,
|
|
190
|
+
l,
|
|
192
191
|
u,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
t,
|
|
193
|
+
v,
|
|
194
|
+
x,
|
|
195
|
+
j,
|
|
196
196
|
U,
|
|
197
|
-
|
|
197
|
+
B,
|
|
198
198
|
k,
|
|
199
199
|
S
|
|
200
200
|
],
|
|
@@ -202,18 +202,18 @@ const oe = { class: "key-value-input flex flex-col gap-1" }, se = { class: "flex
|
|
|
202
202
|
W();
|
|
203
203
|
},
|
|
204
204
|
{ deep: !0 }
|
|
205
|
-
),
|
|
206
|
-
() =>
|
|
207
|
-
(
|
|
208
|
-
const e =
|
|
209
|
-
JSON.stringify(
|
|
205
|
+
), C(
|
|
206
|
+
() => d.modelValue,
|
|
207
|
+
(i) => {
|
|
208
|
+
const e = A();
|
|
209
|
+
JSON.stringify(i) !== JSON.stringify(e) && (n.value = i.method, y.value = i.url, f.value = i.path, l.value = i.auth.type, u.value = i.auth.username || "", t.value = i.auth.password || "", v.value = i.auth.token || "", x.value = i.params, j.value = i.headers, U.value = i.body.type, B.value = i.body.formData || [], k.value = i.body.json || "", S.value = i.body.raw || "");
|
|
210
210
|
},
|
|
211
211
|
{ deep: !0 }
|
|
212
212
|
);
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
return
|
|
216
|
-
}),
|
|
213
|
+
const X = J(() => {
|
|
214
|
+
const i = x.value.filter((e) => !!e.key).map((e) => e.key + "=" + encodeURIComponent(e.value)).join("&");
|
|
215
|
+
return i === "" ? "" : "?" + i;
|
|
216
|
+
}), Q = J(() => {
|
|
217
217
|
switch (U.value) {
|
|
218
218
|
case "application/json":
|
|
219
219
|
try {
|
|
@@ -222,412 +222,537 @@ const oe = { class: "key-value-input flex flex-col gap-1" }, se = { class: "flex
|
|
|
222
222
|
return "Invalid JSON";
|
|
223
223
|
}
|
|
224
224
|
case "multipart/form-data":
|
|
225
|
-
const
|
|
226
|
-
return
|
|
227
|
-
(
|
|
228
|
-
Content-Disposition: form-data; name="${
|
|
225
|
+
const i = "----WebKitFormBoundaryPreview";
|
|
226
|
+
return B.value.filter((T) => !!T.key).map(
|
|
227
|
+
(T) => `--${i}\r
|
|
228
|
+
Content-Disposition: form-data; name="${T.key}"\r
|
|
229
229
|
\r
|
|
230
|
-
${
|
|
230
|
+
${T.value}\r
|
|
231
231
|
`
|
|
232
|
-
).join("") + `--${
|
|
232
|
+
).join("") + `--${i}--\r
|
|
233
233
|
`;
|
|
234
234
|
case "text/plain":
|
|
235
235
|
return S.value || "-空-";
|
|
236
236
|
default:
|
|
237
237
|
return "-空-";
|
|
238
238
|
}
|
|
239
|
-
}),
|
|
239
|
+
}), Y = () => {
|
|
240
240
|
try {
|
|
241
|
-
k.value && (JSON.parse(k.value),
|
|
241
|
+
k.value && (JSON.parse(k.value), h.value = "");
|
|
242
242
|
} catch {
|
|
243
|
-
|
|
243
|
+
h.value = "Invalid JSON format";
|
|
244
244
|
}
|
|
245
|
-
},
|
|
245
|
+
}, Z = () => {
|
|
246
246
|
try {
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}),
|
|
253
|
-
} catch (
|
|
254
|
-
console.error("URL解析失败:",
|
|
247
|
+
const i = y.value, e = new URL(i);
|
|
248
|
+
y.value = `${e.protocol}//${e.host}`, f.value = e.pathname;
|
|
249
|
+
const T = new URLSearchParams(e.search), E = [];
|
|
250
|
+
T.forEach((V, D) => {
|
|
251
|
+
E.push({ key: D, value: V });
|
|
252
|
+
}), x.value = E;
|
|
253
|
+
} catch (i) {
|
|
254
|
+
console.error("URL解析失败:", i);
|
|
255
255
|
}
|
|
256
|
-
},
|
|
257
|
-
if (!
|
|
256
|
+
}, ee = J(() => {
|
|
257
|
+
if (!y.value) return !1;
|
|
258
258
|
try {
|
|
259
|
-
const
|
|
259
|
+
const i = y.value, e = new URL(i);
|
|
260
260
|
return e.search !== "" || e.pathname !== "/";
|
|
261
261
|
} catch {
|
|
262
262
|
return !1;
|
|
263
263
|
}
|
|
264
264
|
});
|
|
265
|
-
return (
|
|
266
|
-
const
|
|
267
|
-
return
|
|
268
|
-
|
|
269
|
-
default:
|
|
270
|
-
|
|
265
|
+
return (i, e) => {
|
|
266
|
+
const T = c("a-input"), E = c("a-button"), V = c("a-select-option"), D = c("a-select"), P = c("a-card"), q = c("a-radio-button"), G = c("a-radio-group"), te = c("a-input-password"), I = c("a-textarea"), ae = c("a-alert"), oe = c("a-form");
|
|
267
|
+
return _(), $("div", ie, [
|
|
268
|
+
s(oe, { layout: "vertical" }, {
|
|
269
|
+
default: r(() => [
|
|
270
|
+
s(P, {
|
|
271
271
|
title: "URL配置",
|
|
272
272
|
class: "form-section",
|
|
273
273
|
size: "small"
|
|
274
274
|
}, {
|
|
275
|
-
default:
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
value:
|
|
280
|
-
"onUpdate:value": e[0] || (e[0] = (
|
|
275
|
+
default: r(() => [
|
|
276
|
+
p("div", pe, [
|
|
277
|
+
p("div", ve, [
|
|
278
|
+
s(T, {
|
|
279
|
+
value: y.value,
|
|
280
|
+
"onUpdate:value": e[0] || (e[0] = (m) => y.value = m),
|
|
281
281
|
placeholder: "基础URL",
|
|
282
282
|
size: "small"
|
|
283
283
|
}, null, 8, ["value"]),
|
|
284
|
-
|
|
284
|
+
ee.value ? (_(), O(E, {
|
|
285
285
|
key: 0,
|
|
286
286
|
type: "primary",
|
|
287
287
|
size: "small",
|
|
288
|
-
onClick:
|
|
288
|
+
onClick: Z
|
|
289
289
|
}, {
|
|
290
|
-
default:
|
|
291
|
-
|
|
290
|
+
default: r(() => e[13] || (e[13] = [
|
|
291
|
+
b("拆解")
|
|
292
292
|
])),
|
|
293
293
|
_: 1
|
|
294
|
-
})) :
|
|
294
|
+
})) : R("", !0)
|
|
295
295
|
]),
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
p("div", me, [
|
|
297
|
+
s(D, {
|
|
298
298
|
value: n.value,
|
|
299
|
-
"onUpdate:value": e[1] || (e[1] = (
|
|
299
|
+
"onUpdate:value": e[1] || (e[1] = (m) => n.value = m),
|
|
300
300
|
class: "w-40",
|
|
301
301
|
size: "small"
|
|
302
302
|
}, {
|
|
303
|
-
default:
|
|
304
|
-
|
|
305
|
-
default:
|
|
306
|
-
|
|
303
|
+
default: r(() => [
|
|
304
|
+
s(V, { value: "GET" }, {
|
|
305
|
+
default: r(() => e[14] || (e[14] = [
|
|
306
|
+
b("GET")
|
|
307
307
|
])),
|
|
308
308
|
_: 1
|
|
309
309
|
}),
|
|
310
|
-
|
|
311
|
-
default:
|
|
312
|
-
|
|
310
|
+
s(V, { value: "POST" }, {
|
|
311
|
+
default: r(() => e[15] || (e[15] = [
|
|
312
|
+
b("POST")
|
|
313
313
|
])),
|
|
314
314
|
_: 1
|
|
315
315
|
}),
|
|
316
|
-
|
|
317
|
-
default:
|
|
318
|
-
|
|
316
|
+
s(V, { value: "PUT" }, {
|
|
317
|
+
default: r(() => e[16] || (e[16] = [
|
|
318
|
+
b("PUT")
|
|
319
319
|
])),
|
|
320
320
|
_: 1
|
|
321
321
|
}),
|
|
322
|
-
|
|
323
|
-
default:
|
|
324
|
-
|
|
322
|
+
s(V, { value: "DELETE" }, {
|
|
323
|
+
default: r(() => e[17] || (e[17] = [
|
|
324
|
+
b("DELETE")
|
|
325
325
|
])),
|
|
326
326
|
_: 1
|
|
327
327
|
}),
|
|
328
|
-
|
|
329
|
-
default:
|
|
330
|
-
|
|
328
|
+
s(V, { value: "OPTIONS" }, {
|
|
329
|
+
default: r(() => e[18] || (e[18] = [
|
|
330
|
+
b("OPTIONS")
|
|
331
331
|
])),
|
|
332
332
|
_: 1
|
|
333
333
|
})
|
|
334
334
|
]),
|
|
335
335
|
_: 1
|
|
336
336
|
}, 8, ["value"]),
|
|
337
|
-
|
|
338
|
-
value:
|
|
339
|
-
"onUpdate:value": e[2] || (e[2] = (
|
|
337
|
+
s(T, {
|
|
338
|
+
value: f.value,
|
|
339
|
+
"onUpdate:value": e[2] || (e[2] = (m) => f.value = m),
|
|
340
340
|
placeholder: "路径",
|
|
341
341
|
size: "small"
|
|
342
342
|
}, null, 8, ["value"])
|
|
343
343
|
])
|
|
344
344
|
]),
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
modelValue:
|
|
348
|
-
"onUpdate:modelValue": e[3] || (e[3] = (
|
|
345
|
+
p("div", fe, [
|
|
346
|
+
s(L, {
|
|
347
|
+
modelValue: x.value,
|
|
348
|
+
"onUpdate:modelValue": e[3] || (e[3] = (m) => x.value = m),
|
|
349
349
|
"add-button-text": "添加参数",
|
|
350
350
|
"show-preview": !0,
|
|
351
|
-
"preview-text":
|
|
351
|
+
"preview-text": y.value + f.value + X.value
|
|
352
352
|
}, null, 8, ["modelValue", "preview-text"])
|
|
353
353
|
])
|
|
354
354
|
]),
|
|
355
355
|
_: 1
|
|
356
356
|
}),
|
|
357
|
-
|
|
357
|
+
s(P, {
|
|
358
358
|
title: "认证方案",
|
|
359
359
|
class: "form-section",
|
|
360
360
|
size: "small"
|
|
361
361
|
}, {
|
|
362
|
-
default:
|
|
363
|
-
|
|
364
|
-
value:
|
|
365
|
-
"onUpdate:value": e[4] || (e[4] = (
|
|
362
|
+
default: r(() => [
|
|
363
|
+
s(G, {
|
|
364
|
+
value: l.value,
|
|
365
|
+
"onUpdate:value": e[4] || (e[4] = (m) => l.value = m),
|
|
366
366
|
"button-style": "solid",
|
|
367
367
|
size: "small"
|
|
368
368
|
}, {
|
|
369
|
-
default:
|
|
370
|
-
|
|
371
|
-
default:
|
|
372
|
-
|
|
369
|
+
default: r(() => [
|
|
370
|
+
s(q, { value: "none" }, {
|
|
371
|
+
default: r(() => e[19] || (e[19] = [
|
|
372
|
+
b("无认证")
|
|
373
373
|
])),
|
|
374
374
|
_: 1
|
|
375
375
|
}),
|
|
376
|
-
|
|
377
|
-
default:
|
|
378
|
-
|
|
376
|
+
s(q, { value: "Basic" }, {
|
|
377
|
+
default: r(() => e[20] || (e[20] = [
|
|
378
|
+
b("Basic认证")
|
|
379
379
|
])),
|
|
380
380
|
_: 1
|
|
381
381
|
}),
|
|
382
|
-
|
|
383
|
-
default:
|
|
384
|
-
|
|
382
|
+
s(q, { value: "Bearer" }, {
|
|
383
|
+
default: r(() => e[21] || (e[21] = [
|
|
384
|
+
b("Bearer认证")
|
|
385
385
|
])),
|
|
386
386
|
_: 1
|
|
387
387
|
})
|
|
388
388
|
]),
|
|
389
389
|
_: 1
|
|
390
390
|
}, 8, ["value"]),
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
e[22] || (e[22] =
|
|
394
|
-
|
|
395
|
-
value:
|
|
396
|
-
"onUpdate:value": e[5] || (e[5] = (
|
|
391
|
+
l.value === "Basic" ? (_(), $("div", ce, [
|
|
392
|
+
p("div", ye, [
|
|
393
|
+
e[22] || (e[22] = p("p", { class: "m-0 w-16" }, "用户名", -1)),
|
|
394
|
+
s(T, {
|
|
395
|
+
value: u.value,
|
|
396
|
+
"onUpdate:value": e[5] || (e[5] = (m) => u.value = m),
|
|
397
397
|
size: "small"
|
|
398
398
|
}, null, 8, ["value"])
|
|
399
399
|
]),
|
|
400
|
-
|
|
401
|
-
e[23] || (e[23] =
|
|
402
|
-
|
|
403
|
-
value:
|
|
404
|
-
"onUpdate:value": e[6] || (e[6] = (
|
|
400
|
+
p("div", _e, [
|
|
401
|
+
e[23] || (e[23] = p("p", { class: "m-0 w-16" }, "密码", -1)),
|
|
402
|
+
s(te, {
|
|
403
|
+
value: t.value,
|
|
404
|
+
"onUpdate:value": e[6] || (e[6] = (m) => t.value = m),
|
|
405
405
|
size: "small"
|
|
406
406
|
}, null, 8, ["value"])
|
|
407
407
|
])
|
|
408
|
-
])) :
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
e[24] || (e[24] =
|
|
412
|
-
|
|
413
|
-
value:
|
|
414
|
-
"onUpdate:value": e[7] || (e[7] = (
|
|
408
|
+
])) : R("", !0),
|
|
409
|
+
l.value === "Bearer" ? (_(), $("div", be, [
|
|
410
|
+
p("div", xe, [
|
|
411
|
+
e[24] || (e[24] = p("p", { class: "m-0 w-16 h-full" }, "Token", -1)),
|
|
412
|
+
s(I, {
|
|
413
|
+
value: v.value,
|
|
414
|
+
"onUpdate:value": e[7] || (e[7] = (m) => v.value = m),
|
|
415
415
|
size: "small",
|
|
416
416
|
class: "mt-1",
|
|
417
417
|
rows: "4",
|
|
418
418
|
placeholder: "请输入Token"
|
|
419
419
|
}, null, 8, ["value"])
|
|
420
420
|
])
|
|
421
|
-
])) :
|
|
421
|
+
])) : R("", !0)
|
|
422
422
|
]),
|
|
423
423
|
_: 1
|
|
424
424
|
}),
|
|
425
|
-
|
|
425
|
+
s(P, {
|
|
426
426
|
title: "请求头",
|
|
427
427
|
class: "form-section",
|
|
428
428
|
size: "small"
|
|
429
429
|
}, {
|
|
430
|
-
default:
|
|
431
|
-
|
|
432
|
-
modelValue:
|
|
433
|
-
"onUpdate:modelValue": e[8] || (e[8] = (
|
|
430
|
+
default: r(() => [
|
|
431
|
+
s(L, {
|
|
432
|
+
modelValue: j.value,
|
|
433
|
+
"onUpdate:modelValue": e[8] || (e[8] = (m) => j.value = m),
|
|
434
434
|
"add-button-text": "添加请求头",
|
|
435
435
|
"show-preview": !1
|
|
436
436
|
}, null, 8, ["modelValue"])
|
|
437
437
|
]),
|
|
438
438
|
_: 1
|
|
439
439
|
}),
|
|
440
|
-
n.value === "POST" || n.value === "PUT" ? (
|
|
440
|
+
n.value === "POST" || n.value === "PUT" ? (_(), O(P, {
|
|
441
441
|
key: 0,
|
|
442
442
|
title: "请求体",
|
|
443
443
|
class: "form-section",
|
|
444
444
|
size: "small"
|
|
445
445
|
}, {
|
|
446
|
-
default:
|
|
447
|
-
|
|
446
|
+
default: r(() => [
|
|
447
|
+
s(G, {
|
|
448
448
|
value: U.value,
|
|
449
|
-
"onUpdate:value": e[9] || (e[9] = (
|
|
449
|
+
"onUpdate:value": e[9] || (e[9] = (m) => U.value = m),
|
|
450
450
|
"button-style": "solid",
|
|
451
451
|
size: "small",
|
|
452
452
|
class: "mb-1"
|
|
453
453
|
}, {
|
|
454
|
-
default:
|
|
455
|
-
|
|
456
|
-
default:
|
|
457
|
-
|
|
454
|
+
default: r(() => [
|
|
455
|
+
s(q, { value: "application/json" }, {
|
|
456
|
+
default: r(() => e[25] || (e[25] = [
|
|
457
|
+
b("JSON")
|
|
458
458
|
])),
|
|
459
459
|
_: 1
|
|
460
460
|
}),
|
|
461
|
-
|
|
462
|
-
default:
|
|
463
|
-
|
|
461
|
+
s(q, { value: "multipart/form-data" }, {
|
|
462
|
+
default: r(() => e[26] || (e[26] = [
|
|
463
|
+
b("Form Data")
|
|
464
464
|
])),
|
|
465
465
|
_: 1
|
|
466
466
|
}),
|
|
467
|
-
|
|
468
|
-
default:
|
|
469
|
-
|
|
467
|
+
s(q, { value: "text/plain" }, {
|
|
468
|
+
default: r(() => e[27] || (e[27] = [
|
|
469
|
+
b("Raw")
|
|
470
470
|
])),
|
|
471
471
|
_: 1
|
|
472
472
|
})
|
|
473
473
|
]),
|
|
474
474
|
_: 1
|
|
475
475
|
}, 8, ["value"]),
|
|
476
|
-
U.value === "application/json" ? (
|
|
477
|
-
|
|
476
|
+
U.value === "application/json" ? (_(), $(F, { key: 0 }, [
|
|
477
|
+
s(I, {
|
|
478
478
|
value: k.value,
|
|
479
|
-
"onUpdate:value": e[10] || (e[10] = (
|
|
479
|
+
"onUpdate:value": e[10] || (e[10] = (m) => k.value = m),
|
|
480
480
|
rows: 6,
|
|
481
481
|
placeholder: "请输入 JSON 数据",
|
|
482
|
-
onInput:
|
|
482
|
+
onInput: Y
|
|
483
483
|
}, null, 8, ["value"]),
|
|
484
|
-
|
|
484
|
+
h.value ? (_(), O(ae, {
|
|
485
485
|
key: 0,
|
|
486
486
|
type: "error",
|
|
487
|
-
message:
|
|
487
|
+
message: h.value,
|
|
488
488
|
banner: "",
|
|
489
489
|
style: { "margin-bottom": "8px" }
|
|
490
|
-
}, null, 8, ["message"])) :
|
|
491
|
-
], 64)) :
|
|
492
|
-
U.value === "multipart/form-data" ? (
|
|
490
|
+
}, null, 8, ["message"])) : R("", !0)
|
|
491
|
+
], 64)) : R("", !0),
|
|
492
|
+
U.value === "multipart/form-data" ? (_(), O(L, {
|
|
493
493
|
key: 1,
|
|
494
|
-
modelValue:
|
|
495
|
-
"onUpdate:modelValue": e[11] || (e[11] = (
|
|
494
|
+
modelValue: B.value,
|
|
495
|
+
"onUpdate:modelValue": e[11] || (e[11] = (m) => B.value = m),
|
|
496
496
|
"add-button-text": "添加表单字段",
|
|
497
497
|
"show-preview": !1
|
|
498
|
-
}, null, 8, ["modelValue"])) :
|
|
499
|
-
U.value === "text/plain" ? (
|
|
498
|
+
}, null, 8, ["modelValue"])) : R("", !0),
|
|
499
|
+
U.value === "text/plain" ? (_(), O(I, {
|
|
500
500
|
key: 2,
|
|
501
501
|
value: S.value,
|
|
502
|
-
"onUpdate:value": e[12] || (e[12] = (
|
|
502
|
+
"onUpdate:value": e[12] || (e[12] = (m) => S.value = m),
|
|
503
503
|
rows: 6,
|
|
504
504
|
placeholder: "请输入原始数据"
|
|
505
|
-
}, null, 8, ["value"])) :
|
|
506
|
-
|
|
505
|
+
}, null, 8, ["value"])) : R("", !0),
|
|
506
|
+
p("pre", null, z(Q.value), 1)
|
|
507
507
|
]),
|
|
508
508
|
_: 1
|
|
509
|
-
})) :
|
|
509
|
+
})) : R("", !0)
|
|
510
510
|
]),
|
|
511
511
|
_: 1
|
|
512
512
|
})
|
|
513
513
|
]);
|
|
514
514
|
};
|
|
515
515
|
}
|
|
516
|
-
}),
|
|
517
|
-
async function
|
|
518
|
-
return
|
|
516
|
+
}), Ee = /* @__PURE__ */ M(we, [["__scopeId", "data-v-c9f65487"]]);
|
|
517
|
+
async function ge(a, g = "xhr") {
|
|
518
|
+
return g === "fetch" ? ke(a) : he(a);
|
|
519
519
|
}
|
|
520
|
-
async function
|
|
521
|
-
var
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
520
|
+
async function ke(a) {
|
|
521
|
+
var y;
|
|
522
|
+
const g = a.params.filter((l) => !!l.key).map((l) => `${l.key}=${encodeURIComponent(l.value)}`).join("&"), d = `${a.url}${a.path}${g ? "?" + g : ""}`, o = new Headers();
|
|
523
|
+
a.headers.forEach((l) => {
|
|
524
|
+
l.key && o.append(l.key, l.value);
|
|
525
525
|
});
|
|
526
526
|
const n = {
|
|
527
|
-
method:
|
|
528
|
-
headers:
|
|
527
|
+
method: a.method,
|
|
528
|
+
headers: o,
|
|
529
529
|
credentials: "omit"
|
|
530
530
|
};
|
|
531
|
-
if (
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
} else
|
|
535
|
-
if (
|
|
536
|
-
switch (
|
|
531
|
+
if (a.auth.type === "Basic" && a.auth.username && a.auth.password) {
|
|
532
|
+
const l = btoa(`${a.auth.username}:${a.auth.password}`);
|
|
533
|
+
o.append("Authorization", `Basic ${l}`);
|
|
534
|
+
} else a.auth.type === "Bearer" && a.auth.token && o.append("Authorization", `Bearer ${a.auth.token}`);
|
|
535
|
+
if (a.method === "POST" || a.method === "PUT")
|
|
536
|
+
switch (a.body.type) {
|
|
537
537
|
case "application/json":
|
|
538
|
-
n.body =
|
|
538
|
+
n.body = a.body.json || "", o.set("Content-Type", "application/json; charset=utf-8");
|
|
539
539
|
break;
|
|
540
540
|
case "multipart/form-data":
|
|
541
|
-
const
|
|
542
|
-
(
|
|
543
|
-
|
|
544
|
-
}), n.body =
|
|
541
|
+
const l = new FormData();
|
|
542
|
+
(y = a.body.formData) == null || y.forEach((f) => {
|
|
543
|
+
f.key && l.append(f.key, f.value);
|
|
544
|
+
}), n.body = l;
|
|
545
545
|
break;
|
|
546
546
|
case "text/plain":
|
|
547
|
-
n.body =
|
|
547
|
+
n.body = a.body.raw || "", o.set("Content-Type", "text/plain; charset=utf-8");
|
|
548
548
|
break;
|
|
549
549
|
}
|
|
550
550
|
try {
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
551
|
+
const l = await fetch(d, n), f = {};
|
|
552
|
+
l.headers.forEach((v, x) => {
|
|
553
|
+
f[x.toLowerCase()] = v;
|
|
554
554
|
});
|
|
555
|
-
let
|
|
556
|
-
if ((
|
|
555
|
+
let u = "";
|
|
556
|
+
if ((f["content-type"] || "").startsWith("application/json"))
|
|
557
557
|
try {
|
|
558
|
-
const
|
|
559
|
-
|
|
558
|
+
const v = await l.json();
|
|
559
|
+
u = JSON.stringify(v, null, 2);
|
|
560
560
|
} catch {
|
|
561
|
-
|
|
561
|
+
u = await l.text();
|
|
562
562
|
}
|
|
563
563
|
else
|
|
564
|
-
|
|
564
|
+
u = await l.text();
|
|
565
565
|
return {
|
|
566
|
-
status:
|
|
567
|
-
headers:
|
|
568
|
-
body:
|
|
566
|
+
status: l.status.toString(),
|
|
567
|
+
headers: f,
|
|
568
|
+
body: u
|
|
569
569
|
};
|
|
570
570
|
} catch {
|
|
571
571
|
throw new Error("Request failed");
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
|
-
async function he(
|
|
575
|
-
return new Promise((
|
|
576
|
-
var
|
|
577
|
-
const
|
|
578
|
-
if (
|
|
579
|
-
|
|
580
|
-
}),
|
|
581
|
-
let
|
|
582
|
-
switch (
|
|
574
|
+
async function he(a) {
|
|
575
|
+
return new Promise((g, d) => {
|
|
576
|
+
var u;
|
|
577
|
+
const o = new XMLHttpRequest(), n = a.auth.type === "Basic" ? a.auth.username : null, y = a.auth.type === "Basic" ? a.auth.password : null, l = a.params.filter((t) => !!t.key).map((t) => `${t.key}=${encodeURIComponent(t.value)}`).join("&"), f = `${a.url}${a.path}${l ? "?" + l : ""}`;
|
|
578
|
+
if (o.open(a.method, f, !0, n, y), a.headers.forEach((t) => {
|
|
579
|
+
t.key && o.setRequestHeader(t.key, t.value);
|
|
580
|
+
}), a.auth.type === "Bearer" && a.auth.token && o.setRequestHeader("Authorization", `Bearer ${a.auth.token}`), a.method === "POST" || a.method === "PUT") {
|
|
581
|
+
let t = "";
|
|
582
|
+
switch (a.body.type) {
|
|
583
583
|
case "application/json":
|
|
584
|
-
|
|
584
|
+
t = a.body.json || "", o.setRequestHeader("Content-Type", "application/json; charset=utf-8");
|
|
585
585
|
break;
|
|
586
586
|
case "multipart/form-data":
|
|
587
|
-
const
|
|
588
|
-
(
|
|
589
|
-
|
|
590
|
-
}),
|
|
587
|
+
const v = new FormData();
|
|
588
|
+
(u = a.body.formData) == null || u.forEach((x) => {
|
|
589
|
+
x.key && v.append(x.key, x.value);
|
|
590
|
+
}), t = v;
|
|
591
591
|
break;
|
|
592
592
|
case "text/plain":
|
|
593
|
-
|
|
593
|
+
t = a.body.raw || "", o.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
|
|
594
594
|
break;
|
|
595
595
|
}
|
|
596
|
-
|
|
596
|
+
o.send(t);
|
|
597
597
|
} else
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
const
|
|
601
|
-
status:
|
|
602
|
-
headers:
|
|
598
|
+
o.send();
|
|
599
|
+
o.onload = () => {
|
|
600
|
+
const t = Ue(o), v = {
|
|
601
|
+
status: o.status.toString(),
|
|
602
|
+
headers: t,
|
|
603
603
|
body: ""
|
|
604
604
|
};
|
|
605
|
-
if ((
|
|
605
|
+
if ((t["content-type"] || "").startsWith("application/json"))
|
|
606
606
|
try {
|
|
607
|
-
|
|
607
|
+
v.body = JSON.stringify(JSON.parse(o.responseText), null, 2);
|
|
608
608
|
} catch {
|
|
609
|
-
|
|
609
|
+
v.body = o.responseText;
|
|
610
610
|
}
|
|
611
611
|
else
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
},
|
|
615
|
-
|
|
612
|
+
v.body = o.responseText;
|
|
613
|
+
g(v);
|
|
614
|
+
}, o.onerror = () => {
|
|
615
|
+
d(new Error("Request failed"));
|
|
616
616
|
};
|
|
617
617
|
});
|
|
618
618
|
}
|
|
619
|
-
function
|
|
620
|
-
const
|
|
621
|
-
return
|
|
622
|
-
var
|
|
623
|
-
const n =
|
|
624
|
-
|
|
625
|
-
}),
|
|
619
|
+
function Ue(a) {
|
|
620
|
+
const g = a.getAllResponseHeaders().trim().split(/[\r\n]+/), d = {};
|
|
621
|
+
return g.forEach(function(o) {
|
|
622
|
+
var f;
|
|
623
|
+
const n = o.split(": "), y = ((f = n.shift()) == null ? void 0 : f.toLowerCase()) || "", l = n.join(": ");
|
|
624
|
+
d[y] = l;
|
|
625
|
+
}), d;
|
|
626
626
|
}
|
|
627
|
+
const Te = { style: { display: "flex", "align-items": "center", gap: "8px", "margin-bottom": "8px" } }, $e = { class: "flex flex-col gap-2" }, Se = { class: "flex flex-col gap-1" }, Re = {
|
|
628
|
+
key: 0,
|
|
629
|
+
class: "border border-solid border-gray-300 w-full"
|
|
630
|
+
}, je = { class: "border border-gray-300" }, Be = { class: "border border-gray-300" }, Oe = { key: 1 }, Ve = /* @__PURE__ */ H({
|
|
631
|
+
__name: "ResponseSection",
|
|
632
|
+
props: {
|
|
633
|
+
modelValue: {}
|
|
634
|
+
},
|
|
635
|
+
setup(a) {
|
|
636
|
+
const g = a, d = w("xhr"), o = w({
|
|
637
|
+
status: "",
|
|
638
|
+
headers: {},
|
|
639
|
+
body: "",
|
|
640
|
+
timing: 0
|
|
641
|
+
}), n = w(""), y = (u) => {
|
|
642
|
+
const t = Number(u);
|
|
643
|
+
return t >= 200 && t < 300 ? "success" : t >= 300 && t < 400 ? "warning" : t >= 400 && t < 500 || t >= 500 ? "error" : "default";
|
|
644
|
+
}, l = (u) => u instanceof Error ? u.message : "请求失败", f = async () => {
|
|
645
|
+
n.value = "";
|
|
646
|
+
const u = Date.now();
|
|
647
|
+
try {
|
|
648
|
+
o.value = await ge(g.modelValue, d.value), o.value.timing = Date.now() - u;
|
|
649
|
+
} catch (t) {
|
|
650
|
+
n.value = l(t), o.value = {
|
|
651
|
+
status: "Error",
|
|
652
|
+
headers: {},
|
|
653
|
+
body: t instanceof Error ? t.message : "Request failed",
|
|
654
|
+
timing: Date.now() - u
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
return (u, t) => {
|
|
659
|
+
const v = c("a-radio-button"), x = c("a-radio-group"), j = c("a-button"), B = c("a-alert"), U = c("a-tag"), k = c("a-textarea"), S = c("a-card");
|
|
660
|
+
return _(), O(S, {
|
|
661
|
+
title: "响应",
|
|
662
|
+
class: "form-section",
|
|
663
|
+
size: "small"
|
|
664
|
+
}, {
|
|
665
|
+
default: r(() => [
|
|
666
|
+
p("div", Te, [
|
|
667
|
+
s(x, {
|
|
668
|
+
value: d.value,
|
|
669
|
+
"onUpdate:value": t[0] || (t[0] = (h) => d.value = h),
|
|
670
|
+
"button-style": "solid",
|
|
671
|
+
size: "small"
|
|
672
|
+
}, {
|
|
673
|
+
default: r(() => [
|
|
674
|
+
s(v, { value: "xhr" }, {
|
|
675
|
+
default: r(() => t[2] || (t[2] = [
|
|
676
|
+
b("XMLHttpRequest")
|
|
677
|
+
])),
|
|
678
|
+
_: 1
|
|
679
|
+
}),
|
|
680
|
+
s(v, { value: "fetch" }, {
|
|
681
|
+
default: r(() => t[3] || (t[3] = [
|
|
682
|
+
b("Fetch")
|
|
683
|
+
])),
|
|
684
|
+
_: 1
|
|
685
|
+
})
|
|
686
|
+
]),
|
|
687
|
+
_: 1
|
|
688
|
+
}, 8, ["value"]),
|
|
689
|
+
s(j, {
|
|
690
|
+
type: "primary",
|
|
691
|
+
onClick: f,
|
|
692
|
+
size: "small"
|
|
693
|
+
}, {
|
|
694
|
+
default: r(() => t[4] || (t[4] = [
|
|
695
|
+
b("发送")
|
|
696
|
+
])),
|
|
697
|
+
_: 1
|
|
698
|
+
})
|
|
699
|
+
]),
|
|
700
|
+
n.value ? (_(), O(B, {
|
|
701
|
+
key: 0,
|
|
702
|
+
message: n.value,
|
|
703
|
+
type: "error",
|
|
704
|
+
"show-icon": "",
|
|
705
|
+
style: { "margin-bottom": "8px" }
|
|
706
|
+
}, null, 8, ["message"])) : R("", !0),
|
|
707
|
+
p("div", $e, [
|
|
708
|
+
t[7] || (t[7] = p("div", { class: "text-sm font-bold" }, "基本信息", -1)),
|
|
709
|
+
p("div", Se, [
|
|
710
|
+
p("div", null, [
|
|
711
|
+
t[5] || (t[5] = p("span", null, "状态码:", -1)),
|
|
712
|
+
s(U, {
|
|
713
|
+
color: y(o.value.status)
|
|
714
|
+
}, {
|
|
715
|
+
default: r(() => [
|
|
716
|
+
b(z(o.value.status), 1)
|
|
717
|
+
]),
|
|
718
|
+
_: 1
|
|
719
|
+
}, 8, ["color"])
|
|
720
|
+
]),
|
|
721
|
+
p("div", null, [
|
|
722
|
+
t[6] || (t[6] = p("span", null, "耗时:", -1)),
|
|
723
|
+
p("span", null, z(o.value.timing ? `${o.value.timing}ms` : "-"), 1)
|
|
724
|
+
])
|
|
725
|
+
]),
|
|
726
|
+
t[8] || (t[8] = p("div", { class: "text-sm font-bold" }, "响应头", -1)),
|
|
727
|
+
Object.keys(o.value.headers).length > 0 ? (_(), $("table", Re, [
|
|
728
|
+
p("tbody", null, [
|
|
729
|
+
(_(!0), $(F, null, K(Object.entries(o.value.headers), ([h, N]) => (_(), $("tr", { key: h }, [
|
|
730
|
+
p("td", je, z(h), 1),
|
|
731
|
+
p("td", Be, z(N), 1)
|
|
732
|
+
]))), 128))
|
|
733
|
+
])
|
|
734
|
+
])) : (_(), $("p", Oe, "无响应头")),
|
|
735
|
+
t[9] || (t[9] = p("div", { class: "text-sm font-bold" }, "响应体", -1)),
|
|
736
|
+
s(k, {
|
|
737
|
+
value: o.value.body,
|
|
738
|
+
"onUpdate:value": t[1] || (t[1] = (h) => o.value.body = h),
|
|
739
|
+
rows: 5,
|
|
740
|
+
readonly: "",
|
|
741
|
+
style: { width: "100%" },
|
|
742
|
+
size: "small"
|
|
743
|
+
}, null, 8, ["value"])
|
|
744
|
+
])
|
|
745
|
+
]),
|
|
746
|
+
_: 1
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
}), qe = /* @__PURE__ */ M(Ve, [["__scopeId", "data-v-1dd2b288"]]);
|
|
627
751
|
export {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
752
|
+
L as KeyValueInput,
|
|
753
|
+
Ee as RequestForm,
|
|
754
|
+
qe as ResponseSection,
|
|
755
|
+
Ee as default,
|
|
631
756
|
de as defaultRequestSchema,
|
|
632
|
-
|
|
757
|
+
ge as executeRequest
|
|
633
758
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
Content-Disposition: form-data; name="${
|
|
1
|
+
(function(_,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(_=typeof globalThis<"u"?globalThis:_||self,e(_.ApiRequestBuilder={},_.Vue))})(this,function(_,e){"use strict";const P={class:"key-value-input flex flex-col gap-1"},v={class:"flex gap-2"},I={key:0,class:"flex flex-col gap-1"},L={class:"flex w-full gap-1 items-center"},J=e.defineComponent({__name:"KeyValueInput",props:{modelValue:{},addButtonText:{default:"添加参数"},showPreview:{type:Boolean,default:!1},previewText:{default:""}},emits:["update:modelValue"],setup(a,{emit:y}){const d=a,l=y,r=e.ref(d.modelValue);e.watch(()=>d.modelValue,s=>{r.value=s}),e.watch(r,s=>{l("update:modelValue",s)},{deep:!0});const u=()=>{r.value.push({key:"",value:""})},n=s=>{r.value.splice(s,1)},m=()=>{r.value=[]};return(s,o)=>{const p=e.resolveComponent("a-button"),f=e.resolveComponent("a-popconfirm"),h=e.resolveComponent("a-input"),C=e.resolveComponent("a-typography-paragraph"),N=e.resolveComponent("a-typography");return e.openBlock(),e.createElementBlock("div",P,[e.createElementVNode("div",v,[e.createVNode(p,{type:"primary",onClick:u,class:"w-40 max-w-full",size:"small"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(s.addButtonText),1)]),_:1}),e.createVNode(f,{title:"确认清空",description:"确定要清空所有参数吗?","ok-text":"确认","cancel-text":"取消",onConfirm:m},{default:e.withCtx(()=>[e.createVNode(p,{type:"primary",danger:"",class:"w-40 max-w-full",size:"small",disabled:r.value.length===0},{default:e.withCtx(()=>o[0]||(o[0]=[e.createTextVNode(" 清空 ")])),_:1},8,["disabled"])]),_:1})]),r.value.length>0?(e.openBlock(),e.createElementBlock("div",I,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.value,(V,k)=>(e.openBlock(),e.createElementBlock("div",{key:k,class:"flex"},[e.createElementVNode("div",L,[e.createVNode(p,{type:"primary",danger:"",onClick:x=>n(k),class:"w-16",size:"small"},{default:e.withCtx(()=>o[1]||(o[1]=[e.createTextVNode(" 删除 ")])),_:2},1032,["onClick"]),e.createVNode(h,{value:V.key,"onUpdate:value":x=>V.key=x,placeholder:"键",style:{width:"60%"},size:"small"},null,8,["value","onUpdate:value"]),e.createVNode(h,{value:V.value,"onUpdate:value":x=>V.value=x,placeholder:"值",style:{width:"100%"},size:"small"},null,8,["value","onUpdate:value"])])]))),128))])):e.createCommentVNode("",!0),s.showPreview?(e.openBlock(),e.createBlock(N,{key:1,class:"m-0"},{default:e.withCtx(()=>[e.createVNode(C,{class:"!m-0"},{default:e.withCtx(()=>[e.createElementVNode("pre",null,e.toDisplayString(s.previewText),1)]),_:1})]),_:1})):e.createCommentVNode("",!0)])}}}),S=(a,y)=>{const d=a.__vccOpts||a;for(const[l,r]of y)d[l]=r;return d},E=S(J,[["__scopeId","data-v-1e5ef051"]]),j={method:"GET",url:"https://yesno.wtf",path:"/api",auth:{type:"none"},params:[],headers:[],body:{type:"application/json"}},F={class:"request-form"},H={class:"flex flex-col gap-1"},M={class:"flex flex-row gap-1"},A={class:"flex flex-row gap-1"},K={class:"mt-1"},G={key:0,class:"flex flex-col gap-1 mt-2"},W={class:"flex flex-row gap-1 h-6"},X={class:"flex flex-row gap-1"},Q={key:1,class:"flex flex-col gap-1 mt-1"},Y={class:"flex flex-row gap-1 items-center"},q=S(e.defineComponent({__name:"RequestForm",props:{modelValue:{default:()=>j}},emits:["update:modelValue"],setup(a,{emit:y}){const d=a,l=y,r=e.ref(d.modelValue.method),u=e.ref(d.modelValue.url),n=e.ref(d.modelValue.auth.type),m=e.ref(d.modelValue.path),s=e.ref(d.modelValue.auth.username||""),o=e.ref(d.modelValue.auth.password||""),p=e.ref(d.modelValue.auth.token||""),f=e.ref(d.modelValue.params),h=e.ref(d.modelValue.headers),C=e.ref(d.modelValue.body.formData||[]),N=e.ref(d.modelValue.body.type),V=e.ref(d.modelValue.body.json||""),k=e.ref(d.modelValue.body.raw||""),x=e.ref("");function U(i,t){let w;return function(...g){clearTimeout(w),w=setTimeout(()=>i.apply(this,g),t)}}const z=()=>({method:r.value,url:u.value,path:m.value,auth:{type:n.value,...n.value==="Basic"?{username:s.value,password:o.value}:n.value==="Bearer"?{token:p.value}:{}},params:f.value,headers:h.value,body:{type:N.value,...N.value==="application/json"?{json:V.value}:N.value==="multipart/form-data"?{formData:C.value}:{raw:k.value}}}),pe=U(()=>{l("update:modelValue",z())},100);e.watch([r,u,m,n,s,o,p,f,h,N,C,V,k],()=>{pe()},{deep:!0}),e.watch(()=>d.modelValue,i=>{const t=z();JSON.stringify(i)!==JSON.stringify(t)&&(r.value=i.method,u.value=i.url,m.value=i.path,n.value=i.auth.type,s.value=i.auth.username||"",o.value=i.auth.password||"",p.value=i.auth.token||"",f.value=i.params,h.value=i.headers,N.value=i.body.type,C.value=i.body.formData||[],V.value=i.body.json||"",k.value=i.body.raw||"")},{deep:!0});const ce=e.computed(()=>{const i=f.value.filter(t=>!!t.key).map(t=>t.key+"="+encodeURIComponent(t.value)).join("&");return i===""?"":"?"+i}),me=e.computed(()=>{switch(N.value){case"application/json":try{return V.value?JSON.stringify(JSON.parse(V.value),null,2):"-空-"}catch{return"Invalid JSON"}case"multipart/form-data":const i="----WebKitFormBoundaryPreview";return C.value.filter(w=>!!w.key).map(w=>`--${i}\r
|
|
2
|
+
Content-Disposition: form-data; name="${w.key}"\r
|
|
3
3
|
\r
|
|
4
|
-
${
|
|
5
|
-
`).join("")+`--${
|
|
6
|
-
`;case"text/plain":return N.value||"-空-";default:return"-空-"}}),ne=()=>{try{x.value&&(JSON.parse(x.value),k.value="")}catch{k.value="Invalid JSON format"}},re=()=>{try{const l=m.value,t=new URL(l);m.value=`${t.protocol}//${t.host}`,u.value=t.pathname;const V=new URLSearchParams(t.search),T=[];V.forEach((b,v)=>{T.push({key:v,value:b})}),f.value=T}catch(l){console.error("URL解析失败:",l)}},se=e.computed(()=>{if(!m.value)return!1;try{const l=m.value,t=new URL(l);return t.search!==""||t.pathname!=="/"}catch{return!1}});return(l,t)=>{const V=e.resolveComponent("a-input"),T=e.resolveComponent("a-button"),b=e.resolveComponent("a-select-option"),v=e.resolveComponent("a-select"),E=e.resolveComponent("a-card"),B=e.resolveComponent("a-radio-button"),O=e.resolveComponent("a-radio-group"),de=e.resolveComponent("a-input-password"),U=e.resolveComponent("a-textarea"),pe=e.resolveComponent("a-alert"),ie=e.resolveComponent("a-form");return e.openBlock(),e.createElementBlock("div",J,[e.createVNode(ie,{layout:"vertical"},{default:e.withCtx(()=>[e.createVNode(E,{title:"URL配置",class:"form-section",size:"small"},{default:e.withCtx(()=>[e.createElementVNode("div",L,[e.createElementVNode("div",F,[e.createVNode(V,{value:m.value,"onUpdate:value":t[0]||(t[0]=p=>m.value=p),placeholder:"基础URL",size:"small"},null,8,["value"]),se.value?(e.openBlock(),e.createBlock(T,{key:0,type:"primary",size:"small",onClick:re},{default:e.withCtx(()=>t[13]||(t[13]=[e.createTextVNode("拆解")])),_:1})):e.createCommentVNode("",!0)]),e.createElementVNode("div",H,[e.createVNode(v,{value:r.value,"onUpdate:value":t[1]||(t[1]=p=>r.value=p),class:"w-40",size:"small"},{default:e.withCtx(()=>[e.createVNode(b,{value:"GET"},{default:e.withCtx(()=>t[14]||(t[14]=[e.createTextVNode("GET")])),_:1}),e.createVNode(b,{value:"POST"},{default:e.withCtx(()=>t[15]||(t[15]=[e.createTextVNode("POST")])),_:1}),e.createVNode(b,{value:"PUT"},{default:e.withCtx(()=>t[16]||(t[16]=[e.createTextVNode("PUT")])),_:1}),e.createVNode(b,{value:"DELETE"},{default:e.withCtx(()=>t[17]||(t[17]=[e.createTextVNode("DELETE")])),_:1}),e.createVNode(b,{value:"OPTIONS"},{default:e.withCtx(()=>t[18]||(t[18]=[e.createTextVNode("OPTIONS")])),_:1})]),_:1},8,["value"]),e.createVNode(V,{value:u.value,"onUpdate:value":t[2]||(t[2]=p=>u.value=p),placeholder:"路径",size:"small"},null,8,["value"])])]),e.createElementVNode("div",A,[e.createVNode(g,{modelValue:f.value,"onUpdate:modelValue":t[3]||(t[3]=p=>f.value=p),"add-button-text":"添加参数","show-preview":!0,"preview-text":m.value+u.value+ae.value},null,8,["modelValue","preview-text"])])]),_:1}),e.createVNode(E,{title:"认证方案",class:"form-section",size:"small"},{default:e.withCtx(()=>[e.createVNode(O,{value:a.value,"onUpdate:value":t[4]||(t[4]=p=>a.value=p),"button-style":"solid",size:"small"},{default:e.withCtx(()=>[e.createVNode(B,{value:"none"},{default:e.withCtx(()=>t[19]||(t[19]=[e.createTextVNode("无认证")])),_:1}),e.createVNode(B,{value:"Basic"},{default:e.withCtx(()=>t[20]||(t[20]=[e.createTextVNode("Basic认证")])),_:1}),e.createVNode(B,{value:"Bearer"},{default:e.withCtx(()=>t[21]||(t[21]=[e.createTextVNode("Bearer认证")])),_:1})]),_:1},8,["value"]),a.value==="Basic"?(e.openBlock(),e.createElementBlock("div",K,[e.createElementVNode("div",M,[t[22]||(t[22]=e.createElementVNode("p",{class:"m-0 w-16"},"用户名",-1)),e.createVNode(V,{value:i.value,"onUpdate:value":t[5]||(t[5]=p=>i.value=p),size:"small"},null,8,["value"])]),e.createElementVNode("div",G,[t[23]||(t[23]=e.createElementVNode("p",{class:"m-0 w-16"},"密码",-1)),e.createVNode(de,{value:s.value,"onUpdate:value":t[6]||(t[6]=p=>s.value=p),size:"small"},null,8,["value"])])])):e.createCommentVNode("",!0),a.value==="Bearer"?(e.openBlock(),e.createElementBlock("div",W,[e.createElementVNode("div",X,[t[24]||(t[24]=e.createElementVNode("p",{class:"m-0 w-16 h-full"},"Token",-1)),e.createVNode(U,{value:c.value,"onUpdate:value":t[7]||(t[7]=p=>c.value=p),size:"small",class:"mt-1",rows:"4",placeholder:"请输入Token"},null,8,["value"])])])):e.createCommentVNode("",!0)]),_:1}),e.createVNode(E,{title:"请求头",class:"form-section",size:"small"},{default:e.withCtx(()=>[e.createVNode(g,{modelValue:C.value,"onUpdate:modelValue":t[8]||(t[8]=p=>C.value=p),"add-button-text":"添加请求头","show-preview":!1},null,8,["modelValue"])]),_:1}),r.value==="POST"||r.value==="PUT"?(e.openBlock(),e.createBlock(E,{key:0,title:"请求体",class:"form-section",size:"small"},{default:e.withCtx(()=>[e.createVNode(O,{value:w.value,"onUpdate:value":t[9]||(t[9]=p=>w.value=p),"button-style":"solid",size:"small",class:"mb-1"},{default:e.withCtx(()=>[e.createVNode(B,{value:"application/json"},{default:e.withCtx(()=>t[25]||(t[25]=[e.createTextVNode("JSON")])),_:1}),e.createVNode(B,{value:"multipart/form-data"},{default:e.withCtx(()=>t[26]||(t[26]=[e.createTextVNode("Form Data")])),_:1}),e.createVNode(B,{value:"text/plain"},{default:e.withCtx(()=>t[27]||(t[27]=[e.createTextVNode("Raw")])),_:1})]),_:1},8,["value"]),w.value==="application/json"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createVNode(U,{value:x.value,"onUpdate:value":t[10]||(t[10]=p=>x.value=p),rows:6,placeholder:"请输入 JSON 数据",onInput:ne},null,8,["value"]),k.value?(e.openBlock(),e.createBlock(pe,{key:0,type:"error",message:k.value,banner:"",style:{"margin-bottom":"8px"}},null,8,["message"])):e.createCommentVNode("",!0)],64)):e.createCommentVNode("",!0),w.value==="multipart/form-data"?(e.openBlock(),e.createBlock(g,{key:1,modelValue:_.value,"onUpdate:modelValue":t[11]||(t[11]=p=>_.value=p),"add-button-text":"添加表单字段","show-preview":!1},null,8,["modelValue"])):e.createCommentVNode("",!0),w.value==="text/plain"?(e.openBlock(),e.createBlock(U,{key:2,value:N.value,"onUpdate:value":t[12]||(t[12]=p=>N.value=p),rows:6,placeholder:"请输入原始数据"},null,8,["value"])):e.createCommentVNode("",!0),e.createElementVNode("pre",null,e.toDisplayString(le.value),1)]),_:1})):e.createCommentVNode("",!0)]),_:1})])}}}),[["__scopeId","data-v-c9f65487"]]);async function Q(o,y="xhr"){return y==="fetch"?Y(o):Z(o)}async function Y(o){var m;const y=o.params.filter(a=>!!a.key).map(a=>`${a.key}=${encodeURIComponent(a.value)}`).join("&"),d=`${o.url}${o.path}${y?"?"+y:""}`,n=new Headers;o.headers.forEach(a=>{a.key&&n.append(a.key,a.value)});const r={method:o.method,headers:n,credentials:"omit"};if(o.auth.type==="Basic"&&o.auth.username&&o.auth.password){const a=btoa(`${o.auth.username}:${o.auth.password}`);n.append("Authorization",`Basic ${a}`)}else o.auth.type==="Bearer"&&o.auth.token&&n.append("Authorization",`Bearer ${o.auth.token}`);if(o.method==="POST"||o.method==="PUT")switch(o.body.type){case"application/json":r.body=o.body.json||"",n.set("Content-Type","application/json; charset=utf-8");break;case"multipart/form-data":const a=new FormData;(m=o.body.formData)==null||m.forEach(u=>{u.key&&a.append(u.key,u.value)}),r.body=a;break;case"text/plain":r.body=o.body.raw||"",n.set("Content-Type","text/plain; charset=utf-8");break}try{const a=await fetch(d,r),u={};a.headers.forEach((c,f)=>{u[f.toLowerCase()]=c});let i="";if((u["content-type"]||"").startsWith("application/json"))try{const c=await a.json();i=JSON.stringify(c,null,2)}catch{i=await a.text()}else i=await a.text();return{status:a.status.toString(),headers:u,body:i}}catch{throw new Error("Request failed")}}async function Z(o){return new Promise((y,d)=>{var i;const n=new XMLHttpRequest,r=o.auth.type==="Basic"?o.auth.username:null,m=o.auth.type==="Basic"?o.auth.password:null,a=o.params.filter(s=>!!s.key).map(s=>`${s.key}=${encodeURIComponent(s.value)}`).join("&"),u=`${o.url}${o.path}${a?"?"+a:""}`;if(n.open(o.method,u,!0,r,m),o.headers.forEach(s=>{s.key&&n.setRequestHeader(s.key,s.value)}),o.auth.type==="Bearer"&&o.auth.token&&n.setRequestHeader("Authorization",`Bearer ${o.auth.token}`),o.method==="POST"||o.method==="PUT"){let s="";switch(o.body.type){case"application/json":s=o.body.json||"",n.setRequestHeader("Content-Type","application/json; charset=utf-8");break;case"multipart/form-data":const c=new FormData;(i=o.body.formData)==null||i.forEach(f=>{f.key&&c.append(f.key,f.value)}),s=c;break;case"text/plain":s=o.body.raw||"",n.setRequestHeader("Content-Type","text/plain; charset=utf-8");break}n.send(s)}else n.send();n.onload=()=>{const s=ee(n),c={status:n.status.toString(),headers:s,body:""};if((s["content-type"]||"").startsWith("application/json"))try{c.body=JSON.stringify(JSON.parse(n.responseText),null,2)}catch{c.body=n.responseText}else c.body=n.responseText;y(c)},n.onerror=()=>{d(new Error("Request failed"))}})}function ee(o){const y=o.getAllResponseHeaders().trim().split(/[\r\n]+/),d={};return y.forEach(function(n){var u;const r=n.split(": "),m=((u=r.shift())==null?void 0:u.toLowerCase())||"",a=r.join(": ");d[m]=a}),d}h.KeyValueInput=g,h.RequestForm=R,h.default=R,h.defaultRequestSchema=j,h.executeRequest=Q,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
4
|
+
${w.value}\r
|
|
5
|
+
`).join("")+`--${i}--\r
|
|
6
|
+
`;case"text/plain":return k.value||"-空-";default:return"-空-"}}),ue=()=>{try{V.value&&(JSON.parse(V.value),x.value="")}catch{x.value="Invalid JSON format"}},fe=()=>{try{const i=u.value,t=new URL(i);u.value=`${t.protocol}//${t.host}`,m.value=t.pathname;const w=new URLSearchParams(t.search),g=[];w.forEach((b,$)=>{g.push({key:$,value:b})}),f.value=g}catch(i){console.error("URL解析失败:",i)}},ye=e.computed(()=>{if(!u.value)return!1;try{const i=u.value,t=new URL(i);return t.search!==""||t.pathname!=="/"}catch{return!1}});return(i,t)=>{const w=e.resolveComponent("a-input"),g=e.resolveComponent("a-button"),b=e.resolveComponent("a-select-option"),$=e.resolveComponent("a-select"),T=e.resolveComponent("a-card"),B=e.resolveComponent("a-radio-button"),D=e.resolveComponent("a-radio-group"),Ve=e.resolveComponent("a-input-password"),R=e.resolveComponent("a-textarea"),xe=e.resolveComponent("a-alert"),Ne=e.resolveComponent("a-form");return e.openBlock(),e.createElementBlock("div",F,[e.createVNode(Ne,{layout:"vertical"},{default:e.withCtx(()=>[e.createVNode(T,{title:"URL配置",class:"form-section",size:"small"},{default:e.withCtx(()=>[e.createElementVNode("div",H,[e.createElementVNode("div",M,[e.createVNode(w,{value:u.value,"onUpdate:value":t[0]||(t[0]=c=>u.value=c),placeholder:"基础URL",size:"small"},null,8,["value"]),ye.value?(e.openBlock(),e.createBlock(g,{key:0,type:"primary",size:"small",onClick:fe},{default:e.withCtx(()=>t[13]||(t[13]=[e.createTextVNode("拆解")])),_:1})):e.createCommentVNode("",!0)]),e.createElementVNode("div",A,[e.createVNode($,{value:r.value,"onUpdate:value":t[1]||(t[1]=c=>r.value=c),class:"w-40",size:"small"},{default:e.withCtx(()=>[e.createVNode(b,{value:"GET"},{default:e.withCtx(()=>t[14]||(t[14]=[e.createTextVNode("GET")])),_:1}),e.createVNode(b,{value:"POST"},{default:e.withCtx(()=>t[15]||(t[15]=[e.createTextVNode("POST")])),_:1}),e.createVNode(b,{value:"PUT"},{default:e.withCtx(()=>t[16]||(t[16]=[e.createTextVNode("PUT")])),_:1}),e.createVNode(b,{value:"DELETE"},{default:e.withCtx(()=>t[17]||(t[17]=[e.createTextVNode("DELETE")])),_:1}),e.createVNode(b,{value:"OPTIONS"},{default:e.withCtx(()=>t[18]||(t[18]=[e.createTextVNode("OPTIONS")])),_:1})]),_:1},8,["value"]),e.createVNode(w,{value:m.value,"onUpdate:value":t[2]||(t[2]=c=>m.value=c),placeholder:"路径",size:"small"},null,8,["value"])])]),e.createElementVNode("div",K,[e.createVNode(E,{modelValue:f.value,"onUpdate:modelValue":t[3]||(t[3]=c=>f.value=c),"add-button-text":"添加参数","show-preview":!0,"preview-text":u.value+m.value+ce.value},null,8,["modelValue","preview-text"])])]),_:1}),e.createVNode(T,{title:"认证方案",class:"form-section",size:"small"},{default:e.withCtx(()=>[e.createVNode(D,{value:n.value,"onUpdate:value":t[4]||(t[4]=c=>n.value=c),"button-style":"solid",size:"small"},{default:e.withCtx(()=>[e.createVNode(B,{value:"none"},{default:e.withCtx(()=>t[19]||(t[19]=[e.createTextVNode("无认证")])),_:1}),e.createVNode(B,{value:"Basic"},{default:e.withCtx(()=>t[20]||(t[20]=[e.createTextVNode("Basic认证")])),_:1}),e.createVNode(B,{value:"Bearer"},{default:e.withCtx(()=>t[21]||(t[21]=[e.createTextVNode("Bearer认证")])),_:1})]),_:1},8,["value"]),n.value==="Basic"?(e.openBlock(),e.createElementBlock("div",G,[e.createElementVNode("div",W,[t[22]||(t[22]=e.createElementVNode("p",{class:"m-0 w-16"},"用户名",-1)),e.createVNode(w,{value:s.value,"onUpdate:value":t[5]||(t[5]=c=>s.value=c),size:"small"},null,8,["value"])]),e.createElementVNode("div",X,[t[23]||(t[23]=e.createElementVNode("p",{class:"m-0 w-16"},"密码",-1)),e.createVNode(Ve,{value:o.value,"onUpdate:value":t[6]||(t[6]=c=>o.value=c),size:"small"},null,8,["value"])])])):e.createCommentVNode("",!0),n.value==="Bearer"?(e.openBlock(),e.createElementBlock("div",Q,[e.createElementVNode("div",Y,[t[24]||(t[24]=e.createElementVNode("p",{class:"m-0 w-16 h-full"},"Token",-1)),e.createVNode(R,{value:p.value,"onUpdate:value":t[7]||(t[7]=c=>p.value=c),size:"small",class:"mt-1",rows:"4",placeholder:"请输入Token"},null,8,["value"])])])):e.createCommentVNode("",!0)]),_:1}),e.createVNode(T,{title:"请求头",class:"form-section",size:"small"},{default:e.withCtx(()=>[e.createVNode(E,{modelValue:h.value,"onUpdate:modelValue":t[8]||(t[8]=c=>h.value=c),"add-button-text":"添加请求头","show-preview":!1},null,8,["modelValue"])]),_:1}),r.value==="POST"||r.value==="PUT"?(e.openBlock(),e.createBlock(T,{key:0,title:"请求体",class:"form-section",size:"small"},{default:e.withCtx(()=>[e.createVNode(D,{value:N.value,"onUpdate:value":t[9]||(t[9]=c=>N.value=c),"button-style":"solid",size:"small",class:"mb-1"},{default:e.withCtx(()=>[e.createVNode(B,{value:"application/json"},{default:e.withCtx(()=>t[25]||(t[25]=[e.createTextVNode("JSON")])),_:1}),e.createVNode(B,{value:"multipart/form-data"},{default:e.withCtx(()=>t[26]||(t[26]=[e.createTextVNode("Form Data")])),_:1}),e.createVNode(B,{value:"text/plain"},{default:e.withCtx(()=>t[27]||(t[27]=[e.createTextVNode("Raw")])),_:1})]),_:1},8,["value"]),N.value==="application/json"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createVNode(R,{value:V.value,"onUpdate:value":t[10]||(t[10]=c=>V.value=c),rows:6,placeholder:"请输入 JSON 数据",onInput:ue},null,8,["value"]),x.value?(e.openBlock(),e.createBlock(xe,{key:0,type:"error",message:x.value,banner:"",style:{"margin-bottom":"8px"}},null,8,["message"])):e.createCommentVNode("",!0)],64)):e.createCommentVNode("",!0),N.value==="multipart/form-data"?(e.openBlock(),e.createBlock(E,{key:1,modelValue:C.value,"onUpdate:modelValue":t[11]||(t[11]=c=>C.value=c),"add-button-text":"添加表单字段","show-preview":!1},null,8,["modelValue"])):e.createCommentVNode("",!0),N.value==="text/plain"?(e.openBlock(),e.createBlock(R,{key:2,value:k.value,"onUpdate:value":t[12]||(t[12]=c=>k.value=c),rows:6,placeholder:"请输入原始数据"},null,8,["value"])):e.createCommentVNode("",!0),e.createElementVNode("pre",null,e.toDisplayString(me.value),1)]),_:1})):e.createCommentVNode("",!0)]),_:1})])}}}),[["__scopeId","data-v-c9f65487"]]);async function O(a,y="xhr"){return y==="fetch"?Z(a):ee(a)}async function Z(a){var u;const y=a.params.filter(n=>!!n.key).map(n=>`${n.key}=${encodeURIComponent(n.value)}`).join("&"),d=`${a.url}${a.path}${y?"?"+y:""}`,l=new Headers;a.headers.forEach(n=>{n.key&&l.append(n.key,n.value)});const r={method:a.method,headers:l,credentials:"omit"};if(a.auth.type==="Basic"&&a.auth.username&&a.auth.password){const n=btoa(`${a.auth.username}:${a.auth.password}`);l.append("Authorization",`Basic ${n}`)}else a.auth.type==="Bearer"&&a.auth.token&&l.append("Authorization",`Bearer ${a.auth.token}`);if(a.method==="POST"||a.method==="PUT")switch(a.body.type){case"application/json":r.body=a.body.json||"",l.set("Content-Type","application/json; charset=utf-8");break;case"multipart/form-data":const n=new FormData;(u=a.body.formData)==null||u.forEach(m=>{m.key&&n.append(m.key,m.value)}),r.body=n;break;case"text/plain":r.body=a.body.raw||"",l.set("Content-Type","text/plain; charset=utf-8");break}try{const n=await fetch(d,r),m={};n.headers.forEach((p,f)=>{m[f.toLowerCase()]=p});let s="";if((m["content-type"]||"").startsWith("application/json"))try{const p=await n.json();s=JSON.stringify(p,null,2)}catch{s=await n.text()}else s=await n.text();return{status:n.status.toString(),headers:m,body:s}}catch{throw new Error("Request failed")}}async function ee(a){return new Promise((y,d)=>{var s;const l=new XMLHttpRequest,r=a.auth.type==="Basic"?a.auth.username:null,u=a.auth.type==="Basic"?a.auth.password:null,n=a.params.filter(o=>!!o.key).map(o=>`${o.key}=${encodeURIComponent(o.value)}`).join("&"),m=`${a.url}${a.path}${n?"?"+n:""}`;if(l.open(a.method,m,!0,r,u),a.headers.forEach(o=>{o.key&&l.setRequestHeader(o.key,o.value)}),a.auth.type==="Bearer"&&a.auth.token&&l.setRequestHeader("Authorization",`Bearer ${a.auth.token}`),a.method==="POST"||a.method==="PUT"){let o="";switch(a.body.type){case"application/json":o=a.body.json||"",l.setRequestHeader("Content-Type","application/json; charset=utf-8");break;case"multipart/form-data":const p=new FormData;(s=a.body.formData)==null||s.forEach(f=>{f.key&&p.append(f.key,f.value)}),o=p;break;case"text/plain":o=a.body.raw||"",l.setRequestHeader("Content-Type","text/plain; charset=utf-8");break}l.send(o)}else l.send();l.onload=()=>{const o=te(l),p={status:l.status.toString(),headers:o,body:""};if((o["content-type"]||"").startsWith("application/json"))try{p.body=JSON.stringify(JSON.parse(l.responseText),null,2)}catch{p.body=l.responseText}else p.body=l.responseText;y(p)},l.onerror=()=>{d(new Error("Request failed"))}})}function te(a){const y=a.getAllResponseHeaders().trim().split(/[\r\n]+/),d={};return y.forEach(function(l){var m;const r=l.split(": "),u=((m=r.shift())==null?void 0:m.toLowerCase())||"",n=r.join(": ");d[u]=n}),d}const oe={style:{display:"flex","align-items":"center",gap:"8px","margin-bottom":"8px"}},ae={class:"flex flex-col gap-2"},le={class:"flex flex-col gap-1"},ne={key:0,class:"border border-solid border-gray-300 w-full"},re={class:"border border-gray-300"},se={class:"border border-gray-300"},de={key:1},ie=S(e.defineComponent({__name:"ResponseSection",props:{modelValue:{}},setup(a){const y=a,d=e.ref("xhr"),l=e.ref({status:"",headers:{},body:"",timing:0}),r=e.ref(""),u=s=>{const o=Number(s);return o>=200&&o<300?"success":o>=300&&o<400?"warning":o>=400&&o<500||o>=500?"error":"default"},n=s=>s instanceof Error?s.message:"请求失败",m=async()=>{r.value="";const s=Date.now();try{l.value=await O(y.modelValue,d.value),l.value.timing=Date.now()-s}catch(o){r.value=n(o),l.value={status:"Error",headers:{},body:o instanceof Error?o.message:"Request failed",timing:Date.now()-s}}};return(s,o)=>{const p=e.resolveComponent("a-radio-button"),f=e.resolveComponent("a-radio-group"),h=e.resolveComponent("a-button"),C=e.resolveComponent("a-alert"),N=e.resolveComponent("a-tag"),V=e.resolveComponent("a-textarea"),k=e.resolveComponent("a-card");return e.openBlock(),e.createBlock(k,{title:"响应",class:"form-section",size:"small"},{default:e.withCtx(()=>[e.createElementVNode("div",oe,[e.createVNode(f,{value:d.value,"onUpdate:value":o[0]||(o[0]=x=>d.value=x),"button-style":"solid",size:"small"},{default:e.withCtx(()=>[e.createVNode(p,{value:"xhr"},{default:e.withCtx(()=>o[2]||(o[2]=[e.createTextVNode("XMLHttpRequest")])),_:1}),e.createVNode(p,{value:"fetch"},{default:e.withCtx(()=>o[3]||(o[3]=[e.createTextVNode("Fetch")])),_:1})]),_:1},8,["value"]),e.createVNode(h,{type:"primary",onClick:m,size:"small"},{default:e.withCtx(()=>o[4]||(o[4]=[e.createTextVNode("发送")])),_:1})]),r.value?(e.openBlock(),e.createBlock(C,{key:0,message:r.value,type:"error","show-icon":"",style:{"margin-bottom":"8px"}},null,8,["message"])):e.createCommentVNode("",!0),e.createElementVNode("div",ae,[o[7]||(o[7]=e.createElementVNode("div",{class:"text-sm font-bold"},"基本信息",-1)),e.createElementVNode("div",le,[e.createElementVNode("div",null,[o[5]||(o[5]=e.createElementVNode("span",null,"状态码:",-1)),e.createVNode(N,{color:u(l.value.status)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(l.value.status),1)]),_:1},8,["color"])]),e.createElementVNode("div",null,[o[6]||(o[6]=e.createElementVNode("span",null,"耗时:",-1)),e.createElementVNode("span",null,e.toDisplayString(l.value.timing?`${l.value.timing}ms`:"-"),1)])]),o[8]||(o[8]=e.createElementVNode("div",{class:"text-sm font-bold"},"响应头",-1)),Object.keys(l.value.headers).length>0?(e.openBlock(),e.createElementBlock("table",ne,[e.createElementVNode("tbody",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Object.entries(l.value.headers),([x,U])=>(e.openBlock(),e.createElementBlock("tr",{key:x},[e.createElementVNode("td",re,e.toDisplayString(x),1),e.createElementVNode("td",se,e.toDisplayString(U),1)]))),128))])])):(e.openBlock(),e.createElementBlock("p",de,"无响应头")),o[9]||(o[9]=e.createElementVNode("div",{class:"text-sm font-bold"},"响应体",-1)),e.createVNode(V,{value:l.value.body,"onUpdate:value":o[1]||(o[1]=x=>l.value.body=x),rows:5,readonly:"",style:{width:"100%"},size:"small"},null,8,["value"])])]),_:1})}}}),[["__scopeId","data-v-1dd2b288"]]);_.KeyValueInput=E,_.RequestForm=q,_.ResponseSection=ie,_.default=q,_.defaultRequestSchema=j,_.executeRequest=O,Object.defineProperties(_,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.key-value-input[data-v-1e5ef051]{width:100%}.empty-state[data-v-1e5ef051]{color:#999;text-align:center;padding:8px 0}.key-value-input[data-v-1e5ef051] .ant-typography pre{background-color:#f5f5f5;padding:4px 8px;border-radius:4px;margin:0;width:100%;overflow-x:auto}.key-value-input[data-v-1e5ef051] .ant-space-item{flex:1}.key-value-input[data-v-1e5ef051] .ant-space-item:first-child{flex:0 0 100px}.key-value-input[data-v-1e5ef051] .ant-space-item:nth-child(2){flex:0 0 200px}.key-value-input[data-v-1e5ef051] .ant-list-item{padding:4px 0}[data-v-1e5ef051] .ant-typography pre{background-color:#f5f5f5;padding:8px;border-radius:4px;margin:0;width:100%;overflow-x:auto;max-height:60px;font-size:12px;line-height:1.5}.request-form[data-v-c9f65487]{margin:0;padding:0}.request-form[data-v-c9f65487] *{font-size:.9rem}.form-section[data-v-c9f65487]{margin-bottom:8px;width:100%}[data-v-c9f65487] .ant-card-head{background-color:#fafafa}[data-v-c9f65487] .ant-card-head-title{font-weight:500;padding:4px 0}[data-v-c9f65487] .ant-card-body{padding:8px 12px}[data-v-c9f65487] .ant-space{width:100%;display:flex;gap:8px;align-items:center}pre[data-v-c9f65487]{background-color:#f5f5f5;padding:8px;border-radius:4px;margin:0;width:100%;overflow-x:auto}
|
|
1
|
+
.key-value-input[data-v-1e5ef051]{width:100%}.empty-state[data-v-1e5ef051]{color:#999;text-align:center;padding:8px 0}.key-value-input[data-v-1e5ef051] .ant-typography pre{background-color:#f5f5f5;padding:4px 8px;border-radius:4px;margin:0;width:100%;overflow-x:auto}.key-value-input[data-v-1e5ef051] .ant-space-item{flex:1}.key-value-input[data-v-1e5ef051] .ant-space-item:first-child{flex:0 0 100px}.key-value-input[data-v-1e5ef051] .ant-space-item:nth-child(2){flex:0 0 200px}.key-value-input[data-v-1e5ef051] .ant-list-item{padding:4px 0}[data-v-1e5ef051] .ant-typography pre{background-color:#f5f5f5;padding:8px;border-radius:4px;margin:0;width:100%;overflow-x:auto;max-height:60px;font-size:12px;line-height:1.5}.request-form[data-v-c9f65487]{margin:0;padding:0}.request-form[data-v-c9f65487] *{font-size:.9rem}.form-section[data-v-c9f65487]{margin-bottom:8px;width:100%}[data-v-c9f65487] .ant-card-head{background-color:#fafafa}[data-v-c9f65487] .ant-card-head-title{font-weight:500;padding:4px 0}[data-v-c9f65487] .ant-card-body{padding:8px 12px}[data-v-c9f65487] .ant-space{width:100%;display:flex;gap:8px;align-items:center}pre[data-v-c9f65487]{background-color:#f5f5f5;padding:8px;border-radius:4px;margin:0;width:100%;overflow-x:auto}.form-section[data-v-1dd2b288]{margin-bottom:8px}.response-section[data-v-1dd2b288]{margin-bottom:16px}.section-title[data-v-1dd2b288]{font-size:14px;font-weight:500;color:#1f1f1f;margin-bottom:8px;padding-left:4px;border-left:3px solid #1890ff}[data-v-1dd2b288] .ant-card-head{background-color:#fafafa}[data-v-1dd2b288] .ant-card-head-title{font-weight:500;padding:4px 0}[data-v-1dd2b288] .ant-card-body{padding:8px 12px}[data-v-1dd2b288] .ant-descriptions-item-label{font-weight:500}
|
package/lib/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import RequestForm from './components/RequestForm.vue';
|
|
2
|
+
import ResponseSection from './components/ResponseSection.vue';
|
|
2
3
|
import KeyValueInput from './components/KeyValueInput.vue';
|
|
3
4
|
import type { RequestSchema, KeyValuePair, ResponseData } from './types/request';
|
|
4
5
|
import { defaultRequestSchema } from './types/request';
|
|
@@ -6,6 +7,7 @@ import { executeRequest } from './utils/request';
|
|
|
6
7
|
|
|
7
8
|
export {
|
|
8
9
|
RequestForm,
|
|
10
|
+
ResponseSection,
|
|
9
11
|
KeyValueInput,
|
|
10
12
|
type RequestSchema,
|
|
11
13
|
type KeyValuePair,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-api-request-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.umd.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"ant-design-vue": "4.x",
|
|
24
|
-
"vue": "^3.5.13"
|
|
24
|
+
"vue": "^3.5.13",
|
|
25
|
+
"vue-api-request-builder": "^0.1.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@types/node": "^20.0.0",
|