forked from drone/command-center-dashboard

罗广辉
2025-04-20 fc514f7ef6db3c9de8eb74f184d2c29eafb7d649
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!--
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2025-04-19 13:13:15
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2025-04-19 15:07:04
 * @FilePath: \command-center-dashboard\src\components\CurrentTaskDetails\CurrentTaskDetails.vue
 * @Description:
 *
 * Copyright (c) 2025 by shuishen, All Rights Reserved.
-->
<!--当前任务详情-->
<template>
    <el-dialog
        modal-class="current-task-details"
        v-model="isShow"
        title="当前任务详情"
        :width="pxToRem(1500)"
        :close-on-click-modal="false"
        :destroy-on-close="true"
    >
        <div class="content-container" v-if="isShow">
            <!-- 视频直播 -->
            <div :class="`${isMaxMap ? 'minBox' : 'maxBox'} centerPoint`">
                <LiveVideo :videoUrl="currentLiveUrl" :controls="false" />
            </div>
            <!-- 展示地图 -->
            <RealTimeMap :class="`${isMaxMap ? 'maxBox' : 'minBox'}`" />
            <TaskDetailsRight v-if="isAutoControl" />
            <template v-else>
                <TaskDetailsHead />
                <TaskDetailsLeft />
            </template>
            <!--    控制面板,里面有方法需要立即执行,不可用v-if        -->
            <ControlPanel v-show="!isAutoControl" />
            <img alt="" :src="amplifyImg" class="amplify" @click="isMaxMap = !isMaxMap" />
        </div>
    </el-dialog>
</template>
 
<script setup>
import { pxToRem } from '@/utils/rem'
import LiveVideo from '@/components/LiveVideo.vue'
import { liveStart } from '@/api/home/machineNest'
import RealTimeMap from '@/components/CurrentTaskDetails/RealTimeMap.vue'
import ControlPanel from '@/components/CurrentTaskDetails/ControlPanel/ControlPanel.vue'
import TaskDetailsHead from '@/components/CurrentTaskDetails/TaskDetailsHead.vue'
import TaskDetailsLeft from '@/components/CurrentTaskDetails/TaskDetailsLeft.vue'
import TaskDetailsRight from '@/components/CurrentTaskDetails/TaskDetailsRight.vue'
import amplifyImg from '@/assets/images/taskManagement/taskIntermediateContent/amplifyImg.png'
import { ElMessage } from 'element-plus'
import EventBus from '@/event-bus'
import { updateDroneQualityApi } from '@/api/drc'
import { getLiveAiLinkApi, getLiveCapacityApi } from '@/api/payload'
import { CURRENT_CONFIG } from '@/utils/http/config'
import { useDroneWS } from '@/hooks/useDroneWS'
import { useTaskDetails } from '@/hooks/useTaskDetails/useTaskDetails'
 
const isAutoControl = ref(true) //是否自动控制
const lineQuality = ref(1) //1流畅,2标清
const taskDetailsViewer = ref(null) //地图实例
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
const isShow = defineModel('show') // 是否显示当前任务详情
const props = defineProps(['id'])
const currentLiveUrl = ref('') // 当前直播地址
const isTakeOff = ref(false) // 是在飞行中
const isMaxMap = ref(false) //是大地图
const client_id = ref('') //mqtt id
const hasIr = ref(false) //有红外能力
let once = true //第一次触发
 
let { taskDetails, workspace_id, getTaskDetails } = useTaskDetails(()=> getDeviceLiveUrl())
let { wsInfo, removeWS } = useDroneWS(workspace_id) //ws信息,是一个ref对象
 
provide('wsInfo', wsInfo)
provide('workspace_id', workspace_id)
provide('dockOsdInfo', wsInfo?.value?.dock_osd)
provide('dockSn', dockSn)
provide('droneSn', droneSn)
provide('isAutoControl', isAutoControl)
provide('lineQuality', lineQuality)
provide('taskDetailsViewer', taskDetailsViewer)
provide('taskDetails', taskDetails)
provide('trueAltitude', trueAltitude)
provide('isAiLive', isAiLive)
provide('video_id', video_id)
provide('client_id', client_id)
provide('hasIr', hasIr)
 
// 获取机巢直播
const getDeviceLiveUrl = async () => {
    const res = await liveStart(dockSn.value, 2)
    currentLiveUrl.value = res.data.data.rtcs_url
}
 
//获取是否有红外功能
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, '-')}`,
        video_id: video_id.value,
    })
    currentLiveUrl.value = res.data.data.rtcs_url
    ElMessage.success('开启成功')
    isAiLive.value = true
}
 
// 获取无人机直播url
async function getDroneLiveUrl(reset = false) {
    currentLiveUrl.value = ''
    await nextTick()
    const res = await liveStart(droneSn.value, lineQuality.value)
    currentLiveUrl.value = res.data.data.rtcs_url
    video_id.value = res.data.data.video_id
    isAiLive.value = false
    reset && ElMessage.success('刷新成功')
}
 
// 无人机直播画质切换
const changeLineQuality = async () => {
    await updateDroneQualityApi({ video_id: video_id.value, video_quality: lineQuality.value })
    ElMessage.success('切换画质成功')
}
 
// 设置当前直播地址
const setCurrentLiveUrl = async () => {
    const deviceInfo = wsInfo.value?.device_osd?.data?.host
    if (!deviceInfo) return
    const currentIsTakeOff = ![14, 0].includes(deviceInfo?.mode_code)
    // 如果还是之前的状态,不切换
    if (isTakeOff.value === currentIsTakeOff) return
    isTakeOff.value = currentIsTakeOff
    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)
    EventBus.on('CurrentTaskDetails-getAiLiveUrl', getAiLiveUrl)
    EventBus.on('CurrentTaskDetails-getDroneLiveUrl', getDroneLiveUrl)
})
 
onBeforeUnmount(() => {
    EventBus.off('CurrentTaskDetails-timeStop', changeLineQuality)
    EventBus.off('CurrentTaskDetails-getAiLiveUrl', getAiLiveUrl)
    EventBus.off('CurrentTaskDetails-getDroneLiveUrl', getDroneLiveUrl)
})
</script>
 
<style lang="scss">
.current-task-details {
    display: flex;
    justify-content: space-between;
 
    .el-dialog {
        border-radius: 40px;
        position: relative;
        margin-top: 25px;
        width: 1782px;
        height: 1002px;
        padding: 0;
 
        .el-dialog__body {
            width: 100%;
            height: 100%;
        }
 
        .el-dialog__header {
            height: 0;
            overflow: hidden;
            padding: 0;
 
            .el-dialog__headerbtn {
                position: absolute;
                right: -30px;
                top: -30px;
 
                .el-dialog__close {
                    font-size: 30px;
                }
            }
        }
    }
}
</style>
 
<style lang="scss" scoped>
.content-container {
    height: 100%;
    width: 100%;
    border-radius: 4rem;
    overflow: hidden;
 
    .centerPoint {
        &:before {
            content: '+';
            font-size: 30px;
            color: white;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            pointer-events: none;
            font-weight: bold;
            text-shadow: -1px -1px 0 black, 1px -1px 0 black, -1px 1px 0 black, 1px 1px 0 black; /* 四方向描边 */
        }
    }
 
    .maxBox {
        width: 100%;
        height: 100%;
    }
 
    .minBox {
        position: absolute;
        width: 376px;
        height: 212px;
        left: 0;
        bottom: 0;
        border-radius: 0px 20px 0px 40px;
        border: 1px solid #62a1ff;
        overflow: hidden;
    }
 
    .amplify {
        cursor: pointer;
        position: absolute;
        left: 340px;
        bottom: 183px;
        width: 22px;
        height: 22px;
    }
}
</style>