Showing
9 changed files
with
72 additions
and
78 deletions
| @@ -52,6 +52,8 @@ | @@ -52,6 +52,8 @@ | ||
| 52 | }, | 52 | }, |
| 53 | }); | 53 | }); |
| 54 | 54 | ||
| 55 | + const emits = defineEmits(['resetValue']); | ||
| 56 | + | ||
| 55 | const { pushObj } = useUtils(); | 57 | const { pushObj } = useUtils(); |
| 56 | 58 | ||
| 57 | const bodyCellFormDataTableRef = ref<InstanceType<typeof BodyTable>>(); | 59 | const bodyCellFormDataTableRef = ref<InstanceType<typeof BodyTable>>(); |
| @@ -63,6 +65,7 @@ | @@ -63,6 +65,7 @@ | ||
| 63 | const handleChange = ({ target }) => { | 65 | const handleChange = ({ target }) => { |
| 64 | const { value } = target; | 66 | const { value } = target; |
| 65 | getRequestBody.content.requestParamsBodyType = value; | 67 | getRequestBody.content.requestParamsBodyType = value; |
| 68 | + emits('resetValue', value); | ||
| 66 | }; | 69 | }; |
| 67 | 70 | ||
| 68 | //获取数据 | 71 | //获取数据 |
| @@ -17,8 +17,9 @@ | @@ -17,8 +17,9 @@ | ||
| 17 | key="Body" | 17 | key="Body" |
| 18 | tab="Body" | 18 | tab="Body" |
| 19 | > | 19 | > |
| 20 | - <Body ref="bodyRef" /> | 20 | + <Body ref="bodyRef" @resetValue="handleResetValue" /> |
| 21 | <BodyTest | 21 | <BodyTest |
| 22 | + v-if="bodyType !== 'none'" | ||
| 22 | @testBodyInterface="handleTestBodyInterface" | 23 | @testBodyInterface="handleTestBodyInterface" |
| 23 | ref="testBodyRequestRef" | 24 | ref="testBodyRequestRef" |
| 24 | :data="dataMap.mapBodyObj" | 25 | :data="dataMap.mapBodyObj" |
| @@ -70,6 +71,8 @@ | @@ -70,6 +71,8 @@ | ||
| 70 | 71 | ||
| 71 | const excuteData = ref({}); | 72 | const excuteData = ref({}); |
| 72 | 73 | ||
| 74 | + const bodyType = ref(''); | ||
| 75 | + | ||
| 73 | const paramsCellTableRef = ref<InstanceType<typeof ParamsTable>>(); | 76 | const paramsCellTableRef = ref<InstanceType<typeof ParamsTable>>(); |
| 74 | 77 | ||
| 75 | const editHeaderCellTableRef = ref<InstanceType<typeof ParamsTable>>(); | 78 | const editHeaderCellTableRef = ref<InstanceType<typeof ParamsTable>>(); |
| @@ -90,15 +93,18 @@ | @@ -90,15 +93,18 @@ | ||
| 90 | mapHeaderObj: {}, | 93 | mapHeaderObj: {}, |
| 91 | }); | 94 | }); |
| 92 | 95 | ||
| 93 | - const handleChange = () => { | ||
| 94 | - excuteTestRef.value?.resetValue(); | 96 | + const handleChange = () => excuteTestRef.value?.resetValue(false); |
| 97 | + | ||
| 98 | + const handleResetValue = (v) => { | ||
| 99 | + bodyType.value = v; | ||
| 100 | + handleClickReset(); | ||
| 95 | }; | 101 | }; |
| 96 | 102 | ||
| 97 | const handleClickReset = () => { | 103 | const handleClickReset = () => { |
| 98 | testParamsRequestRef.value?.setValue(); | 104 | testParamsRequestRef.value?.setValue(); |
| 99 | testHeaderRequestRef.value?.setValue(); | 105 | testHeaderRequestRef.value?.setValue(); |
| 100 | testBodyRequestRef.value?.setValue(); | 106 | testBodyRequestRef.value?.setValue(); |
| 101 | - excuteTestRef.value?.resetValue(); | 107 | + excuteTestRef.value?.resetValue(true); |
| 102 | }; | 108 | }; |
| 103 | 109 | ||
| 104 | //if-else-if-else分支优化 | 110 | //if-else-if-else分支优化 |
| @@ -160,14 +166,14 @@ | @@ -160,14 +166,14 @@ | ||
| 160 | }; | 166 | }; |
| 161 | 167 | ||
| 162 | const handleTestBodyInterface = () => { | 168 | const handleTestBodyInterface = () => { |
| 163 | - excuteTestRef.value?.showTest(); | ||
| 164 | let value = getValue(false) as any; | 169 | let value = getValue(false) as any; |
| 165 | const type = value?.Body?.requestParamsBodyType; | 170 | const type = value?.Body?.requestParamsBodyType; |
| 166 | - //取出对应的类型的值 | 171 | + excuteTestRef.value?.showTest(); |
| 167 | let values = []; | 172 | let values = []; |
| 168 | for (let i in value?.Body) if (i === type) values = value?.Body[i]; | 173 | for (let i in value?.Body) if (i === type) values = value?.Body[i]; |
| 169 | dataMap.mapBodyObj = { | 174 | dataMap.mapBodyObj = { |
| 170 | list: values, | 175 | list: values, |
| 176 | + type, | ||
| 171 | ...getCompose(), | 177 | ...getCompose(), |
| 172 | }; | 178 | }; |
| 173 | }; | 179 | }; |
| @@ -8,7 +8,15 @@ | @@ -8,7 +8,15 @@ | ||
| 8 | <a-row type="flex" justify="center"> | 8 | <a-row type="flex" justify="center"> |
| 9 | <a-col :span="3"> 参数设置 </a-col> | 9 | <a-col :span="3"> 参数设置 </a-col> |
| 10 | <a-col :span="21"> | 10 | <a-col :span="21"> |
| 11 | - <TestBodyCellTable ref="testEditCellTableRef" /> | 11 | + <div v-if="data?.type === 'x-www-form-urlencoded' || data?.type === 'form-data'"> |
| 12 | + <TestBodyCellTable ref="testEditCellTableRef" /> | ||
| 13 | + </div> | ||
| 14 | + <div style="width: 30vw" v-else-if="data?.type === 'json'"> | ||
| 15 | + <JsonEditor ref="jsonEditorRef" /> | ||
| 16 | + </div> | ||
| 17 | + <div style="width: 30vw" v-else-if="data?.type === 'xml'"> | ||
| 18 | + <a-textarea v-model:value="xmlContent" placeholder="请输入xml" :rows="6" /> | ||
| 19 | + </div> | ||
| 12 | </a-col> | 20 | </a-col> |
| 13 | </a-row> | 21 | </a-row> |
| 14 | </div> | 22 | </div> |
| @@ -22,6 +30,7 @@ | @@ -22,6 +30,7 @@ | ||
| 22 | import TestBodyCellTable from './testEditBodyCellTable.vue'; | 30 | import TestBodyCellTable from './testEditBodyCellTable.vue'; |
| 23 | import moment from 'moment'; | 31 | import moment from 'moment'; |
| 24 | import { useUtils } from '../../../hooks/useUtils'; | 32 | import { useUtils } from '../../../hooks/useUtils'; |
| 33 | + import JsonEditor from '../../SimpleRequest/components/jsonEditor.vue'; | ||
| 25 | 34 | ||
| 26 | const emits = defineEmits(['testBodyInterface']); | 35 | const emits = defineEmits(['testBodyInterface']); |
| 27 | 36 | ||
| @@ -35,8 +44,12 @@ | @@ -35,8 +44,12 @@ | ||
| 35 | 44 | ||
| 36 | const excuteData = ref({}); | 45 | const excuteData = ref({}); |
| 37 | 46 | ||
| 47 | + const xmlContent = ref(''); | ||
| 48 | + | ||
| 38 | const testEditCellTableRef = ref<InstanceType<typeof TestBodyCellTable>>(); | 49 | const testEditCellTableRef = ref<InstanceType<typeof TestBodyCellTable>>(); |
| 39 | 50 | ||
| 51 | + const jsonEditorRef = ref<InstanceType<typeof JsonEditor>>(); | ||
| 52 | + | ||
| 40 | const testResult = ref(''); | 53 | const testResult = ref(''); |
| 41 | 54 | ||
| 42 | const { getMultipleKeys } = useUtils(); | 55 | const { getMultipleKeys } = useUtils(); |
| @@ -50,14 +63,20 @@ | @@ -50,14 +63,20 @@ | ||
| 50 | const getValue = async () => { | 63 | const getValue = async () => { |
| 51 | await nextTick(); | 64 | await nextTick(); |
| 52 | await nextTick(() => { | 65 | await nextTick(() => { |
| 53 | - //拆分"xx,xx,xx"多个 | ||
| 54 | - const getSingleKey = props.data?.list; | ||
| 55 | - const getMuteKey = props.data?.list?.filter((it: any) => it.key.split(',').length > 1); | ||
| 56 | - const getMuteKeys = getMultipleKeys(getMuteKey); | ||
| 57 | - const mergeKeys = [...getSingleKey, ...getMuteKeys]?.filter( | ||
| 58 | - (it: any) => it.key.split(',').length === 1 | ||
| 59 | - ); | ||
| 60 | - testEditCellTableRef.value?.setTableArray(mergeKeys); | 66 | + console.log(props.data?.list); |
| 67 | + if (props.data?.type === 'x-www-form-urlencoded' || props.data?.type === 'form-data') { | ||
| 68 | + const getSingleKey = props.data?.list; | ||
| 69 | + const getMuteKey = props.data?.list?.filter((it: any) => it.key.split(',').length > 1); | ||
| 70 | + const getMuteKeys = getMultipleKeys(getMuteKey); | ||
| 71 | + const mergeKeys = [...getSingleKey, ...getMuteKeys]?.filter( | ||
| 72 | + (it: any) => it.key.split(',').length === 1 | ||
| 73 | + ); | ||
| 74 | + testEditCellTableRef.value?.setTableArray(mergeKeys); | ||
| 75 | + } else if (props.data?.type === 'json') { | ||
| 76 | + jsonEditorRef.value?.setJsonValue(props.data?.list); | ||
| 77 | + } else if (props.data?.type === 'xml') { | ||
| 78 | + xmlContent.value = props.data?.list; | ||
| 79 | + } | ||
| 61 | }); | 80 | }); |
| 62 | }; | 81 | }; |
| 63 | 82 | ||
| @@ -98,27 +117,20 @@ | @@ -98,27 +117,20 @@ | ||
| 98 | 117 | ||
| 99 | //获取数据 | 118 | //获取数据 |
| 100 | const getTestValue = () => { | 119 | const getTestValue = () => { |
| 101 | - const getTable = getTestTableKeyValue(); | ||
| 102 | - //源地址 | ||
| 103 | - let apiGetUrl = ''; | ||
| 104 | - if (props.data?.originUrlType === 'server_url') { | ||
| 105 | - const pathUrl = window.location.host; | ||
| 106 | - const protocol = window.location.protocol; | ||
| 107 | - apiGetUrl = `${protocol}//${pathUrl}`; | ||
| 108 | - } else { | ||
| 109 | - apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestTypeAndUrl?.requestUrl}`; | 120 | + let params: any = {}; |
| 121 | + if (props.data?.type === 'x-www-form-urlencoded' || props.data?.type === 'form-data') { | ||
| 122 | + const getTable = getTestTableKeyValue(); | ||
| 123 | + getTable?.map((it) => (params[it.key!] = it.value!)); | ||
| 124 | + } else if (props.data?.type === 'json') { | ||
| 125 | + params = jsonEditorRef.value?.getJsonValue(); | ||
| 126 | + } else if (props.data?.type === 'xml') { | ||
| 127 | + params = xmlContent.value; | ||
| 128 | + } | ||
| 129 | + if (params['keys']) { | ||
| 130 | + Reflect.set(params, 'keys', params['keys'].join(',')); | ||
| 110 | } | 131 | } |
| 111 | - //请求类型 | ||
| 112 | - const apiType = props.data?.requestTypeAndUrl?.requestHttpType; | ||
| 113 | - //替换key value | ||
| 114 | - const params: any = {}; | ||
| 115 | - getTable?.map((it) => (params[it.key!] = it.value!)); | ||
| 116 | excuteData.value = { | 132 | excuteData.value = { |
| 117 | - method: props.data?.method, | ||
| 118 | - apiGetUrl, | ||
| 119 | - apiType, | ||
| 120 | params, | 133 | params, |
| 121 | - activeKey: props.data?.activeKey, | ||
| 122 | }; | 134 | }; |
| 123 | return excuteData.value; | 135 | return excuteData.value; |
| 124 | }; | 136 | }; |
| @@ -45,6 +45,7 @@ | @@ -45,6 +45,7 @@ | ||
| 45 | placeholder="请选择" | 45 | placeholder="请选择" |
| 46 | notFoundContent="请选择" | 46 | notFoundContent="请选择" |
| 47 | :options="attributeOptions" | 47 | :options="attributeOptions" |
| 48 | + mode="multiple" | ||
| 48 | allowClear | 49 | allowClear |
| 49 | /> | 50 | /> |
| 50 | <div v-else-if="item.key === 'date_range'"> | 51 | <div v-else-if="item.key === 'date_range'"> |
| @@ -149,6 +150,9 @@ | @@ -149,6 +150,9 @@ | ||
| 149 | //设置数据 | 150 | //设置数据 |
| 150 | const setTableArray = (data) => { | 151 | const setTableArray = (data) => { |
| 151 | const list = cloneDeep(data); | 152 | const list = cloneDeep(data); |
| 153 | + list?.forEach((it) => { | ||
| 154 | + if (it.key === 'keys') it.value = []; | ||
| 155 | + }); | ||
| 152 | if (Array.isArray(list)) (tableTestArray.content = list) && getApi(list); | 156 | if (Array.isArray(list)) (tableTestArray.content = list) && getApi(list); |
| 153 | if (list.hasOwnProperty('form-data') && Array.isArray(list['form-data'])) | 157 | if (list.hasOwnProperty('form-data') && Array.isArray(list['form-data'])) |
| 154 | (tableTestArray.content = list['form-data']) && getApi(list['form-data']); | 158 | (tableTestArray.content = list['form-data']) && getApi(list['form-data']); |
| @@ -202,7 +206,7 @@ | @@ -202,7 +206,7 @@ | ||
| 202 | if (e.key === 'deviceProfileId') { | 206 | if (e.key === 'deviceProfileId') { |
| 203 | tableTestArray.content.forEach((f: any) => { | 207 | tableTestArray.content.forEach((f: any) => { |
| 204 | if (f.key === 'keys') { | 208 | if (f.key === 'keys') { |
| 205 | - f.value = null; | 209 | + f.value = []; |
| 206 | } | 210 | } |
| 207 | if (f.key === 'organizationId') organizationId = f.value; | 211 | if (f.key === 'organizationId') organizationId = f.value; |
| 208 | if (f.key === 'entityId') f.value = null; | 212 | if (f.key === 'entityId') f.value = null; |
| @@ -183,8 +183,10 @@ | @@ -183,8 +183,10 @@ | ||
| 183 | } | 183 | } |
| 184 | }; | 184 | }; |
| 185 | 185 | ||
| 186 | - const resetValue = () => { | ||
| 187 | - showTestFlag.value = false; | 186 | + const resetValue = (flag) => { |
| 187 | + if (flag) { | ||
| 188 | + showTestFlag.value = false; | ||
| 189 | + } | ||
| 188 | httpResult.value = '测试结果为:'; | 190 | httpResult.value = '测试结果为:'; |
| 189 | testResult.value = '测试结果为:'; | 191 | testResult.value = '测试结果为:'; |
| 190 | ifWebSocket.value = '0'; | 192 | ifWebSocket.value = '0'; |
| @@ -59,26 +59,10 @@ | @@ -59,26 +59,10 @@ | ||
| 59 | //获取数据 | 59 | //获取数据 |
| 60 | const getTestValue = () => { | 60 | const getTestValue = () => { |
| 61 | const getTable = getTestTableKeyValue(); | 61 | const getTable = getTestTableKeyValue(); |
| 62 | - //源地址 | ||
| 63 | - let apiGetUrl = ''; | ||
| 64 | - if (props.data?.originUrlType === 'server_url') { | ||
| 65 | - const pathUrl = window.location.host; | ||
| 66 | - const protocol = window.location.protocol; | ||
| 67 | - apiGetUrl = `${protocol}//${pathUrl}`; | ||
| 68 | - } else { | ||
| 69 | - apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestTypeAndUrl?.requestUrl}`; | ||
| 70 | - } | ||
| 71 | - //请求类型 | ||
| 72 | - const apiType = props.data?.requestTypeAndUrl?.requestHttpType; | ||
| 73 | - //替换key value | ||
| 74 | const params: any = {}; | 62 | const params: any = {}; |
| 75 | getTable?.map((it: any) => (params[it.key!] = it.value!)); | 63 | getTable?.map((it: any) => (params[it.key!] = it.value!)); |
| 76 | excuteData.value = { | 64 | excuteData.value = { |
| 77 | - method: props.data?.method, | ||
| 78 | - apiGetUrl, | ||
| 79 | - apiType, | ||
| 80 | params, | 65 | params, |
| 81 | - activeKey: props.data?.activeKey, | ||
| 82 | }; | 66 | }; |
| 83 | return excuteData.value; | 67 | return excuteData.value; |
| 84 | }; | 68 | }; |
| @@ -99,26 +99,13 @@ | @@ -99,26 +99,13 @@ | ||
| 99 | //获取数据 | 99 | //获取数据 |
| 100 | const getTestValue = () => { | 100 | const getTestValue = () => { |
| 101 | const getTable = getTestTableKeyValue(); | 101 | const getTable = getTestTableKeyValue(); |
| 102 | - //源地址 | ||
| 103 | - let apiGetUrl = ''; | ||
| 104 | - if (props.data?.originUrlType === 'server_url') { | ||
| 105 | - const pathUrl = window.location.host; | ||
| 106 | - const protocol = window.location.protocol; | ||
| 107 | - apiGetUrl = `${protocol}//${pathUrl}`; | ||
| 108 | - } else { | ||
| 109 | - apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestTypeAndUrl?.requestUrl}`; | ||
| 110 | - } | ||
| 111 | - //请求类型 | ||
| 112 | - const apiType = props.data?.requestTypeAndUrl?.requestHttpType; | ||
| 113 | - //替换key value | ||
| 114 | const params: any = {}; | 102 | const params: any = {}; |
| 115 | getTable?.map((it) => (params[it.key!] = it.value!)); | 103 | getTable?.map((it) => (params[it.key!] = it.value!)); |
| 104 | + if (params['keys']) { | ||
| 105 | + Reflect.set(params, 'keys', params['keys'].join(',')); | ||
| 106 | + } | ||
| 116 | excuteData.value = { | 107 | excuteData.value = { |
| 117 | - method: props.data?.method, | ||
| 118 | - apiGetUrl, | ||
| 119 | - apiType, | ||
| 120 | params, | 108 | params, |
| 121 | - activeKey: props.data?.activeKey, | ||
| 122 | }; | 109 | }; |
| 123 | return excuteData.value; | 110 | return excuteData.value; |
| 124 | }; | 111 | }; |
| @@ -45,6 +45,7 @@ | @@ -45,6 +45,7 @@ | ||
| 45 | placeholder="请选择" | 45 | placeholder="请选择" |
| 46 | notFoundContent="请选择" | 46 | notFoundContent="请选择" |
| 47 | :options="attributeOptions" | 47 | :options="attributeOptions" |
| 48 | + mode="multiple" | ||
| 48 | allowClear | 49 | allowClear |
| 49 | /> | 50 | /> |
| 50 | <div v-else-if="item.key === 'date_range'"> | 51 | <div v-else-if="item.key === 'date_range'"> |
| @@ -149,15 +150,10 @@ | @@ -149,15 +150,10 @@ | ||
| 149 | //设置数据 | 150 | //设置数据 |
| 150 | const setTableArray = (data) => { | 151 | const setTableArray = (data) => { |
| 151 | const list = cloneDeep(data); | 152 | const list = cloneDeep(data); |
| 153 | + list?.forEach((it) => { | ||
| 154 | + if (it.key === 'keys') it.value = []; | ||
| 155 | + }); | ||
| 152 | if (Array.isArray(list)) (tableTestArray.content = list) && getApi(list); | 156 | if (Array.isArray(list)) (tableTestArray.content = list) && getApi(list); |
| 153 | - if (list.hasOwnProperty('form-data') && Array.isArray(list['form-data'])) | ||
| 154 | - (tableTestArray.content = list['form-data']) && getApi(list['form-data']); | ||
| 155 | - if ( | ||
| 156 | - list.hasOwnProperty('x-www-form-urlencoded') && | ||
| 157 | - Array.isArray(list['x-www-form-urlencoded']) | ||
| 158 | - ) | ||
| 159 | - (tableTestArray.content = list['x-www-form-urlencoded']) && | ||
| 160 | - getApi(list['x-www-form-urlencoded']); | ||
| 161 | }; | 157 | }; |
| 162 | 158 | ||
| 163 | const getApi = (list) => { | 159 | const getApi = (list) => { |
| @@ -202,7 +198,7 @@ | @@ -202,7 +198,7 @@ | ||
| 202 | if (e.key === 'deviceProfileId') { | 198 | if (e.key === 'deviceProfileId') { |
| 203 | tableTestArray.content.forEach((f: any) => { | 199 | tableTestArray.content.forEach((f: any) => { |
| 204 | if (f.key === 'keys') { | 200 | if (f.key === 'keys') { |
| 205 | - f.value = null; | 201 | + f.value = []; |
| 206 | } | 202 | } |
| 207 | if (f.key === 'organizationId') organizationId = f.value; | 203 | if (f.key === 'organizationId') organizationId = f.value; |
| 208 | if (f.key === 'entityId') f.value = null; | 204 | if (f.key === 'entityId') f.value = null; |
| @@ -10,7 +10,7 @@ export type selectType = { label: string; value: string; disabled?: boolean }; | @@ -10,7 +10,7 @@ export type selectType = { label: string; value: string; disabled?: boolean }; | ||
| 10 | */ | 10 | */ |
| 11 | export type tableItems = { | 11 | export type tableItems = { |
| 12 | key: SelectValue | undefined; | 12 | key: SelectValue | undefined; |
| 13 | - value: string | SelectValue | undefined; | 13 | + value: string | SelectValue | undefined | [string]; |
| 14 | fixed_date_value?: string; | 14 | fixed_date_value?: string; |
| 15 | editDisabled?: boolean; | 15 | editDisabled?: boolean; |
| 16 | required?: boolean; | 16 | required?: boolean; |