|
@@ -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
|
|