吉安感知网项目-前端
罗广辉
2026-01-05 c3b16a234fee5bab6d91077b8fe27a4c1ce702f8
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<template>
    <div class="manualControl" v-if="false">
        <div class="manualControlBg">
            <div class="manualControlBorder">
                <div class="manualControlCenter" @click="airAlleyOop">
                    <img :src="controlCenterImg" alt="" />
                </div>
            </div>
            <div
                v-for="item in controlBtnList"
                :key="item.name"
                :style="item.style"
                :title="item.name"
                :class="{
                    operateBtn: true,
                    active: item.active,
                    disable: item.disable || (item.name === '控制台' ? false : apiDisable),
                }"
                @click="funBtnClick(item)"
            ></div>
            <SvgIcon
                v-for="(item, index) in controlBtnList"
                :name="item.svg"
                :class="`${'btnIcon-' + index} btnIcon ${item.active ? 'active' : ''}`"
                :style="item.imgStyle"
            />
        </div>
 
    </div>
</template>
 
<script setup>
import { stopRecording } from '@/api/drc'
import { checkControllUserMeApi, closeSendWsApi, setWidgetSetApi, stopVoiceApi } from '@/api/payload'
import controlCenterImg from '@/assets/images/taskManagement/taskIntermediateContent/controlCenter.png'
import SvgIcon from '@/components/SvgIcon.vue'
import EventBus from '@/utils/eventBus'
import { ElMessage } from 'element-plus'
import { useStore } from 'vuex'
import _, { throttle } from 'lodash'
import { useRunOnce } from '@/hooks'
import { showToast } from 'vant'
const store = useStore()
 
const isAutoControl = inject('isAutoControl')
const isBackDock = inject('isBackDock')
const droneStatus = inject('droneStatus')
const showUpKeyPanel = inject('showUpKeyPanel')
const isManualControl = inject('isManualControl')
const dockSn = inject('dockSn')
const isAiLive = inject('isAiLive')
const droneSn = inject('droneSn')
const usedControl = inject('usedControl')
const apiDisable = inject('apiDisable')
const airAlleyOopShow = ref(false)
const recordingId = inject('recordingId')
const isRouteRecord = inject('isRouteRecord')
const controlBtnList = ref([
    {
        name: '自动控制',
        svg: 'autoControl',
        style: { top: '-70%' },
        active: true,
        handle: autoControl,
    },
    { name: '控制台', svg: 'consoleBtn', style: { left: '70%' }, active: false, handle: showConsole },
    {
        name: '手动控制',
        svg: 'manualControl',
        style: { top: '70%' },
        active: false,
        handle: manualControl,
    },
    { name: '返航/取消返航', svg: 'turnBack', style: { left: '-70%' }, active: false, handle: turnBack },
])
 
// 自动控制
function autoControl() {
    EventBus.emit('controlPanel-cancelManualControl')
}
 
function funBtnClick(item) {
    if (item.name !== '控制台' && apiDisable.value) {
        return
    }
    !item.disable && item.handle()
}
 
// 切换控制台显示
function showConsole() {
    if (!showUpKeyPanel.value && [undefined, 0, 14].includes(droneStatus.value.mode_code)) {
        return showToast('当前状态无法操作')
    }
    showUpKeyPanel.value = !showUpKeyPanel.value
    if (showUpKeyPanel.value) {
        EventBus.emit('controlPanel-getPayloadControl')
    }
}
 
// 手动控制
function manualControl() {
    usedControl.value = true
    EventBus.emit('controlPanel-control')
}
 
// 返航
function turnBack() {
    EventBus.emit('controlPanel-returnOrCancelReturn')
}
// 设置回显状态
function setSelectStatus() {
    const modeCode = droneStatus?.value?.mode_code
 
    if (modeCode === undefined) return
    // 自动控制
    if ([0, 1, 2, 4, 5, 14].includes(modeCode)) {
        controlBtnList.value = controlBtnList.value.map(item => ({ ...item, active: false }))
        controlBtnList.value[0].active = true
        isAutoControl.value = true
        isBackDock.value = false
        isManualControl.value = false
    }
    // 控制中
    if ([3, 16, 17].includes(modeCode)) {
        controlBtnList.value = controlBtnList.value.map(item => ({ ...item, active: false }))
        controlBtnList.value[2].active = true
        isManualControl.value = true
        isAutoControl.value = false
        isBackDock.value = false
    }
    // 降落中
    if ([9, 10, 11, 12].includes(modeCode)) {
        controlBtnList.value = controlBtnList.value.map(item => ({ ...item, active: false }))
        controlBtnList.value[3].active = true
        isAutoControl.value = false
        isManualControl.value = false
        isAiLive.value && closeAiFunOnce()
        isBackDock.value = true
        if (recordingId.value) {
            getstopRecording()
            recordingId.value = ''
        }
        if (modeCode === 10) {
            showUpKeyPanel.value = false
        }
    }
}
 
// 停止录制
const getstopRecording = useRunOnce(() => {
    if (!droneSn.value) return
    isRouteRecord.value = false
    stopRecording(recordingId.value).then(res => {
        recordingId.value = ''
        showToast('航线录制结束')
    })
})
 
// 设置按钮禁用状态
function setButtonDisabledStatus() {
    const modeCode = droneStatus?.value?.mode_code
    controlBtnList.value[0].disable = [undefined, 0, 14, 9, 10, 11, 12].includes(modeCode)
    controlBtnList.value[1].disable = [undefined, 0, 10, 14].includes(modeCode)
    controlBtnList.value[2].disable = [undefined, 0, 14, 9, 10].includes(modeCode)
    if ([undefined, 0, 14].includes(modeCode)) {
        controlBtnList.value[3].disable = true
    } else {
        controlBtnList.value[3].disable = false
        if ([9, 10, 11, 12].includes(modeCode)) {
            controlBtnList.value[3].disable = modeCode !== 9
        }
    }
}
 
// 获取控制 只触发一次
const getControlFunOnce = useRunOnce(() => {
    usedControl.value ||
        checkControllUserMeApi(dockSn.value).then(res => {
            const isMe = res.data.data
            isMe && EventBus.emit('controlPanel-control', { hasTips: false })
        })
})
 
const closeAiFunOnce = throttle(()=>{
    EventBus.emit('CurrentTaskDetails-getDroneLiveUrl')
    closeSendWsApi(droneSn.value, { type: 'AI' })
}, 4000)
 
// 统一节流
const statusThrottle = throttle(() => {
    setButtonDisabledStatus()
    setSelectStatus()
}, 1000)
 
function airAlleyOop() {
    // airAlleyOopShow.value = true
}
 
watch(droneStatus, statusThrottle, { deep: true, immediate: true })
</script>
 
<style scoped lang="scss">
.manualControl {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 188px;
    height: 188px;
    background: rgb(0, 0, 0, 0.4); /* 半透明背景 */
    border-radius: 40px 40px 40px 40px;
 
    .manualControlBg {
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        width: 165px;
        height: 165px;
        border-radius: 50%;
        position: relative;
        background: radial-gradient(circle, #5d5c5e 0%, #514f52 50%, #3d3b3d 100%);
 
        .operateBtn {
            position: absolute;
            width: 100%;
            height: 100%;
            transform: rotate(45deg);
 
            &.active,
            &:hover {
                cursor: pointer;
                box-shadow: 0 0 20px 5px rgba(0, 0, 0, 0.3);
                z-index: 1;
                background: rgba(255, 255, 255, 0.19);
            }
 
            &.active {
                z-index: 2;
                background: radial-gradient(circle, #5d5c5e 0%, #6d6d6d 50%, #4a454a 100%);
            }
 
            &.disable {
                cursor: not-allowed;
            }
        }
 
        .btnIcon {
            position: absolute;
            font-size: 24px;
            pointer-events: none;
            color: #8e8e8f;
            z-index: 2;
 
            &.active {
                color: #fff;
            }
 
            &-0 {
                left: 50%;
                top: 20px;
                transform: translateX(-50%);
            }
 
            &-1 {
                top: 50%;
                right: 20px;
                transform: translateY(-50%);
            }
 
            &-2 {
                bottom: 20px;
                left: 50%;
                transform: translateX(-50%);
            }
 
            &-3 {
                top: 50%;
                left: 20px;
                transform: translateY(-50%);
            }
        }
 
        .manualControlBorder {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 135px;
            height: 135px;
            border-radius: 50%;
            border: 2px solid #ffffff;
 
            .manualControlCenter {
                cursor: pointer;
                z-index: 5;
                width: 50px;
                height: 50px;
                background: #404040;
                border-radius: 50%;
                display: flex;
                align-items: center;
                justify-content: center;
 
                img {
                    width: 18px;
                    height: 18px;
                }
            }
        }
    }
}
</style>