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