Commit 98b596babea6acca3d0edfd20e1734e75f609653

Authored by ww
1 parent 8c2d5f78

fix: socket receive null message happend error

... ... @@ -77,6 +77,7 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) {
77 77 // console.log({ dataSource: unref(dataSourceRef), cmdIdMapping });
78 78 const res: ResponseMessage = JSON.parse(message.data);
79 79 const { subscriptionId, data = {} } = res;
  80 + if (!subscriptionId) return;
80 81 const mappingRecord = cmdIdMapping.get(subscriptionId);
81 82 if (!mappingRecord) return;
82 83 const { attribute, recordIndex, dataSourceIndex } = mappingRecord;
... ... @@ -102,8 +103,14 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) {
102 103 let index = 0;
103 104 unref(dataSourceRef).forEach((record, recordIndex) => {
104 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 112 const { deviceId, attribute, slaveDeviceId, gatewayDevice } = dataSource;
  113 + if (!attribute) continue;
107 114 const cmdId = index;
108 115 index++;
109 116 setCmdId(cmdId, {
... ... @@ -117,7 +124,7 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) {
117 124 messageList.push(
118 125 generateMessage(gatewayDevice ? slaveDeviceId : deviceId, cmdId, attribute)
119 126 );
120   - });
  127 + }
121 128 });
122 129 return {
123 130 tsSubCmds: messageList,
... ...