From 2800fa4f32f3900509cb4d6eefaf2bfaf54efdd7 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Mon, 21 Apr 2025 18:29:09 +0800
Subject: [PATCH] fix: 天气显示
---
src/views/SignMachineNest/SignMachineNest.vue | 136 ++++++++++++++++++---------------------------
1 files changed, 54 insertions(+), 82 deletions(-)
diff --git a/src/views/SignMachineNest/SignMachineNest.vue b/src/views/SignMachineNest/SignMachineNest.vue
index c2d013d..2bcff88 100644
--- a/src/views/SignMachineNest/SignMachineNest.vue
+++ b/src/views/SignMachineNest/SignMachineNest.vue
@@ -1,99 +1,71 @@
<template>
- <MachineLeft></MachineLeft>
- <MachineRight></MachineRight>
+ <MachineLeft></MachineLeft>
+ <MachineRight></MachineRight>
</template>
<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 } from '@/api/home/machineNest';
-
-
-const store = useStore();
-let connectWs = ref(null);
+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);
+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)
-let osdVisible = ref({});
+// 单机巢初始化及事件撒点
+const { init, initEventLayer, initDroneEntity } = useSingleDroneMap({
+ eventApi: getEventList,
+ eventApiParams: {
+ device_sn: singleUavHome.value.device_sn,
+ },
+})
-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
- }
-};
-
-// 获取单个机巢信息
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();
- });
-};
+ 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;
- const result = res.data.data;
- console.log(result);
- console.log(result);
- store.commit('setSingleTotal', result);
- })
-};
+ getFlightStatistics(singleUavHome.value.device_sn).then(res => {
+ if (res.data.code !== 0) return
+ singleTotal.value = res.data.data
+ })
+}
onMounted(() => {
- getSingleDetails();
- getMachineData();
-});
+ initEventLayer()
+ getSingleDetails()
+ getMachineData()
+})
onUnmounted(() => {
- connectWs?.value?.close();
-});
+ connectWs?.value?.close()
+})
</script>
--
Gitblit v1.9.3