forked from drone/command-center-dashboard

chenyao
2025-04-21 2a45e8331f65e4fc6dee2fba898bfbeaa01b0f5c
src/views/SignMachineNest/SignMachineNest.vue
@@ -6,51 +6,27 @@
<script setup>
import MachineLeft from '@/views/SignMachineNest/MachineLeft/MachineLeft.vue'
import MachineRight from '@/views/SignMachineNest/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, getEventList } from '@/api/home/machineNest'
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 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) // 为了兼容聊天消息
   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
   }
}
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({
@@ -60,46 +36,43 @@
   },
})
// 获取单个机巢信息
const getSingleDetails = () => {
   getDeviceDetail(singleUavHome.value.device_sn).then(res => {
      if (res.data.code !== 0) return
      const result = res.data.data
      dockDetails.value = result
    const storageObj  = _.pick(result, ['latitude', 'longitude'])
      setSingleUavAreaCode(storageObj)
      initDroneEntity({
         lng: result.longitude,
         lat: result.latitude,
         status: result.status,
      })
      const child = result.children
      // 对应store 里面数据结构
      osdVisible.value.nickname = result.nickname || '--'
      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 setSingleUavAreaCode = (position) =>{
   store.commit('setSingleUavHome',{...singleUavHome.value, ...position})
   const params = {
      output:'json',
      location: position.longitude+','+position.latitude,
      key:'6c3ea75b215f0c0efcbcfdf13273991b',
      radius:'0',
      extensions:'base',
   }
   // todo 2025年4月23号 后端提供接口然后对接
   // getAreaCodeApi(params).then(res => {
   //    console.log(res,66666666)
   // })
}
// 获取机巢统计数据 提供给左右侧组件使用
const getMachineData = () => {
   getFlightStatistics(singleUavHome.value.device_sn).then(res => {
      if (res.data.code !== 0) return
      const result = res.data.data
      store.commit('setSingleTotal', result)
      singleTotal.value = res.data.data
   })
}