11<script setup lang="ts">
2- import type ReconnectingWebSocket from ' reconnecting-websocket'
32import type { EnvGroup } from ' @/api/env_group'
4- import type { Environment } from ' @/api/environment'
53import { message } from ' ant-design-vue'
64import nodeApi from ' @/api/node'
7- import ws from ' @/lib/websocket '
5+ import { useNodeAvailabilityStore } from ' @/pinia/moudule/nodeAvailability '
86
97const props = defineProps <{
108 envGroups: EnvGroup []
119}>()
1210
1311const modelValue = defineModel <string | number >(' activeKey' )
12+ const nodeStore = useNodeAvailabilityStore ()
1413
15- const environments = ref <Environment []>([])
16- const environmentsMap = ref <Record <number , Environment >>({})
1714const loading = ref ({
1815 reload: false ,
1916 restart: false ,
2017})
2118
22- // WebSocket connection for environment monitoring
23- let socket: ReconnectingWebSocket | WebSocket | null = null
24-
25- // Get node data when tab is not 'All'
26- watch (modelValue , newVal => {
27- if (newVal && newVal !== 0 ) {
28- connectWebSocket ()
29- }
30- else {
31- disconnectWebSocket ()
32- }
33- }, { immediate: true })
34-
35- function connectWebSocket() {
36- if (socket ) {
37- socket .close ()
38- }
39-
40- socket = ws (' /api/cluster/environments/enabled/ws' , true )
41-
42- socket .onmessage = event => {
43- try {
44- const message = JSON .parse (event .data )
45-
46- if (message .event === ' message' ) {
47- const data: Environment [] = message .data
48- environments .value = data
49- environmentsMap .value = environments .value .reduce ((acc , node ) => {
50- acc [node .id ] = node
51- return acc
52- }, {} as Record <number , Environment >)
53- }
54- }
55- catch (error ) {
56- console .error (' Error parsing WebSocket message:' , error )
57- }
58- }
59-
60- socket .onerror = error => {
61- console .warn (' Failed to connect to environments WebSocket endpoint' , error )
62- }
63- }
64-
65- function disconnectWebSocket() {
66- if (socket ) {
67- socket .close ()
68- socket = null
69- }
70- }
71-
72- // Cleanup on unmount
73- onUnmounted (() => {
74- disconnectWebSocket ()
75- })
76-
7719// Get the current Node Group data
7820const currentEnvGroup = computed (() => {
7921 if (! modelValue .value || modelValue .value === 0 )
@@ -90,7 +32,7 @@ const syncNodes = computed(() => {
9032 return []
9133
9234 return currentEnvGroup .value .sync_node_ids
93- .map (id => environmentsMap . value [ id ] )
35+ .map (id => nodeStore . getNodeStatus ( id ) )
9436 .filter (Boolean )
9537})
9638
0 commit comments