Showing
7 changed files
with
50 additions
and
9 deletions
... | ... | @@ -40,6 +40,7 @@ enum DataBoardShareUrl { |
40 | 40 | |
41 | 41 | enum SendCommand { |
42 | 42 | ONEWAY = '/plugins/rpc/oneway', |
43 | + TWOWAY = '/plugins/rpc/twoway', | |
43 | 44 | } |
44 | 45 | |
45 | 46 | enum DeviceUrl { |
... | ... | @@ -229,6 +230,16 @@ export const sendCommandOneway = (params: SendCommandParams) => { |
229 | 230 | ); |
230 | 231 | }; |
231 | 232 | |
233 | +export const sendCommandTwoway = (params: SendCommandParams) => { | |
234 | + return defHttp.post( | |
235 | + { | |
236 | + url: `${SendCommand.TWOWAY}/${params.deviceId}`, | |
237 | + params: params.value, | |
238 | + }, | |
239 | + { joinPrefix: false, withShareToken: isShareMode() } | |
240 | + ); | |
241 | +}; | |
242 | + | |
232 | 243 | export const getDeviceRelation = (params: { deviceId: string; isSlave: boolean }) => { |
233 | 244 | return defHttp.get<string>({ |
234 | 245 | url: DeviceUrl.GET_DEVICE_RELATION, | ... | ... |
... | ... | @@ -33,6 +33,7 @@ |
33 | 33 | service: value.service, |
34 | 34 | command: value.command, |
35 | 35 | commandType: value.commandType, |
36 | + callType: value.callType, | |
36 | 37 | }, |
37 | 38 | }; |
38 | 39 | return value; |
... | ... | @@ -46,6 +47,7 @@ |
46 | 47 | service: customCommand?.service || (record as Recordable).service, |
47 | 48 | command: customCommand?.command || (record as Recordable).command, |
48 | 49 | commandType: customCommand?.commandType || (record as Recordable).commandType, |
50 | + callType: customCommand?.callType || (record as Recordable).callType, | |
49 | 51 | } as unknown as Partial<CommonDataSourceBindValueType>); |
50 | 52 | }; |
51 | 53 | ... | ... |
... | ... | @@ -33,6 +33,7 @@ |
33 | 33 | service: value.service, |
34 | 34 | command: value.command, |
35 | 35 | commandType: value.commandType, |
36 | + callType: value.callType, | |
36 | 37 | }, |
37 | 38 | }; |
38 | 39 | return value; |
... | ... | @@ -46,6 +47,7 @@ |
46 | 47 | service: customCommand?.service || (record as Recordable).service, |
47 | 48 | command: customCommand?.command || (record as Recordable).command, |
48 | 49 | commandType: customCommand?.commandType || (record as Recordable).commandType, |
50 | + callType: customCommand?.callType || (record as Recordable).callType, | |
49 | 51 | } as unknown as Partial<CommonDataSourceBindValueType>); |
50 | 52 | }; |
51 | 53 | ... | ... |
... | ... | @@ -33,6 +33,7 @@ |
33 | 33 | service: value.service, |
34 | 34 | command: value.command, |
35 | 35 | commandType: value.commandType, |
36 | + callType: value.callType, | |
36 | 37 | }, |
37 | 38 | }; |
38 | 39 | return value; |
... | ... | @@ -46,6 +47,7 @@ |
46 | 47 | service: customCommand?.service || (record as Recordable).service, |
47 | 48 | command: customCommand?.command || (record as Recordable).command, |
48 | 49 | commandType: customCommand?.commandType || (record as Recordable).commandType, |
50 | + callType: customCommand?.callType || (record as Recordable).callType, | |
49 | 51 | } as unknown as Partial<CommonDataSourceBindValueType>); |
50 | 52 | }; |
51 | 53 | ... | ... |
... | ... | @@ -23,6 +23,7 @@ export interface CommonDataSourceBindValueType extends Record<DataSourceField, s |
23 | 23 | service?: string; |
24 | 24 | command?: string; |
25 | 25 | commandType?: string; |
26 | + callType?: string; | |
26 | 27 | }; |
27 | 28 | } |
28 | 29 | |
... | ... | @@ -44,6 +45,7 @@ export enum DataSourceField { |
44 | 45 | COMMAND = 'command', |
45 | 46 | COMMAND_TYPE = 'commandType', |
46 | 47 | SERVICE = 'service', |
48 | + CALL_TYPE = 'callType', | |
47 | 49 | } |
48 | 50 | |
49 | 51 | const isTcpProfile = (transportType: string) => transportType === TransportTypeEnum.TCP; |
... | ... | @@ -292,12 +294,22 @@ export const commonDataSourceSchemas = (): FormSchema[] => { |
292 | 294 | valueField: 'itemValue', |
293 | 295 | placeholder: '请选择命令类型', |
294 | 296 | onChange() { |
295 | - setFieldsValue({ [DataSourceField.COMMAND]: null, [DataSourceField.SERVICE]: null }); | |
297 | + setFieldsValue({ | |
298 | + [DataSourceField.COMMAND]: null, | |
299 | + [DataSourceField.SERVICE]: null, | |
300 | + [DataSourceField.CALL_TYPE]: null, | |
301 | + }); | |
296 | 302 | }, |
297 | 303 | }; |
298 | 304 | }, |
299 | 305 | }, |
300 | 306 | { |
307 | + field: DataSourceField.CALL_TYPE, | |
308 | + component: 'Input', | |
309 | + ifShow: false, | |
310 | + label: 'callType', | |
311 | + }, | |
312 | + { | |
301 | 313 | field: DataSourceField.SERVICE, |
302 | 314 | component: 'ApiSelect', |
303 | 315 | label: '服务', |
... | ... | @@ -317,7 +329,13 @@ export const commonDataSourceSchemas = (): FormSchema[] => { |
317 | 329 | api: async () => { |
318 | 330 | try { |
319 | 331 | if (deviceProfileId) { |
320 | - return await getDeviceService(deviceProfileId); | |
332 | + const services = await getDeviceService(deviceProfileId); | |
333 | + const value = formModel[DataSourceField.SERVICE]; | |
334 | + if (value) { | |
335 | + const selected = services.find((item) => item.value === value); | |
336 | + selected && setFieldsValue({ [DataSourceField.CALL_TYPE]: selected.callType }); | |
337 | + } | |
338 | + return services; | |
321 | 339 | } |
322 | 340 | } catch (error) {} |
323 | 341 | return []; |
... | ... | @@ -328,7 +346,10 @@ export const commonDataSourceSchemas = (): FormSchema[] => { |
328 | 346 | const command = value |
329 | 347 | ? (options.functionJson.inputData || [])[0]?.serviceCommand |
330 | 348 | : null; |
331 | - setFieldsValue({ [DataSourceField.COMMAND]: command }); | |
349 | + setFieldsValue({ | |
350 | + [DataSourceField.COMMAND]: command, | |
351 | + [DataSourceField.CALL_TYPE]: value ? options.callType : null, | |
352 | + }); | |
332 | 353 | }, |
333 | 354 | }; |
334 | 355 | }, | ... | ... |
1 | 1 | import { ref } from 'vue'; |
2 | 2 | import { DataSource } from '../../palette/types'; |
3 | -import { sendCommandOneway } from '/@/api/dataBoard'; | |
3 | +import { sendCommandOneway, sendCommandTwoway } from '/@/api/dataBoard'; | |
4 | 4 | import { useMessage } from '/@/hooks/web/useMessage'; |
5 | 5 | import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; |
6 | +import { ServiceCallTypeEnum } from '/@/enums/toolEnum'; | |
6 | 7 | |
7 | 8 | const { createMessage } = useMessage(); |
8 | 9 | export function useSendCommand() { |
... | ... | @@ -16,7 +17,6 @@ export function useSendCommand() { |
16 | 17 | const sendCommand = async (record: DataSource, value: any) => { |
17 | 18 | if (!record) return false; |
18 | 19 | const { customCommand, attribute } = record || {}; |
19 | - | |
20 | 20 | const { deviceId } = record; |
21 | 21 | if (!deviceId) return false; |
22 | 22 | |
... | ... | @@ -26,21 +26,23 @@ export function useSendCommand() { |
26 | 26 | [attribute!]: Number(value), |
27 | 27 | }; |
28 | 28 | |
29 | + let sendCommandFn = sendCommandOneway; | |
29 | 30 | // 如果是TCP设备从物模型中获取下发命令(TCP网关子设备无物模型服务与事件) |
30 | 31 | if (customCommand?.transportType === TransportTypeEnum.TCP) { |
31 | 32 | params = customCommand.command!; |
33 | + if (customCommand.callType === ServiceCallTypeEnum.ASYNC) { | |
34 | + sendCommandFn = sendCommandTwoway; | |
35 | + } | |
32 | 36 | } |
33 | 37 | |
34 | - console.log(params); | |
35 | - | |
36 | 38 | // 控制按钮下发命令为0 或 1 |
37 | - await sendCommandOneway({ | |
39 | + await sendCommandFn({ | |
38 | 40 | deviceId, |
39 | 41 | value: { |
40 | 42 | params: params || null, |
41 | 43 | persistent: true, |
42 | 44 | additionalInfo: { |
43 | - cmdType: 'API', | |
45 | + cmdType: customCommand.commandType || 'API', | |
44 | 46 | }, |
45 | 47 | method: 'methodThingskit', |
46 | 48 | }, | ... | ... |