Showing
5 changed files
with
104 additions
and
26 deletions
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | <div class="flex flex-col justify-between"> | 2 | <div class="flex flex-col justify-between"> |
3 | <div ref="jsoneditorRef" style="height: 100%; width: 100%"></div> | 3 | <div ref="jsoneditorRef" style="height: 100%; width: 100%"></div> |
4 | <div class="ml-2 -mt-1.5"> | 4 | <div class="ml-2 -mt-1.5"> |
5 | - <Button v-if="showBtn" @click="onHandleCopy" class="mt-8"> | 5 | + <Button v-if="showBtn" @click="onHandleCopy" class="mt-8 -ml-2"> |
6 | <template #icon> | 6 | <template #icon> |
7 | <CopyOutlined /> | 7 | <CopyOutlined /> |
8 | </template> | 8 | </template> |
@@ -42,11 +42,7 @@ | @@ -42,11 +42,7 @@ | ||
42 | mode: 'code', | 42 | mode: 'code', |
43 | mainMenuBar: false, | 43 | mainMenuBar: false, |
44 | statusBar: false, | 44 | statusBar: false, |
45 | - onFocus: () => { | ||
46 | - if (props.showBtn) { | ||
47 | - setJsonValue('测试结果为'); | ||
48 | - } | ||
49 | - }, | 45 | + onFocus: () => {}, |
50 | onBlur: () => {}, | 46 | onBlur: () => {}, |
51 | onChangeText: (e) => { | 47 | onChangeText: (e) => { |
52 | if (props.showBtn) { | 48 | if (props.showBtn) { |
@@ -100,6 +100,8 @@ | @@ -100,6 +100,8 @@ | ||
100 | 100 | ||
101 | const isShowTestResult = ref(false); | 101 | const isShowTestResult = ref(false); |
102 | 102 | ||
103 | + const postBodyType = ref(''); | ||
104 | + | ||
103 | //执行测试接口 | 105 | //执行测试接口 |
104 | const handleExcute = () => { | 106 | const handleExcute = () => { |
105 | emits('emitExcute'); | 107 | emits('emitExcute'); |
@@ -123,6 +125,7 @@ | @@ -123,6 +125,7 @@ | ||
123 | isToken.value = Objects?.Params?.token; | 125 | isToken.value = Objects?.Params?.token; |
124 | const body = Objects?.Body?.params; | 126 | const body = Objects?.Body?.params; |
125 | isPostToken.value = Objects?.Body?.token; | 127 | isPostToken.value = Objects?.Body?.token; |
128 | + postBodyType.value = Objects?.Body?.type; | ||
126 | apiUrl.value = url?.restfulFormat(params); | 129 | apiUrl.value = url?.restfulFormat(params); |
127 | if (isWebSocketType.value === '2') { | 130 | if (isWebSocketType.value === '2') { |
128 | socketUrls.value = url; | 131 | socketUrls.value = url; |
@@ -143,7 +146,8 @@ | @@ -143,7 +146,8 @@ | ||
143 | params, | 146 | params, |
144 | body, | 147 | body, |
145 | isToken.value, | 148 | isToken.value, |
146 | - isPostToken.value | 149 | + isPostToken.value, |
150 | + postBodyType.value | ||
147 | ); | 151 | ); |
148 | if (!resp) return; | 152 | if (!resp) return; |
149 | if (Object.prototype.toString.call(resp) === '[object Object]') { | 153 | if (Object.prototype.toString.call(resp) === '[object Object]') { |
@@ -151,7 +155,10 @@ | @@ -151,7 +155,10 @@ | ||
151 | } else if (typeof resp === 'string') { | 155 | } else if (typeof resp === 'string') { |
152 | jsonEditorRef.value?.setJsonValue(resp); | 156 | jsonEditorRef.value?.setJsonValue(resp); |
153 | } else if (Array.isArray(resp)) { | 157 | } else if (Array.isArray(resp)) { |
154 | - jsonEditorRef.value?.setJsonValue(JSON.stringify(resp)); | 158 | + const temp = { |
159 | + data: resp, | ||
160 | + }; | ||
161 | + jsonEditorRef.value?.setJsonValue(temp); | ||
155 | } else { | 162 | } else { |
156 | jsonEditorRef.value?.setJsonValue(JSON.stringify(resp)); | 163 | jsonEditorRef.value?.setJsonValue(JSON.stringify(resp)); |
157 | } | 164 | } |
@@ -217,14 +224,19 @@ | @@ -217,14 +224,19 @@ | ||
217 | body, | 224 | body, |
218 | token, | 225 | token, |
219 | postToken, | 226 | postToken, |
227 | + postBodyType, | ||
220 | joinPrefix = false | 228 | joinPrefix = false |
221 | ) => { | 229 | ) => { |
222 | const { convertObj } = useUtils(); | 230 | const { convertObj } = useUtils(); |
223 | switch (apiType) { | 231 | switch (apiType) { |
224 | case 'GET': | 232 | case 'GET': |
225 | - const objGet = Object.assign({}, headers, { | ||
226 | - 'X-Authorization': `Bearer ${!token ? postToken : token}`, | ||
227 | - }); | 233 | + const objGet = Object.assign( |
234 | + {}, | ||
235 | + { | ||
236 | + 'X-Authorization': `Bearer ${!token ? postToken : token}`, | ||
237 | + }, | ||
238 | + headers | ||
239 | + ); | ||
228 | return await otherHttp.get( | 240 | return await otherHttp.get( |
229 | { url: apiUrl, params, headers: objGet }, | 241 | { url: apiUrl, params, headers: objGet }, |
230 | { | 242 | { |
@@ -235,9 +247,26 @@ | @@ -235,9 +247,26 @@ | ||
235 | } | 247 | } |
236 | ); | 248 | ); |
237 | case 'POST': | 249 | case 'POST': |
238 | - const objPost = Object.assign({}, headers, { | ||
239 | - 'X-Authorization': `Bearer ${!postToken ? token : postToken}`, | ||
240 | - }); | 250 | + console.log(postBodyType); |
251 | + const objPost = Object.assign( | ||
252 | + {}, | ||
253 | + { | ||
254 | + 'X-Authorization': `Bearer ${!postToken ? token : postToken}`, | ||
255 | + }, | ||
256 | + { | ||
257 | + 'Content-Type': | ||
258 | + postBodyType === 'xml' | ||
259 | + ? 'text/xml' | ||
260 | + : postBodyType === 'form-data' | ||
261 | + ? 'multipart/form-data' | ||
262 | + : postBodyType === 'x-www-form-urlencoded' | ||
263 | + ? 'application/x-www-form-urlencoded' | ||
264 | + : postBodyType === 'json' | ||
265 | + ? 'application/json' | ||
266 | + : 'none', | ||
267 | + }, | ||
268 | + headers | ||
269 | + ); | ||
241 | return await otherHttp.post( | 270 | return await otherHttp.post( |
242 | { url: `${apiUrl}?${convertObj(params)}`, data: body, headers: objPost }, | 271 | { url: `${apiUrl}?${convertObj(params)}`, data: body, headers: objPost }, |
243 | { | 272 | { |
@@ -82,6 +82,46 @@ export const schemas: FormSchema[] = [ | @@ -82,6 +82,46 @@ export const schemas: FormSchema[] = [ | ||
82 | placeholder: '请输入接口名称', | 82 | placeholder: '请输入接口名称', |
83 | }, | 83 | }, |
84 | }, | 84 | }, |
85 | + // { | ||
86 | + // field: 'interfaceType', | ||
87 | + // component: 'ApiRadioGroup', | ||
88 | + // label: '接口类型', | ||
89 | + // required: true, | ||
90 | + // colProps: { | ||
91 | + // span: 8, | ||
92 | + // }, | ||
93 | + // defaultValue: 'SYSTEM', | ||
94 | + // componentProps: { | ||
95 | + // api: findDictItemByCode, | ||
96 | + // params: { | ||
97 | + // dictCode: 'interface_Type', | ||
98 | + // }, | ||
99 | + // labelField: 'itemText', | ||
100 | + // valueField: 'itemValue', | ||
101 | + // }, | ||
102 | + // }, | ||
103 | + { | ||
104 | + field: 'interfaceType', | ||
105 | + component: 'ApiRadioGroup', | ||
106 | + label: '接口类型', | ||
107 | + required: true, | ||
108 | + colProps: { | ||
109 | + span: 8, | ||
110 | + }, | ||
111 | + defaultValue: 'SYSTEM', | ||
112 | + componentProps: { | ||
113 | + options: [ | ||
114 | + { | ||
115 | + label: '系统默认', | ||
116 | + value: 'SYSTEM', | ||
117 | + }, | ||
118 | + { | ||
119 | + label: '自定义', | ||
120 | + value: 'CUSTOM', | ||
121 | + }, | ||
122 | + ], | ||
123 | + }, | ||
124 | + }, | ||
85 | { | 125 | { |
86 | field: 'requestContentType', | 126 | field: 'requestContentType', |
87 | label: '请求方式', | 127 | label: '请求方式', |
@@ -190,9 +230,17 @@ export const schemas: FormSchema[] = [ | @@ -190,9 +230,17 @@ export const schemas: FormSchema[] = [ | ||
190 | slot: 'slotFillAddress', | 230 | slot: 'slotFillAddress', |
191 | colProps: { span: 24 }, | 231 | colProps: { span: 24 }, |
192 | ifShow: ({ values }) => { | 232 | ifShow: ({ values }) => { |
193 | - if (values['requestOriginUrl']) { | ||
194 | - return true; | ||
195 | - } else return false; | 233 | + return values['originUrlType'] === 'custom_url' && values['requestOriginUrl']; |
234 | + }, | ||
235 | + }, | ||
236 | + { | ||
237 | + field: 'slotServerAddress', | ||
238 | + label: '完整地址', | ||
239 | + component: 'Input', | ||
240 | + slot: 'slotServerAddress', | ||
241 | + colProps: { span: 24 }, | ||
242 | + ifShow: ({ values }) => { | ||
243 | + return values['originUrlType'] === 'server_url'; | ||
196 | }, | 244 | }, |
197 | }, | 245 | }, |
198 | { | 246 | { |
@@ -33,6 +33,19 @@ | @@ -33,6 +33,19 @@ | ||
33 | </template> | 33 | </template> |
34 | <template #slotFillAddress="{ model }"> | 34 | <template #slotFillAddress="{ model }"> |
35 | <div> | 35 | <div> |
36 | + <template v-if="model['originUrlType'] === 'custom_url'"> | ||
37 | + <Tag | ||
38 | + v-if="model['requestOriginUrl']" | ||
39 | + color="blue" | ||
40 | + style="width: 35vw; white-space: normal; height: auto" | ||
41 | + > | ||
42 | + {{ ` ${model['requestOriginUrl'] + model['requestHttpTypeAndUrl']?.requestUrl}` }} | ||
43 | + </Tag> | ||
44 | + </template> | ||
45 | + </div> | ||
46 | + </template> | ||
47 | + <template #slotServerAddress="{ model }"> | ||
48 | + <div> | ||
36 | <Tag | 49 | <Tag |
37 | v-if="model['originUrlType'] === 'server_url'" | 50 | v-if="model['originUrlType'] === 'server_url'" |
38 | color="blue" | 51 | color="blue" |
@@ -45,15 +58,6 @@ | @@ -45,15 +58,6 @@ | ||
45 | ` | 58 | ` |
46 | }} | 59 | }} |
47 | </Tag> | 60 | </Tag> |
48 | - <template v-else> | ||
49 | - <Tag | ||
50 | - v-if="model['requestOriginUrl']" | ||
51 | - color="blue" | ||
52 | - style="width: 35vw; white-space: normal; height: auto" | ||
53 | - > | ||
54 | - {{ ` ${model['requestOriginUrl'] + model['requestHttpTypeAndUrl']?.requestUrl}` }} | ||
55 | - </Tag> | ||
56 | - </template> | ||
57 | </div> | 61 | </div> |
58 | </template> | 62 | </template> |
59 | </BasicForm> | 63 | </BasicForm> |