Showing
5 changed files
with
104 additions
and
26 deletions
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | <div class="flex flex-col justify-between"> |
| 3 | 3 | <div ref="jsoneditorRef" style="height: 100%; width: 100%"></div> |
| 4 | 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 | 6 | <template #icon> |
| 7 | 7 | <CopyOutlined /> |
| 8 | 8 | </template> |
| ... | ... | @@ -42,11 +42,7 @@ |
| 42 | 42 | mode: 'code', |
| 43 | 43 | mainMenuBar: false, |
| 44 | 44 | statusBar: false, |
| 45 | - onFocus: () => { | |
| 46 | - if (props.showBtn) { | |
| 47 | - setJsonValue('测试结果为'); | |
| 48 | - } | |
| 49 | - }, | |
| 45 | + onFocus: () => {}, | |
| 50 | 46 | onBlur: () => {}, |
| 51 | 47 | onChangeText: (e) => { |
| 52 | 48 | if (props.showBtn) { | ... | ... |
| ... | ... | @@ -100,6 +100,8 @@ |
| 100 | 100 | |
| 101 | 101 | const isShowTestResult = ref(false); |
| 102 | 102 | |
| 103 | + const postBodyType = ref(''); | |
| 104 | + | |
| 103 | 105 | //执行测试接口 |
| 104 | 106 | const handleExcute = () => { |
| 105 | 107 | emits('emitExcute'); |
| ... | ... | @@ -123,6 +125,7 @@ |
| 123 | 125 | isToken.value = Objects?.Params?.token; |
| 124 | 126 | const body = Objects?.Body?.params; |
| 125 | 127 | isPostToken.value = Objects?.Body?.token; |
| 128 | + postBodyType.value = Objects?.Body?.type; | |
| 126 | 129 | apiUrl.value = url?.restfulFormat(params); |
| 127 | 130 | if (isWebSocketType.value === '2') { |
| 128 | 131 | socketUrls.value = url; |
| ... | ... | @@ -143,7 +146,8 @@ |
| 143 | 146 | params, |
| 144 | 147 | body, |
| 145 | 148 | isToken.value, |
| 146 | - isPostToken.value | |
| 149 | + isPostToken.value, | |
| 150 | + postBodyType.value | |
| 147 | 151 | ); |
| 148 | 152 | if (!resp) return; |
| 149 | 153 | if (Object.prototype.toString.call(resp) === '[object Object]') { |
| ... | ... | @@ -151,7 +155,10 @@ |
| 151 | 155 | } else if (typeof resp === 'string') { |
| 152 | 156 | jsonEditorRef.value?.setJsonValue(resp); |
| 153 | 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 | 162 | } else { |
| 156 | 163 | jsonEditorRef.value?.setJsonValue(JSON.stringify(resp)); |
| 157 | 164 | } |
| ... | ... | @@ -217,14 +224,19 @@ |
| 217 | 224 | body, |
| 218 | 225 | token, |
| 219 | 226 | postToken, |
| 227 | + postBodyType, | |
| 220 | 228 | joinPrefix = false |
| 221 | 229 | ) => { |
| 222 | 230 | const { convertObj } = useUtils(); |
| 223 | 231 | switch (apiType) { |
| 224 | 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 | 240 | return await otherHttp.get( |
| 229 | 241 | { url: apiUrl, params, headers: objGet }, |
| 230 | 242 | { |
| ... | ... | @@ -235,9 +247,26 @@ |
| 235 | 247 | } |
| 236 | 248 | ); |
| 237 | 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 | 270 | return await otherHttp.post( |
| 242 | 271 | { url: `${apiUrl}?${convertObj(params)}`, data: body, headers: objPost }, |
| 243 | 272 | { | ... | ... |
| ... | ... | @@ -82,6 +82,46 @@ export const schemas: FormSchema[] = [ |
| 82 | 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 | 126 | field: 'requestContentType', |
| 87 | 127 | label: '请求方式', |
| ... | ... | @@ -190,9 +230,17 @@ export const schemas: FormSchema[] = [ |
| 190 | 230 | slot: 'slotFillAddress', |
| 191 | 231 | colProps: { span: 24 }, |
| 192 | 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 | 33 | </template> |
| 34 | 34 | <template #slotFillAddress="{ model }"> |
| 35 | 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 | 49 | <Tag |
| 37 | 50 | v-if="model['originUrlType'] === 'server_url'" |
| 38 | 51 | color="blue" |
| ... | ... | @@ -45,15 +58,6 @@ |
| 45 | 58 | ` |
| 46 | 59 | }} |
| 47 | 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 | 61 | </div> |
| 58 | 62 | </template> |
| 59 | 63 | </BasicForm> | ... | ... |