Commit 6a7475d9cdfd01b270eb671c9256a70ae381f1fe

Authored by fengwotao
1 parent 4d97259c

feat:大屏公共接口管理测试新增支持restful风格的接口测试

@@ -189,7 +189,7 @@ @@ -189,7 +189,7 @@
189 189
190 table { 190 table {
191 border-collapse: collapse; 191 border-collapse: collapse;
192 - width: 100%; 192 + width: 35vw;
193 &:extend(.table-border-color); 193 &:extend(.table-border-color);
194 } 194 }
195 195
@@ -92,7 +92,11 @@ @@ -92,7 +92,11 @@
92 }; 92 };
93 93
94 const handleTestInterface = () => { 94 const handleTestInterface = () => {
95 - const value = getValue(false); 95 + let value = getValue(false);
  96 + const type = value?.requestParamsBodyType;
  97 + if (type === 'none') value = [];
  98 + if (type === 'form-data') value = value['form-data'];
  99 + if (type === 'x-www-form-urlencoded') value = value['x-www-form-urlencoded'];
96 nextTick( 100 nextTick(
97 () => 101 () =>
98 (dataMap.mapObj = { 102 (dataMap.mapObj = {
1 <template> 1 <template>
2 <div class="table-content"> 2 <div class="table-content">
3 - <table align="center" style="width: 100%" cellspacing="0"> 3 + <table align="center">
4 <thead> 4 <thead>
5 <tr> 5 <tr>
6 <th></th> 6 <th></th>
@@ -54,6 +54,15 @@ @@ -54,6 +54,15 @@
54 :options="attributeOptions" 54 :options="attributeOptions"
55 allowClear 55 allowClear
56 /> 56 />
  57 + <a-range-picker
  58 + v-else-if="item.key === 'date'"
  59 + v-model:value="item.value"
  60 + style="width: 12vw"
  61 + :show-time="{ format: 'HH:mm' }"
  62 + format="YYYY-MM-DD HH:mm"
  63 + :placeholder="['开始', '结束']"
  64 + @ok="onRangeOk"
  65 + />
57 <Select 66 <Select
58 v-else 67 v-else
59 v-model:value="item.value" 68 v-model:value="item.value"
@@ -146,6 +155,10 @@ @@ -146,6 +155,10 @@
146 getApi(list['x-www-form-urlencoded']); 155 getApi(list['x-www-form-urlencoded']);
147 }; 156 };
148 157
  158 + const onRangeOk = (value) => {
  159 + console.log('onOk: ', value);
  160 + };
  161 +
149 const getApi = (list) => { 162 const getApi = (list) => {
150 list?.forEach(async (it) => { 163 list?.forEach(async (it) => {
151 if (it.key === 'deviceProfileId') { 164 if (it.key === 'deviceProfileId') {
@@ -158,7 +171,7 @@ @@ -158,7 +171,7 @@
158 }); 171 });
159 }; 172 };
160 173
161 - //Select互斥 174 + //TODO 待优化 Select互斥
162 const handleChange = async (e) => { 175 const handleChange = async (e) => {
163 selectOptions.value.forEach((ele) => { 176 selectOptions.value.forEach((ele) => {
164 ele.disabled = false; 177 ele.disabled = false;
@@ -257,6 +270,7 @@ @@ -257,6 +270,7 @@
257 270
258 .table-content { 271 .table-content {
259 table { 272 table {
  273 + width: 31vw;
260 &:extend(.table-border-color); 274 &:extend(.table-border-color);
261 } 275 }
262 276
@@ -35,10 +35,16 @@ @@ -35,10 +35,16 @@
35 </div> 35 </div>
36 </template> 36 </template>
37 <script lang="ts" setup name="testRequest"> 37 <script lang="ts" setup name="testRequest">
38 - import { ref, nextTick } from 'vue'; 38 + import { ref, nextTick, reactive } from 'vue';
39 import { Button } from 'ant-design-vue'; 39 import { Button } from 'ant-design-vue';
40 import { TestEditCellTable } from '../TestEditCellTable/index'; 40 import { TestEditCellTable } from '../TestEditCellTable/index';
41 import { otherHttp } from '/@/utils/http/axios'; 41 import { otherHttp } from '/@/utils/http/axios';
  42 + import moment from 'moment';
  43 + import { useWebSocket } from '@vueuse/core';
  44 + import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum';
  45 + import { getAuthCache } from '/@/utils/auth';
  46 + import { useMessage } from '/@/hooks/web/useMessage';
  47 + import { useGlobSetting } from '/@/hooks/setting';
42 48
43 const emits = defineEmits(['testInterface']); 49 const emits = defineEmits(['testInterface']);
44 50
@@ -51,6 +57,19 @@ @@ -51,6 +57,19 @@
51 }, 57 },
52 }); 58 });
53 59
  60 + const { createMessage } = useMessage();
  61 +
  62 + const token = getAuthCache(JWT_TOKEN_KEY);
  63 +
  64 + const { socketUrl } = useGlobSetting();
  65 +
  66 + const socketMessage = reactive({
  67 + server: `${socketUrl}${token}`,
  68 + sendValue: {
  69 + tsSubCmds: [],
  70 + },
  71 + });
  72 +
54 const showTestEditCell = ref(false); 73 const showTestEditCell = ref(false);
55 74
56 const testEditCellTableRef = ref<InstanceType<typeof TestEditCellTable>>(); 75 const testEditCellTableRef = ref<InstanceType<typeof TestEditCellTable>>();
@@ -113,13 +132,41 @@ @@ -113,13 +132,41 @@
113 return formatString(this, replacements); 132 return formatString(this, replacements);
114 }; 133 };
115 134
116 - //项目自带第三方请求 135 + //TODO 待优化 项目自带第三方请求
117 const otherHttpRequest = async (apiType, params = {}, api, joinPrefix = false) => { 136 const otherHttpRequest = async (apiType, params = {}, api, joinPrefix = false) => {
118 - console.log(params);  
119 switch (apiType) { 137 switch (apiType) {
120 case 'get': 138 case 'get':
  139 + Reflect.deleteProperty(params, 'deviceProfileId');
  140 + Reflect.deleteProperty(params, 'organizationId');
  141 + Reflect.deleteProperty(params, 'entityId');
  142 + Reflect.deleteProperty(params, 'entityType');
  143 + Reflect.deleteProperty(params, 'scope');
  144 + Reflect.deleteProperty(params, 'id');
  145 + Reflect.deleteProperty(params, 'type');
  146 + if (params['date']) {
  147 + Reflect.set(params, 'startTs', moment(params['date'][0]).valueOf());
  148 + Reflect.set(params, 'endTs', moment(params['date'][1]).valueOf());
  149 + Reflect.deleteProperty(params, 'date');
  150 + } else {
  151 + }
121 return await otherHttp.get( 152 return await otherHttp.get(
122 - { url: api }, 153 + { url: api, params },
  154 + {
  155 + apiUrl: '',
  156 + joinPrefix,
  157 + }
  158 + );
  159 + case 'post':
  160 + return await otherHttp.post(
  161 + { url: api, data: params },
  162 + {
  163 + apiUrl: '',
  164 + joinPrefix,
  165 + }
  166 + );
  167 + case 'put':
  168 + return await otherHttp.put(
  169 + { url: api, data: params },
123 { 170 {
124 apiUrl: '', 171 apiUrl: '',
125 joinPrefix, 172 joinPrefix,
@@ -131,11 +178,12 @@ @@ -131,11 +178,12 @@
131 const getValue = async () => { 178 const getValue = async () => {
132 await nextTick(); 179 await nextTick();
133 await nextTick(() => { 180 await nextTick(() => {
134 - const getSingleKey = props.data?.list?.filter((it: any) => it.key.split(',').length === 1); 181 + const getSingleKey = props.data?.list;
135 const getMuteKey = props.data?.list?.filter((it: any) => it.key.split(',').length > 1); 182 const getMuteKey = props.data?.list?.filter((it: any) => it.key.split(',').length > 1);
136 const getMuteKeys = getMultipleKeys(getMuteKey); 183 const getMuteKeys = getMultipleKeys(getMuteKey);
137 - const getSingleKeys = getMultipleKeys(getSingleKey);  
138 - const mergeKeys = [...getSingleKeys, ...getMuteKeys]; 184 + const mergeKeys = [...getSingleKey, ...getMuteKeys]?.filter(
  185 + (it: any) => it.key.split(',').length === 1
  186 + );
139 testEditCellTableRef.value?.setTableArray(mergeKeys); 187 testEditCellTableRef.value?.setTableArray(mergeKeys);
140 }); 188 });
141 }; 189 };
@@ -147,12 +195,37 @@ @@ -147,12 +195,37 @@
147 const getTable = getTestTableKeyValue(); 195 const getTable = getTestTableKeyValue();
148 const apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestUrl}`; 196 const apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestUrl}`;
149 const apiType = props.data?.paramsType.toLowerCase(); 197 const apiType = props.data?.paramsType.toLowerCase();
150 - const getKeyValues = {};  
151 - getTable?.map((it) => (getKeyValues[it.key!] = it.value!));  
152 - const formatApi = apiGetUrl.restfulFormat(getKeyValues);  
153 - const rest = await otherHttpRequest(apiType, {}, formatApi, false);  
154 - if (!rest) return;  
155 - testResult.value = rest; 198 + const params: any = {};
  199 + getTable?.map((it) => (params[it.key!] = it.value!));
  200 + if (props.method === '0') {
  201 + //普通请求
  202 + const formatApi = apiGetUrl.restfulFormat(params);
  203 + const rest = await otherHttpRequest(apiType, params, formatApi.split('{?')[0], false);
  204 + testResult.value = JSON.stringify(rest);
  205 + } else if (props.method === '2') {
  206 + //websocket请求
  207 + Reflect.deleteProperty(params, 'deviceProfileId');
  208 + Reflect.deleteProperty(params, 'organizationId');
  209 + Reflect.set(params, 'cmdId', Number(params?.cmdId));
  210 + socketMessage.sendValue.tsSubCmds.push(params);
  211 + const { send, close } = useWebSocket(socketMessage.server, {
  212 + onConnected() {
  213 + send(JSON.stringify(socketMessage.sendValue));
  214 + console.log('建立连接了');
  215 + },
  216 + onMessage(_, e) {
  217 + const { data } = JSON.parse(e.data);
  218 + testResult.value = JSON.stringify(data);
  219 + },
  220 + onDisconnected() {
  221 + console.log('断开连接了');
  222 + close();
  223 + },
  224 + onError() {
  225 + createMessage.error('webSocket连接超时,请联系管理员');
  226 + },
  227 + });
  228 + }
156 }); 229 });
157 }; 230 };
158 231
@@ -124,7 +124,7 @@ export const schemas: FormSchema[] = [ @@ -124,7 +124,7 @@ export const schemas: FormSchema[] = [
124 required: true, 124 required: true,
125 component: 'Input', 125 component: 'Input',
126 componentProps: { 126 componentProps: {
127 - maxLength: 64, 127 + maxLength: 255,
128 placeholder: '请输入源地址', 128 placeholder: '请输入源地址',
129 }, 129 },
130 }, 130 },
@@ -154,7 +154,7 @@ export const schemas: FormSchema[] = [ @@ -154,7 +154,7 @@ export const schemas: FormSchema[] = [
154 required: true, 154 required: true,
155 colProps: { span: 18 }, 155 colProps: { span: 18 },
156 componentProps: { 156 componentProps: {
157 - maxLength: 64, 157 + maxLength: 255,
158 placeholder: '请输入接口地址', 158 placeholder: '请输入接口地址',
159 }, 159 },
160 ifShow: ({ values }) => 160 ifShow: ({ values }) =>