From fc514f7ef6db3c9de8eb74f184d2c29eafb7d649 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Sun, 20 Apr 2025 10:52:16 +0800
Subject: [PATCH] refactor: 当前任务详情重构变量

---
 src/components/CurrentTaskDetails/CurrentTaskDetails.vue |   88 +++++++++++++++++--------------------------
 1 files changed, 35 insertions(+), 53 deletions(-)

diff --git a/src/components/CurrentTaskDetails/CurrentTaskDetails.vue b/src/components/CurrentTaskDetails/CurrentTaskDetails.vue
index 74bb1b0..723764b 100644
--- a/src/components/CurrentTaskDetails/CurrentTaskDetails.vue
+++ b/src/components/CurrentTaskDetails/CurrentTaskDetails.vue
@@ -41,8 +41,6 @@
 import { pxToRem } from '@/utils/rem'
 import LiveVideo from '@/components/LiveVideo.vue'
 import { liveStart } from '@/api/home/machineNest'
-import { getJobDetails } from '@/api/home/task'
-
 import RealTimeMap from '@/components/CurrentTaskDetails/RealTimeMap.vue'
 import ControlPanel from '@/components/CurrentTaskDetails/ControlPanel/ControlPanel.vue'
 import TaskDetailsHead from '@/components/CurrentTaskDetails/TaskDetailsHead.vue'
@@ -60,9 +58,8 @@
 const isAutoControl = ref(true) //是否自动控制
 const lineQuality = ref(1) //1流畅,2标清
 const taskDetailsViewer = ref(null) //地图实例
-const deviceOsdInfo = computed(() => wsInfo.value?.device_osd)
-const dockSn = computed(() => taskDetails?.value?.device_sns?.[0])
-const droneSn = computed(() => deviceOsdInfo?.value?.data?.sn)
+const dockSn = computed(() => taskDetails?.value?.device_sns?.[0]) //机巢sn
+const droneSn = computed(() => wsInfo.value?.device_osd?.data?.sn) //无人机sn
 const trueAltitude = ref('') // 真实高度
 const isAiLive = ref(false) // 是ai直播
 const video_id = ref('') // 直播视频id
@@ -71,42 +68,15 @@
 const currentLiveUrl = ref('') // 当前直播地址
 const isTakeOff = ref(false) // 是在飞行中
 const isMaxMap = ref(false) //是大地图
-const client_id = ref('') //是大地图
+const client_id = ref('') //mqtt id
+const hasIr = ref(false) //有红外能力
+let once = true //第一次触发
 
-// 获取机巢直播
-const getDeviceLiveUrl = async () => {
-	const res = await liveStart(dockSn.value, 2)
-	currentLiveUrl.value = res.data.data.rtcs_url
-}
-
-const hasIr = ref(false)
-provide('hasIr', hasIr)
-//获取相机能力
-async function getLiveCapacity() {
-	const res = await getLiveCapacityApi({ sn: droneSn.value})
-	res?.data?.data?.forEach((item) => {
-		item?.cameras_list?.forEach((item1) => {
-			item1?.videos_list?.forEach((item2) => {
-				item2?.switch_video_types?.forEach(item3 =>{
-					  if (item3 === 'ir'){
-							hasIr.value = true
-						}
-				})
-			})
-		})
-	})
-}
-
-const useTaskDetailsCallBack = () => {
-	getDeviceLiveUrl()
-}
-
-let { taskDetails, workspace_id, getTaskDetails } = useTaskDetails(useTaskDetailsCallBack)
+let { taskDetails, workspace_id, getTaskDetails } = useTaskDetails(()=> getDeviceLiveUrl())
 let { wsInfo, removeWS } = useDroneWS(workspace_id) //ws信息,是一个ref对象
 
 provide('wsInfo', wsInfo)
 provide('workspace_id', workspace_id)
-provide('deviceOsdInfo', deviceOsdInfo)
 provide('dockOsdInfo', wsInfo?.value?.dock_osd)
 provide('dockSn', dockSn)
 provide('droneSn', droneSn)
@@ -118,24 +88,33 @@
 provide('isAiLive', isAiLive)
 provide('video_id', video_id)
 provide('client_id', client_id)
+provide('hasIr', hasIr)
 
-let once = true
-watch(deviceOsdInfo,()=>{
-	if (once){
-		getLiveCapacity()
-		once =false
-	}
-})
+// 获取机巢直播
+const getDeviceLiveUrl = async () => {
+	const res = await liveStart(dockSn.value, 2)
+	currentLiveUrl.value = res.data.data.rtcs_url
+}
 
-watch(
-	wsInfo,
-	() => {
-		// wsInfo 变化触发
-		setCurrentLiveUrl()
-	},
-	{ deep: true }
-)
+//获取是否有红外功能
+async function getLiveCapacity() {
+	if (!once) return
+	once = false
+	const res = await getLiveCapacityApi({ sn: droneSn.value })
+	res?.data?.data?.forEach(item => {
+		item?.cameras_list?.forEach(item1 => {
+			item1?.videos_list?.forEach(item2 => {
+				item2?.switch_video_types?.forEach(item3 => {
+					if (item3 === 'ir') {
+						hasIr.value = true
+					}
+				})
+			})
+		})
+	})
+}
 
+// set Ai直播
 const getAiLiveUrl = async () => {
 	const res = await getLiveAiLinkApi({
 		original_stream_url: `${CURRENT_CONFIG.rtmpURL}${video_id.value.replace(/\//g, '-')}`,
@@ -159,13 +138,13 @@
 
 // 无人机直播画质切换
 const changeLineQuality = async () => {
-	const res = await updateDroneQualityApi({ video_id: video_id.value, video_quality: lineQuality.value })
+	await updateDroneQualityApi({ video_id: video_id.value, video_quality: lineQuality.value })
 	ElMessage.success('切换画质成功')
 }
 
 // 设置当前直播地址
 const setCurrentLiveUrl = async () => {
-	const deviceInfo = deviceOsdInfo.value?.data?.host
+	const deviceInfo = wsInfo.value?.device_osd?.data?.host
 	if (!deviceInfo) return
 	const currentIsTakeOff = ![14, 0].includes(deviceInfo?.mode_code)
 	// 如果还是之前的状态,不切换
@@ -174,6 +153,9 @@
 	isTakeOff.value ? await getDroneLiveUrl() : await getDeviceLiveUrl()
 }
 
+watch(() => wsInfo.value?.device_osd, getLiveCapacity)
+watch(wsInfo, setCurrentLiveUrl, { deep: true })
+
 onMounted(() => {
 	getTaskDetails(props?.id)
 	EventBus.on('CurrentTaskDetails-timeStop', changeLineQuality)

--
Gitblit v1.9.3