Commit 98b596babea6acca3d0edfd20e1734e75f609653
1 parent
8c2d5f78
fix: socket receive null message happend error
Showing
1 changed file
with
9 additions
and
2 deletions
@@ -77,6 +77,7 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { | @@ -77,6 +77,7 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { | ||
77 | // console.log({ dataSource: unref(dataSourceRef), cmdIdMapping }); | 77 | // console.log({ dataSource: unref(dataSourceRef), cmdIdMapping }); |
78 | const res: ResponseMessage = JSON.parse(message.data); | 78 | const res: ResponseMessage = JSON.parse(message.data); |
79 | const { subscriptionId, data = {} } = res; | 79 | const { subscriptionId, data = {} } = res; |
80 | + if (!subscriptionId) return; | ||
80 | const mappingRecord = cmdIdMapping.get(subscriptionId); | 81 | const mappingRecord = cmdIdMapping.get(subscriptionId); |
81 | if (!mappingRecord) return; | 82 | if (!mappingRecord) return; |
82 | const { attribute, recordIndex, dataSourceIndex } = mappingRecord; | 83 | const { attribute, recordIndex, dataSourceIndex } = mappingRecord; |
@@ -102,8 +103,14 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { | @@ -102,8 +103,14 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { | ||
102 | let index = 0; | 103 | let index = 0; |
103 | unref(dataSourceRef).forEach((record, recordIndex) => { | 104 | unref(dataSourceRef).forEach((record, recordIndex) => { |
104 | const componentId = record.record.id; | 105 | const componentId = record.record.id; |
105 | - record.record.dataSource.forEach((dataSource, dataSourceIndex) => { | 106 | + for ( |
107 | + let dataSourceIndex = 0; | ||
108 | + dataSourceIndex < record.record.dataSource.length; | ||
109 | + dataSourceIndex++ | ||
110 | + ) { | ||
111 | + const dataSource = record.record.dataSource[dataSourceIndex]; | ||
106 | const { deviceId, attribute, slaveDeviceId, gatewayDevice } = dataSource; | 112 | const { deviceId, attribute, slaveDeviceId, gatewayDevice } = dataSource; |
113 | + if (!attribute) continue; | ||
107 | const cmdId = index; | 114 | const cmdId = index; |
108 | index++; | 115 | index++; |
109 | setCmdId(cmdId, { | 116 | setCmdId(cmdId, { |
@@ -117,7 +124,7 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { | @@ -117,7 +124,7 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { | ||
117 | messageList.push( | 124 | messageList.push( |
118 | generateMessage(gatewayDevice ? slaveDeviceId : deviceId, cmdId, attribute) | 125 | generateMessage(gatewayDevice ? slaveDeviceId : deviceId, cmdId, attribute) |
119 | ); | 126 | ); |
120 | - }); | 127 | + } |
121 | }); | 128 | }); |
122 | return { | 129 | return { |
123 | tsSubCmds: messageList, | 130 | tsSubCmds: messageList, |