Commit 7534bb1052d28d7eb100c41a442ec0feec008e5f

Authored by ww
1 parent ad6f08ce

fix: 修复tcp开关下发命令通过modbus获取命令

1   -import { h, render } from 'vue'
  1 +import { h, render, unref } from 'vue'
2 2 import { ControlComponentEnum } from '../packages/Control'
  3 +import { useGetModbusCommand } from '../components/PublicForm/components/DataEvents/CommandDeliveryModal/useGetModbusCommand'
3 4 import { doCommandDelivery, getDeviceActive, getDeviceInfo } from '@/api/device'
4 5 import type { MouseUpEventDataType, NodeDataDataSourceJsonType, NodeDataEventJsonType, SingleClickEventDataType } from '@/api/node/model'
5 6 import { CommandWayEnum } from '@/enums/commandEnum'
6   -import { ActRangListItemTypeEnum, EventActionTypeEnum, TransportTypeEnum } from '@/enums/datasource'
  7 +import { ActRangListItemTypeEnum, CodeTypeEnum, EventActionTypeEnum, TransportTypeEnum } from '@/enums/datasource'
7 8 import { useMessage } from '@/hooks/web/useMessage'
8 9 import { AttributeDeliverModal, CommandDeliveryConfirmModal, CommandDeliveryModal, ConfirmModal } from '@/core/Library/components/PublicForm/components/DataEvents/CommandDeliveryModal'
9 10 import type { MxCell } from '@/fitCore/types'
... ... @@ -76,7 +77,7 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N
76 77 const nodeUtils = new NodeUtils()
77 78 const { way = CommandWayEnum.ONE_WAY } = data
78 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 81 const contentDataStore = useContentDataStoreWithOut()
81 82 const currentData = contentDataStore.contentData.find(item => item.id === cell.getId())
82 83 if (!currentData) return
... ... @@ -95,6 +96,7 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N
95 96 const res = rangeList.find(item => item.type === (status === ActRangListItemTypeEnum.OPEN ? ActRangListItemTypeEnum.CLOSE : ActRangListItemTypeEnum.OPEN))
96 97 if (!res) return
97 98 const { statusValue } = res
  99 +
98 100 command.params = transportType === TransportTypeEnum.TCP
99 101 ? statusValue!
100 102 : {
... ... @@ -104,7 +106,7 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N
104 106 if (operationPasswordEnable) {
105 107 const instance = h(CommandDeliveryConfirmModal)
106 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 111 else {
110 112 const instance = h(ConfirmModal)
... ... @@ -112,6 +114,14 @@ export function useNodeEvent(eventJson: NodeDataEventJsonType, dataSourceJson: N
112 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 125 await doCommandDelivery({ way, command, deviceId })
116 126 createMessage.success('命令下发成功')
117 127 }
... ...