forked from drone/command-center-dashboard

xiebin
2025-04-21 8fa0d6fdb819ddb15b22250d019ce0a564632959
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
<template>
    <MachineLeft></MachineLeft>
    <MachineRight></MachineRight>
</template>
 
<script setup>
import MachineLeft from '@/views/SignMachineNest/MachineLeft/MachineLeft.vue'
import MachineRight from '@/views/SignMachineNest/MachineRight/MachineRight.vue'
import { useStore } from 'vuex'
import { getDeviceDetail, getEventList, getFlightStatistics } from '@/api/home/machineNest'
import { useSingleDroneMap } from '@/hooks/useSingleDroneMap/useSingleDroneMap'
import { useDroneWS } from '@/hooks/useDroneWS'
import _ from 'lodash'
import { getAreaCodeApi } from '@/api/home'
const store = useStore()
let connectWs = ref(null)
// 单个机巢信息
const singleUavHome = computed(() => store.state.home.singleUavHome)
let workspaceId = ref('')
let { wsInfo } = useDroneWS(workspaceId) //ws信息,是一个ref对象
const dockSn = computed(() => singleUavHome.value.device_sn) //机巢sn
const droneSn = computed(() => wsInfo.value?.device_osd?.data?.sn) //无人机sn
const singleTotal = ref({})
const dockDetails = ref('')
provide('dockSn', dockSn)
provide('droneSn', droneSn)
provide('wsInfo', wsInfo)
provide('dockDetails', dockDetails)
provide('singleTotal', singleTotal)
 
// 单机巢初始化及事件撒点
const { init, initEventLayer, initDroneEntity } = useSingleDroneMap({
    eventApi: getEventList,
    eventApiParams: {
        device_sn: singleUavHome.value.device_sn,
    },
})
 
const getSingleDetails = () => {
    getDeviceDetail(singleUavHome.value.device_sn).then(res => {
        const result = res.data.data
        dockDetails.value = result
    const storageObj  = _.pick(result, ['latitude', 'longitude']) || {}
        store.commit('setSingleUavHome',{...singleUavHome.value, ...storageObj})
        initDroneEntity({
            lng: result.longitude,
            lat: result.latitude,
            status: result.status,
        })
        workspaceId.value = result.workspace_id
    })
}
 
// 获取机巢统计数据 提供给左右侧组件使用
const getMachineData = () => {
    getFlightStatistics(singleUavHome.value.device_sn).then(res => {
        if (res.data.code !== 0) return
        singleTotal.value = res.data.data
    })
}
 
onMounted(() => {
    initEventLayer()
    getSingleDetails()
    getMachineData()
})
 
onUnmounted(() => {
    connectWs?.value?.close()
})
</script>