Skip to content

Commit 824f8d6

Browse files
committed
处理请求头参数encodeURIComponent
1 parent 6329aa8 commit 824f8d6

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/views/apiDetail/debug/Index.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
</template>
125125

126126
<script lang="ts">
127-
import { defineComponent, reactive, PropType, watchEffect, toRefs, computed } from "vue";
127+
import { defineComponent, reactive, PropType, watchEffect, toRefs, computed, watch } from "vue";
128128
import { ApiDetailState, FileData, UploadFileState } from "../interface";
129129
import { Table, Button, message, Upload, Alert, Empty } from "ant-design-vue";
130130
import { ReloadOutlined } from "@ant-design/icons-vue";
@@ -271,11 +271,14 @@ export default defineComponent({
271271
return [];
272272
}
273273
274-
watchEffect(() => {
275-
if (props.detail.header) {
276-
state.headerData = renderHeaderData(props.detail.header);
274+
watch(
275+
() => props.detail.header,
276+
() => {
277+
state.headerData = renderHeaderData(props.detail.header as ParamItem[]);
277278
}
278-
});
279+
);
280+
state.headerData = renderHeaderData(props.detail.header as ParamItem[]);
281+
279282
watchEffect(() => {
280283
if (props.detail.param) {
281284
const json = renderCodeJsonByParams(props.detail.param, true);
@@ -371,7 +374,7 @@ export default defineComponent({
371374
item.value &&
372375
(!item.appKey || item.appKey === "global" || item.appKey === state.appKey)
373376
) {
374-
headers[item.name] = item.value;
377+
headers[item.name] = encodeURIComponent(item.value);
375378
}
376379
});
377380
}
@@ -389,7 +392,7 @@ export default defineComponent({
389392
if (state.headerData && state.headerData.length) {
390393
state.headerData.forEach((item) => {
391394
if (item.name && item.default) {
392-
headers[item.name] = item.default;
395+
headers[item.name] = encodeURIComponent(item.default);
393396
}
394397
});
395398
}
@@ -424,6 +427,7 @@ export default defineComponent({
424427
json.data = json.params;
425428
delete json.params;
426429
}
430+
427431
Axios(url, json)
428432
.then((res) => {
429433
// 执行后置方法

src/views/apiDetail/debug/handleEvent.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Store } from "vuex";
66
import md5 from "js-md5";
77
import { t } from "@/hooks/useI18n";
88
import Axios from "@/utils/http/index";
9-
import { isArray } from "lodash";
9+
import { isArray, isObject } from "lodash";
1010
import { DebugEventEnum } from "@/enums/debugEventEnum";
1111
import moduleName from "ant-design-vue";
1212

@@ -69,7 +69,7 @@ const events = {
6969
): Promise<EventResult> {
7070
return new Promise((resolve, reject) => {
7171
if (eventItem.key) {
72-
json.headers[eventItem.key] = value;
72+
json.headers[eventItem.key] = encodeURIComponent(value);
7373
const res: EventResult = {
7474
event: eventItem,
7575
json,
@@ -279,8 +279,8 @@ const events = {
279279
}
280280
} else if (item.event === "setHeader") {
281281
if (item.key) {
282-
ajaxOptions.headers[item.key] = itemValue;
283-
} else {
282+
ajaxOptions.headers[item.key] = encodeURIComponent(itemValue);
283+
} else if (isObject(itemValue)) {
284284
ajaxOptions.headers = itemValue;
285285
}
286286
}
@@ -306,7 +306,7 @@ const events = {
306306
if (item.key && item.event === "setParam") {
307307
json.params[item.key] = itemValue;
308308
} else if (item.key && item.event === "setHeader") {
309-
json.headers[item.key] = itemValue;
309+
json.headers[item.key] = encodeURIComponent(itemValue);
310310
}
311311
}
312312
}
@@ -327,7 +327,7 @@ const events = {
327327
};
328328

329329
/**
330-
* 调试请求前事件处理
330+
* 调试请求事件处理
331331
* @param eventList
332332
* @param json
333333
* @param store

0 commit comments

Comments
 (0)