Commit 13c29cba67851eb07a74f7d8058bb1cdc7051094
Merge branch 'fix/tcp-switch-command-send' into 'main_dev'
fix: 修复tcp开关下发命令通过modbus获取命令 See merge request yunteng/thingskit-scada!207
Showing
1 changed file
with
14 additions
and
4 deletions
1 | -import { h, render } from 'vue' | 1 | +import { h, render, unref } from 'vue' |
2 | import { ControlComponentEnum } from '../packages/Control' | 2 | import { ControlComponentEnum } from '../packages/Control' |
3 | +import { useGetModbusCommand } from '../components/PublicForm/components/DataEvents/CommandDeliveryModal/useGetModbusCommand' | ||
3 | import { doCommandDelivery, getDeviceActive, getDeviceInfo } from '@/api/device' | 4 | import { doCommandDelivery, getDeviceActive, getDeviceInfo } from '@/api/device' |
4 | import type { MouseUpEventDataType, NodeDataDataSourceJsonType, NodeDataEventJsonType, SingleClickEventDataType } from '@/api/node/model' | 5 | import type { MouseUpEventDataType, NodeDataDataSourceJsonType, NodeDataEventJsonType, SingleClickEventDataType } from '@/api/node/model' |
5 | import { CommandWayEnum } from '@/enums/commandEnum' | 6 | import { CommandWayEnum } from '@/enums/commandEnum' |
6 | -import { ActRangListItemTypeEnum, EventActionTypeEnum, TransportTypeEnum } from '@/enums/datasource' | 7 | +import { ActRangListItemTypeEnum, CodeTypeEnum, EventActionTypeEnum, TransportTypeEnum } from '@/enums/datasource' |
7 | import { useMessage } from '@/hooks/web/useMessage' | 8 | import { useMessage } from '@/hooks/web/useMessage' |
8 | import { AttributeDeliverModal, CommandDeliveryConfirmModal, CommandDeliveryModal, ConfirmModal } from '@/core/Library/components/PublicForm/components/DataEvents/CommandDeliveryModal' | 9 | import { AttributeDeliverModal, CommandDeliveryConfirmModal, CommandDeliveryModal, ConfirmModal } from '@/core/Library/components/PublicForm/components/DataEvents/CommandDeliveryModal' |
9 | import type { MxCell } from '@/fitCore/types' | 10 | import type { MxCell } from '@/fitCore/types' |
@@ -76,7 +77,7 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N | @@ -76,7 +77,7 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N | ||
76 | const nodeUtils = new NodeUtils() | 77 | const nodeUtils = new NodeUtils() |
77 | const { way = CommandWayEnum.ONE_WAY } = data | 78 | const { way = CommandWayEnum.ONE_WAY } = data |
78 | const { attr, deviceId, attrInfo } = dataSourceJson | 79 | const { attr, deviceId, attrInfo } = dataSourceJson |
79 | - const { transportType, alias, name: deviceName } = await getDeviceInfo(dataSourceJson.deviceId) || {}// 设备信息 | 80 | + const { transportType, alias, name: deviceName, code, codeType } = await getDeviceInfo(dataSourceJson.deviceId) || {}// 设备信息 |
80 | const contentDataStore = useContentDataStoreWithOut() | 81 | const contentDataStore = useContentDataStoreWithOut() |
81 | const currentData = contentDataStore.contentData.find(item => item.id === cell.getId()) | 82 | const currentData = contentDataStore.contentData.find(item => item.id === cell.getId()) |
82 | if (!currentData) return | 83 | if (!currentData) return |
@@ -95,6 +96,7 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N | @@ -95,6 +96,7 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N | ||
95 | const res = rangeList.find(item => item.type === (status === ActRangListItemTypeEnum.OPEN ? ActRangListItemTypeEnum.CLOSE : ActRangListItemTypeEnum.OPEN)) | 96 | const res = rangeList.find(item => item.type === (status === ActRangListItemTypeEnum.OPEN ? ActRangListItemTypeEnum.CLOSE : ActRangListItemTypeEnum.OPEN)) |
96 | if (!res) return | 97 | if (!res) return |
97 | const { statusValue } = res | 98 | const { statusValue } = res |
99 | + | ||
98 | command.params = transportType === TransportTypeEnum.TCP | 100 | command.params = transportType === TransportTypeEnum.TCP |
99 | ? statusValue! | 101 | ? statusValue! |
100 | : { | 102 | : { |
@@ -104,7 +106,7 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N | @@ -104,7 +106,7 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N | ||
104 | if (operationPasswordEnable) { | 106 | if (operationPasswordEnable) { |
105 | const instance = h(CommandDeliveryConfirmModal) | 107 | const instance = h(CommandDeliveryConfirmModal) |
106 | render(instance, document.body) | 108 | render(instance, document.body) |
107 | - await (instance.component?.exposed as InstanceType<typeof CommandDeliveryConfirmModal>)?.open(operationPassword) | 109 | + await (instance.component?.exposed as InstanceType<typeof CommandDeliveryConfirmModal>)?.open(operationPassword!) |
108 | } | 110 | } |
109 | else { | 111 | else { |
110 | const instance = h(ConfirmModal) | 112 | const instance = h(ConfirmModal) |
@@ -112,6 +114,14 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N | @@ -112,6 +114,14 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N | ||
112 | await (instance.component?.exposed as InstanceType<typeof ConfirmModal>)?.open() | 114 | await (instance.component?.exposed as InstanceType<typeof ConfirmModal>)?.open() |
113 | } | 115 | } |
114 | 116 | ||
117 | + if (transportType === TransportTypeEnum.TCP && codeType === CodeTypeEnum.MODBUS_RTU) { | ||
118 | + const { validateCanGetCommand, getModbusCommand } = useGetModbusCommand() | ||
119 | + if (!validateCanGetCommand(unref(dataSourceJson).attrInfo.extensionDesc, code).flag) return | ||
120 | + const res = await getModbusCommand(statusValue!, unref(dataSourceJson).attrInfo.extensionDesc!, code) | ||
121 | + if (!res) return | ||
122 | + command.params = res | ||
123 | + } | ||
124 | + | ||
115 | await doCommandDelivery({ way, command, deviceId }) | 125 | await doCommandDelivery({ way, command, deviceId }) |
116 | createMessage.success('命令下发成功') | 126 | createMessage.success('命令下发成功') |
117 | } | 127 | } |