Commit e2056a649689bfd55f7593d5d5e6a65a3361768d

Authored by xp.Huang
2 parents b9ccd109 8f736844

Merge branch 'fix/data-board-socket' into 'main_dev'

fix: 修复数据看板socket连接问题

See merge request yunteng/thingskit-front!726
... ... @@ -4,12 +4,12 @@
4 4 import { ComponentPropsConfigType } from '../../../index.type';
5 5 import { option } from './config';
6 6 import { UpdateTime } from '/@/views/visual/commonComponents/UpdateTime';
7   - // import { useIntervalFn } from '@vueuse/core';
8 7 import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
9 8 import { useComponentScale } from '/@/views/visual/packages/hook/useComponentScale';
10 9 import { useReceiveMessage } from '../../../hook/useReceiveMessage';
11 10 import { useReceiveValue } from '../../../hook/useReceiveValue';
12 11 import { MultipleDataFetchUpdateFn } from '../../../hook/socket/useSocket.type';
  12 + import { useMultipleDataFetch } from '../../../hook/socket/useSocket';
13 13
14 14 const props = defineProps<{
15 15 config: ComponentPropsConfigType<typeof option>;
... ...
... ... @@ -23,6 +23,7 @@ import {
23 23 TsSubCmdsItemType,
24 24 } from './useSocket.type';
25 25 import { ComponentPropsConfigType } from '../../index.type';
  26 +import { isNullOrUnDef } from '/@/utils/is';
26 27
27 28 interface DeviceGroupMapType {
28 29 subscriptionId: number;
... ... @@ -70,11 +71,14 @@ class Subscriber {
70 71 clearSubscriber = () => {
71 72 this.deviceGroupMap.clear();
72 73 this.subscriptionMap.clear();
73   - this.componentUpdateFnMap.clear();
74   - this.componentGroupUpdateFnMap.clear();
75 74 this.customSubscribeMap.clear();
76 75 };
77 76
  77 + clearUpdateFn() {
  78 + this.componentUpdateFnMap.clear();
  79 + this.componentGroupUpdateFnMap.clear();
  80 + }
  81 +
78 82 addSubscriber = (info: Record<'deviceId' | 'slaveDeviceId' | 'attribute' | 'uuid', string>) => {
79 83 const { deviceId, attribute, uuid } = info;
80 84 if (!this.deviceGroupMap.has(deviceId)) {
... ... @@ -188,7 +192,7 @@ class Subscriber {
188 192 return;
189 193 }
190 194
191   - if (message.subscriptionId) {
  195 + if (!isNullOrUnDef(message.subscriptionId)) {
192 196 this.triggerTsSubCmdsMessage(message);
193 197 }
194 198 }
... ... @@ -204,29 +208,30 @@ class Subscriber {
204 208 const updateGroups = this.componentGroupUpdateFnMap.get(deviceId);
205 209
206 210 if (updateGroups) {
207   - (updateGroups || []).forEach((item) => {
  211 + for (const item of updateGroups || []) {
208 212 const { attributes, fn } = item;
209 213 try {
210   - if (!fn) return;
  214 + if (!fn) continue;
211 215 fn?.(this.getGroupScopeMessage(message, attributes, deviceId), deviceId, attributes);
212 216 } catch (error) {
213 217 console.error(`deviceId: ${deviceId}`);
214 218 throw error;
215 219 }
216   - });
  220 + }
  221 + return;
217 222 }
218 223
219   - subscriptionGroup.forEach((item) => {
  224 + for (const item of subscriptionGroup) {
220 225 const { attribute, uuid } = item;
221 226 const updateFn = this.componentUpdateFnMap.get(uuid);
222 227 try {
223   - if (!updateFn) return;
  228 + if (!updateFn) continue;
224 229 updateFn?.(this.getScopeMessage(message, [attribute]), attribute);
225 230 } catch (error) {
226 231 console.error(`uuid: ${uuid}`);
227 232 throw error;
228 233 }
229   - });
  234 + }
230 235 }
231 236
232 237 triggerAlarmDataMesssage(message: ReceiveAlarmDataCmdsMessageType) {
... ... @@ -299,6 +304,8 @@ export const useSocket = (dataSourceRef: Ref<WidgetDataType[]>) => {
299 304
300 305 onUnmounted(() => {
301 306 close();
  307 + subscriber.clearSubscriber();
  308 + subscriber.clearUpdateFn();
302 309 });
303 310
304 311 return {
... ...