Showing
7 changed files
with
50 additions
and
9 deletions
@@ -40,6 +40,7 @@ enum DataBoardShareUrl { | @@ -40,6 +40,7 @@ enum DataBoardShareUrl { | ||
40 | 40 | ||
41 | enum SendCommand { | 41 | enum SendCommand { |
42 | ONEWAY = '/plugins/rpc/oneway', | 42 | ONEWAY = '/plugins/rpc/oneway', |
43 | + TWOWAY = '/plugins/rpc/twoway', | ||
43 | } | 44 | } |
44 | 45 | ||
45 | enum DeviceUrl { | 46 | enum DeviceUrl { |
@@ -229,6 +230,16 @@ export const sendCommandOneway = (params: SendCommandParams) => { | @@ -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 | export const getDeviceRelation = (params: { deviceId: string; isSlave: boolean }) => { | 243 | export const getDeviceRelation = (params: { deviceId: string; isSlave: boolean }) => { |
233 | return defHttp.get<string>({ | 244 | return defHttp.get<string>({ |
234 | url: DeviceUrl.GET_DEVICE_RELATION, | 245 | url: DeviceUrl.GET_DEVICE_RELATION, |
@@ -33,6 +33,7 @@ | @@ -33,6 +33,7 @@ | ||
33 | service: value.service, | 33 | service: value.service, |
34 | command: value.command, | 34 | command: value.command, |
35 | commandType: value.commandType, | 35 | commandType: value.commandType, |
36 | + callType: value.callType, | ||
36 | }, | 37 | }, |
37 | }; | 38 | }; |
38 | return value; | 39 | return value; |
@@ -46,6 +47,7 @@ | @@ -46,6 +47,7 @@ | ||
46 | service: customCommand?.service || (record as Recordable).service, | 47 | service: customCommand?.service || (record as Recordable).service, |
47 | command: customCommand?.command || (record as Recordable).command, | 48 | command: customCommand?.command || (record as Recordable).command, |
48 | commandType: customCommand?.commandType || (record as Recordable).commandType, | 49 | commandType: customCommand?.commandType || (record as Recordable).commandType, |
50 | + callType: customCommand?.callType || (record as Recordable).callType, | ||
49 | } as unknown as Partial<CommonDataSourceBindValueType>); | 51 | } as unknown as Partial<CommonDataSourceBindValueType>); |
50 | }; | 52 | }; |
51 | 53 |
@@ -33,6 +33,7 @@ | @@ -33,6 +33,7 @@ | ||
33 | service: value.service, | 33 | service: value.service, |
34 | command: value.command, | 34 | command: value.command, |
35 | commandType: value.commandType, | 35 | commandType: value.commandType, |
36 | + callType: value.callType, | ||
36 | }, | 37 | }, |
37 | }; | 38 | }; |
38 | return value; | 39 | return value; |
@@ -46,6 +47,7 @@ | @@ -46,6 +47,7 @@ | ||
46 | service: customCommand?.service || (record as Recordable).service, | 47 | service: customCommand?.service || (record as Recordable).service, |
47 | command: customCommand?.command || (record as Recordable).command, | 48 | command: customCommand?.command || (record as Recordable).command, |
48 | commandType: customCommand?.commandType || (record as Recordable).commandType, | 49 | commandType: customCommand?.commandType || (record as Recordable).commandType, |
50 | + callType: customCommand?.callType || (record as Recordable).callType, | ||
49 | } as unknown as Partial<CommonDataSourceBindValueType>); | 51 | } as unknown as Partial<CommonDataSourceBindValueType>); |
50 | }; | 52 | }; |
51 | 53 |
@@ -33,6 +33,7 @@ | @@ -33,6 +33,7 @@ | ||
33 | service: value.service, | 33 | service: value.service, |
34 | command: value.command, | 34 | command: value.command, |
35 | commandType: value.commandType, | 35 | commandType: value.commandType, |
36 | + callType: value.callType, | ||
36 | }, | 37 | }, |
37 | }; | 38 | }; |
38 | return value; | 39 | return value; |
@@ -46,6 +47,7 @@ | @@ -46,6 +47,7 @@ | ||
46 | service: customCommand?.service || (record as Recordable).service, | 47 | service: customCommand?.service || (record as Recordable).service, |
47 | command: customCommand?.command || (record as Recordable).command, | 48 | command: customCommand?.command || (record as Recordable).command, |
48 | commandType: customCommand?.commandType || (record as Recordable).commandType, | 49 | commandType: customCommand?.commandType || (record as Recordable).commandType, |
50 | + callType: customCommand?.callType || (record as Recordable).callType, | ||
49 | } as unknown as Partial<CommonDataSourceBindValueType>); | 51 | } as unknown as Partial<CommonDataSourceBindValueType>); |
50 | }; | 52 | }; |
51 | 53 |
@@ -23,6 +23,7 @@ export interface CommonDataSourceBindValueType extends Record<DataSourceField, s | @@ -23,6 +23,7 @@ export interface CommonDataSourceBindValueType extends Record<DataSourceField, s | ||
23 | service?: string; | 23 | service?: string; |
24 | command?: string; | 24 | command?: string; |
25 | commandType?: string; | 25 | commandType?: string; |
26 | + callType?: string; | ||
26 | }; | 27 | }; |
27 | } | 28 | } |
28 | 29 | ||
@@ -44,6 +45,7 @@ export enum DataSourceField { | @@ -44,6 +45,7 @@ export enum DataSourceField { | ||
44 | COMMAND = 'command', | 45 | COMMAND = 'command', |
45 | COMMAND_TYPE = 'commandType', | 46 | COMMAND_TYPE = 'commandType', |
46 | SERVICE = 'service', | 47 | SERVICE = 'service', |
48 | + CALL_TYPE = 'callType', | ||
47 | } | 49 | } |
48 | 50 | ||
49 | const isTcpProfile = (transportType: string) => transportType === TransportTypeEnum.TCP; | 51 | const isTcpProfile = (transportType: string) => transportType === TransportTypeEnum.TCP; |
@@ -292,12 +294,22 @@ export const commonDataSourceSchemas = (): FormSchema[] => { | @@ -292,12 +294,22 @@ export const commonDataSourceSchemas = (): FormSchema[] => { | ||
292 | valueField: 'itemValue', | 294 | valueField: 'itemValue', |
293 | placeholder: '请选择命令类型', | 295 | placeholder: '请选择命令类型', |
294 | onChange() { | 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 | field: DataSourceField.SERVICE, | 313 | field: DataSourceField.SERVICE, |
302 | component: 'ApiSelect', | 314 | component: 'ApiSelect', |
303 | label: '服务', | 315 | label: '服务', |
@@ -317,7 +329,13 @@ export const commonDataSourceSchemas = (): FormSchema[] => { | @@ -317,7 +329,13 @@ export const commonDataSourceSchemas = (): FormSchema[] => { | ||
317 | api: async () => { | 329 | api: async () => { |
318 | try { | 330 | try { |
319 | if (deviceProfileId) { | 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 | } catch (error) {} | 340 | } catch (error) {} |
323 | return []; | 341 | return []; |
@@ -328,7 +346,10 @@ export const commonDataSourceSchemas = (): FormSchema[] => { | @@ -328,7 +346,10 @@ export const commonDataSourceSchemas = (): FormSchema[] => { | ||
328 | const command = value | 346 | const command = value |
329 | ? (options.functionJson.inputData || [])[0]?.serviceCommand | 347 | ? (options.functionJson.inputData || [])[0]?.serviceCommand |
330 | : null; | 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 | import { ref } from 'vue'; | 1 | import { ref } from 'vue'; |
2 | import { DataSource } from '../../palette/types'; | 2 | import { DataSource } from '../../palette/types'; |
3 | -import { sendCommandOneway } from '/@/api/dataBoard'; | 3 | +import { sendCommandOneway, sendCommandTwoway } from '/@/api/dataBoard'; |
4 | import { useMessage } from '/@/hooks/web/useMessage'; | 4 | import { useMessage } from '/@/hooks/web/useMessage'; |
5 | import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; | 5 | import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; |
6 | +import { ServiceCallTypeEnum } from '/@/enums/toolEnum'; | ||
6 | 7 | ||
7 | const { createMessage } = useMessage(); | 8 | const { createMessage } = useMessage(); |
8 | export function useSendCommand() { | 9 | export function useSendCommand() { |
@@ -16,7 +17,6 @@ export function useSendCommand() { | @@ -16,7 +17,6 @@ export function useSendCommand() { | ||
16 | const sendCommand = async (record: DataSource, value: any) => { | 17 | const sendCommand = async (record: DataSource, value: any) => { |
17 | if (!record) return false; | 18 | if (!record) return false; |
18 | const { customCommand, attribute } = record || {}; | 19 | const { customCommand, attribute } = record || {}; |
19 | - | ||
20 | const { deviceId } = record; | 20 | const { deviceId } = record; |
21 | if (!deviceId) return false; | 21 | if (!deviceId) return false; |
22 | 22 | ||
@@ -26,21 +26,23 @@ export function useSendCommand() { | @@ -26,21 +26,23 @@ export function useSendCommand() { | ||
26 | [attribute!]: Number(value), | 26 | [attribute!]: Number(value), |
27 | }; | 27 | }; |
28 | 28 | ||
29 | + let sendCommandFn = sendCommandOneway; | ||
29 | // 如果是TCP设备从物模型中获取下发命令(TCP网关子设备无物模型服务与事件) | 30 | // 如果是TCP设备从物模型中获取下发命令(TCP网关子设备无物模型服务与事件) |
30 | if (customCommand?.transportType === TransportTypeEnum.TCP) { | 31 | if (customCommand?.transportType === TransportTypeEnum.TCP) { |
31 | params = customCommand.command!; | 32 | params = customCommand.command!; |
33 | + if (customCommand.callType === ServiceCallTypeEnum.ASYNC) { | ||
34 | + sendCommandFn = sendCommandTwoway; | ||
35 | + } | ||
32 | } | 36 | } |
33 | 37 | ||
34 | - console.log(params); | ||
35 | - | ||
36 | // 控制按钮下发命令为0 或 1 | 38 | // 控制按钮下发命令为0 或 1 |
37 | - await sendCommandOneway({ | 39 | + await sendCommandFn({ |
38 | deviceId, | 40 | deviceId, |
39 | value: { | 41 | value: { |
40 | params: params || null, | 42 | params: params || null, |
41 | persistent: true, | 43 | persistent: true, |
42 | additionalInfo: { | 44 | additionalInfo: { |
43 | - cmdType: 'API', | 45 | + cmdType: customCommand.commandType || 'API', |
44 | }, | 46 | }, |
45 | method: 'methodThingskit', | 47 | method: 'methodThingskit', |
46 | }, | 48 | }, |
@@ -67,6 +67,7 @@ export interface CustomCommand { | @@ -67,6 +67,7 @@ export interface CustomCommand { | ||
67 | commandType: string; | 67 | commandType: string; |
68 | command: string; | 68 | command: string; |
69 | service: string; | 69 | service: string; |
70 | + callType: string; | ||
70 | } | 71 | } |
71 | 72 | ||
72 | export interface ComponentLayoutType { | 73 | export interface ComponentLayoutType { |