forked from drone/command-center-dashboard

罗广辉
2025-04-03 7635213630830c4cbb9ff6ada69ba9b5c8a35d42
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<template>
  <MachineLeft></MachineLeft>
  <MachineRight></MachineRight>
</template>
 
<script setup>
import MachineLeft from './components/MachineLeft/MachineLeft.vue'
import MachineRight from './components/MachineRight/MachineRight.vue';
import { useConnectWebSocket } from '../../utils/websocket/connect-websocket';
import { getWebsocketUrl } from '@/websocket/util/config';
import { EBizCode } from '@/utils/staticData/enums.js';
import { EModeCode } from '@/utils/staticData/device.js';
import { useStore } from 'vuex';
import { getDeviceDetail, getFlightStatistics } from '@/api/home/machineNest';
 
 
const store = useStore();
let connectWs = ref(null);
// 单个机巢信息
const singleUavHome = computed(() => store.state.home.singleUavHome);
 
let osdVisible = ref({});
 
let workspaceId = ref('');
// 进入单个机巢开始连接ws
const createWsConntect = () => {
  let webSorketUrl = getWebsocketUrl() + '&workspace-id=' + workspaceId.value;
  // 监听ws 消息
  connectWs.value = useConnectWebSocket(messageHandler, webSorketUrl);
};
 
const messageHandler = (result) => {
  let payload = JSON.parse(result) // 为了兼容聊天消息
  // console.log('payload', payload)
  if (!payload) return
  switch (payload.biz_code) {
    case EBizCode.GatewayOsd: {
      store.commit('setGatewayInfo', payload.data)
      break
    }
    case EBizCode.DeviceOsd: {
      store.commit('setDeviceInfo', payload)
      store.commit('setWsMessage', payload)
      break
    }
    case EBizCode.DockOsd: {
      store.commit('setDockOnfo', payload.data)
      break
    }
    default:
          break
  }
};
 
// 获取单个机巢信息
const getSingleDetails = () => {
  getDeviceDetail(singleUavHome.value.device_sn).then((res) => {
    if (res.data.code !== 0) return;
    const result = res.data.data;
    const child = result.children;
    // 对应store 里面数据结构
    osdVisible.value.sn = child?.device_sn || ''
    osdVisible.value.callsign = child?.nickname || '--'
    osdVisible.value.model = EModeCode.Disconnected || ''
    osdVisible.value.visible = true
    osdVisible.value.gateway_sn = result?.device_sn || ''
    osdVisible.value.is_dock = true
    osdVisible.value.gateway_callsign = result?.callsign || '--'
    osdVisible.value.payloads = child?.payloads_list || []
    osdVisible.value.device_domain = child.domain || 0
    osdVisible.value.device_sub_type = child.sub_type || 1
    osdVisible.value.device_type = child.type || 0
    // osdVisible.value.latest_wayline_job = result?.latest_wayline_job || {}
    store.commit('setOsdVisibleInfo', osdVisible.value);
    store.commit('setSelectedWorkSpaceId', result.workspace_id);
    workspaceId.value = result.workspace_id;
    createWsConntect();
  });
};
 
// 获取机巢统计数据 提供给左右侧组件使用
const getMachineData = () => {
  getFlightStatistics(singleUavHome.value.device_sn).then(res => {
    if (res.data.code !== 0) return;
    const result = res.data.data;
    store.commit('setSingleTotal', result);
  })
};
 
onMounted(() => {
  getSingleDetails();
  getMachineData();
});
 
onUnmounted(() => {
  connectWs?.value?.close();
});
</script>