吉安感知网项目-前端
罗广辉
2026-01-26 beb95fb5fc166804056abafd70fc01ac27de7621
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<template>
    <Teleport to=".content-container">
        <div class="shoutingMask">
            {{nowPlaying}}
            <van-icon name="cross" class="closeDlg" @click="closeDlgFun" />
            <div class="playBox">
                <div>
                    <img
                        :src="speakerInfo.play_mode === 0 ? bigPlayOne : bigXunHuan"
                        @click="setModelPlay(speakerInfo.play_mode === 0 ? 1 : 0)"
                        alt=""
                    />
                    <div>{{ playMode?.[speakerInfo.play_mode] }}</div>
                </div>
                <div>
                    <img v-if="speakerInfo.system_state === 2" :src="videoStopImg" alt="" @click="suspendDrone" />
                    <div v-else-if="speakerInfo.system_state === 1" class="intermediateState">
                        <img :src="videoPlayImg" alt="" />
                        <van-loading color="#0E0E0EFF" />
                    </div>
 
                    <img v-else :src="videoPlayImg" alt="" @click="pushToDrone(checkRow)" />
                    <div>{{ systemState?.[speakerInfo?.system_state] }}</div>
                </div>
                <div>
                    <img :src="bigVolume" alt="" @click="showVolumeAdjustment = !showVolumeAdjustment" />
                    <div>音量</div>
                </div>
            </div>
            <VolumeAdjustment v-if="showVolumeAdjustment" />
 
            <div class="searchBox">
                <el-input
                    size="small"
                    v-model="searchParams.name"
                    placeholder="请输入文件名称"
                    :suffix-icon="null"
                    v-focusDisableKeys
                />
                <div class="whiteBtn" @click="getFileList('search')">搜索</div>
                <div class="whiteBtn">
                    <el-upload
                        action="/upload"
                        accept=".FLAC,.ALAC,.WAV,.MP3,.AAC,.AIFF"
                        :show-file-list="false"
                        :before-upload="handleUpload"
                    >
                        上传音频
                    </el-upload>
                </div>
            </div>
 
            <div class="listBoxBlock">
                <div class="listItem title">
                    <div class="serialNumber">序号</div>
                    <div class="fileName">文件名称</div>
                    <div class="operation">操作</div>
                </div>
                <van-list
                    class="listBox"
                    v-model:loading="loading"
                    :finished="finished"
                    finished-text=" "
                    @load="onLoad"
                    offset="5"
                >
                    <div
                        class="listItem"
                        v-for="(item, index) in tableList"
                        :class="{ checked: item.checked }"
                        :key="item.id"
                        @click="pushToDrone(item)"
                    >
                        <div class="serialNumber">{{ index + 1 }}</div>
                        <div class="fileName">{{ item.name }}</div>
                        <div class="operation">
                            <img @click.stop="deleteVideo(item)" :src="deleteImg" alt="" />
                            <img v-if="item.isTryListren" @click.stop="stopTryListren(item)" :src="litterTryPlayImg" alt="" />
                            <img v-else @click.stop="playTryListren(item)" :src="litterTryListrenImg" alt="" />
                        </div>
                    </div>
                </van-list>
            </div>
        </div>
    </Teleport>
</template>
 
<script setup>
import videoStopImg from '@/assets/images/taskManagement/taskIntermediateContent/video-stop.svg'
import videoPlayImg from '@/assets/images/taskManagement/taskIntermediateContent/video-play.svg'
import { getVoiceFile, playAudio, stopVoiceApi, uploadSpeak, voiceMode } from '@/api/payload'
import bigPlayOne from '@/assets/images/taskManagement/taskIntermediateContent/play-one-big.svg'
import bigXunHuan from '@/assets/images/taskManagement/taskIntermediateContent/xunhuan-big.svg'
import bigVolume from '@/assets/images/taskManagement/taskIntermediateContent/volume-big.svg'
import VolumeAdjustment from '@/components/CurrentTaskDetails/AppConsoleRight/VolumeAdjustment.vue'
import deleteImg from '@/assets/images/taskManagement/taskIntermediateContent/delete.svg'
import litterTryListrenImg from '@/assets/images/taskManagement/taskIntermediateContent/little-try-listren.svg'
import litterTryPlayImg from '@/assets/images/taskManagement/taskIntermediateContent/litter-try-play.svg'
import { deleteSpeakVoiceByIdApi } from '@/api/routePlan'
import { showConfirmDialog, showToast } from 'vant'
 
const showBlock = defineModel('show')
const dockSn = inject('dockSn')
const searchParams = ref({
    sn: dockSn.value,
    name: '',
    page: 0,
    page_size: 999,
})
const loading = ref(false)
const finished = ref(true)
const total = ref(0)
const speakerInfo = inject('speakerInfo')
const showVolumeAdjustment = ref(false)
const tableList = ref([])
const checkRow = computed(() => {
    return tableList.value.find(item => item.checked === true)
})
let audioPlayer = null
const playMode = { 0: '单次播放', 1: '循环播放' }
const systemState = { 0: '空闲中', 1: '传输中', 2: '播放中', 3: '异常', 4: '文本转换中', 99: '下载中' }
// 正在播放
const nowPlaying = computed(()=>{
    return speakerInfo.value.system_state === 2 && !checkRow.value ? '正在播放上一次音频' : ''
})
 
// 停止播放
function suspendDrone() {
    stopVoiceApi({ sn: dockSn.value, psdk_index: 2 }).then(res => {
        // speakerInfo.value.system_state = 0
    })
}
 
function closeDlgFun() {
    showBlock.value = false
}
 
function setModelPlay(type) {
    const data = {
        psdk_index: 2,
        play_mode: type, // 1:是循环播放,0:单次播放
    }
    voiceMode({ sn: dockSn.value }, data)
}
 
// 删除音频
function deleteVideo(row) {
    showConfirmDialog({ title: '提示', message: '确定删除该条音频文件?' }).then(() => {
        deleteSpeakVoiceByIdApi(row.id).then(res => {
            if (res.data.code === 0) {
                showToast('删除成功')
                loading.value = true
                getFileList()
            }
        })
    })
}
 
// 上传
function handleUpload(file) {
    let formData = new FormData()
    formData.append('file', file)
    formData.append('sn', dockSn.value)
    uploadSpeak(formData).then(res => {
        showToast('上传成功')
        // 获取文件接口
        getFileList()
    })
}
 
// 获取音频列表
function getFileList() {
    getVoiceFile(searchParams.value).then(res => {
        tableList.value = res.data.data.records
        // if (!checkRow.value) {
        //     if (speakerInfo.value?.play_file_md5 && speakerInfo.value?.system_state === 2){
        //         const row = tableList.value.find(item => item.md5 === speakerInfo.value?.play_file_md5)
        //         playTryListren(row)
        //     }
        // }
        total.value = res.data.data.total
        nextTick(() => {
            loading.value = false
        })
    })
}
 
function onLoad() {
    searchParams.value.page = searchParams.value.page + 1
    getFileList()
}
 
// 本地试听
function playTryListren(row) {
    // 先播放本地音频
    if (row.url) {
        if (!audioPlayer) {
            audioPlayer = new Audio()
        }
        tableList.value.forEach(item => {
            item.isTryListren = false
            item.checked = false
        })
        row.isTryListren = true
        row.checked = true
        audioPlayer.src = row.url
        // speakerInfo.play_mode
        audioPlayer.loop = !!speakerInfo.value.play_mode
        audioPlayer.play()
        audioPlayer.addEventListener('ended', () => {
            row.isTryListren = false
        })
    }
}
 
// 停止试听
function stopTryListren(row) {
    tableList.value.forEach(item => {
        item.isTryListren = false
    })
    if (audioPlayer) {
        audioPlayer.pause()
        // audioPlayer = null
    }
}
 
let duration = null
let timeout = null
 
// 获取当前音频时长
function getDuration(url) {
    return new Promise((resolve, reject) => {
        try {
            let audio = new Audio()
            audio.src = url
            audio.addEventListener('loadedmetadata', () => {
                resolve(audio.duration)
                audio = null
            })
        } catch (e) {
            reject(e)
        }
    })
}
 
// 推送到无人机
async function pushToDrone(item) {
    const { sn, name, url, md5, voice } = item || {}
    if (!name) return showToast('请先选择音频')
    if (!url) return showToast('文件已损坏,请选择其他音频')
 
    // await stopVoiceApi({ sn: dockSn.value, psdk_index: 2 })
    playAudio({ sn, name, url, md5, voice }).then(async res => {
        tableList.value.forEach(item => (item.checked = false))
        item.checked = true
        // speakerInfo.value.system_state = 1
        // playTryListren(item)
        showToast('推送成功')
        // const duration = await getDuration(item.url)
        // if (speakerInfo.value.play_mode === 0) {
        //     timeout && clearTimeout(timeout)
        //     timeout = setTimeout(() => {
        //     }, (duration || 0) * 1000)
        // }
    })
}
 
watch(
    () => speakerInfo.value,
    (newValue, oldValue) => {
        const new_system_state = newValue?.system_state
        const old_system_state = oldValue?.system_state
        if (new_system_state !== old_system_state) {
            if (new_system_state === 2) {
                const row = tableList.value.find(item => item.md5 === speakerInfo.value?.play_file_md5)
                row && playTryListren(row)
            } else {
                stopTryListren()
            }
        }
        if (audioPlayer) {
            audioPlayer.loop = !!speakerInfo.value?.play_mode
        }
    },
    { immediate: true, deep: true }
)
 
onMounted(() => {
    getFileList()
})
 
onBeforeUnmount(() => {
    if (audioPlayer) {
        audioPlayer.pause()
        audioPlayer = null
    }
})
</script>
 
<style scoped lang="scss">
.shoutingMask {
    position: absolute;
    width: half(313);
    height: 100%;
    top: half(0);
    right: half(0);
    padding-top: half(20);
    z-index: 1;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(0.5rem);
    display: flex;
    gap: half(10) 0;
    flex-direction: column;
    align-items: center;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-size: half(13);
    color: #ffffff;
 
    .van-overlay {
        display: flex;
        align-items: center;
        justify-content: center;
    }
 
    .playBox {
        display: flex;
        justify-content: center;
        align-items: center;
        text-align: center;
        gap: half(25);
 
        >div{
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: half(5);
        }
 
        .intermediateState {
            position: relative;
            width: half(42);
            height: half(42);
 
            > img {
                opacity: 0.5;
            }
 
            .van-loading {
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%, -50%);
                width: half(35);
                height: half(35);
            }
        }
 
        //>div{
        //    width: half(42);
        //    height: half(42);
        //}
 
        img {
            width: half(42);
            height: half(42);
        }
    }
 
    .listItem {
        flex-shrink: 0;
        width: 100%;
        height: half(45);
        display: flex;
        align-items: center;
        background: rgba(15, 15, 15, 0.9);
        color: #ffffff;
 
        &.title {
            border-radius: half(10) half(10) 0 0;
        }
 
        &.checked {
            background: rgba(255, 255, 255, 0.4);
            color: #000000;
        }
 
        > div {
            display: flex;
            justify-content: center;
        }
 
        .serialNumber {
            width: 25%;
        }
 
        .fileName {
            width: 50%;
            text-wrap: wrap;
            text-align: center;
        }
 
        .operation {
            width: 25%;
        }
    }
 
    .closeDlg {
        font-size: half(20);
        position: absolute;
        right: half(5);
        top: half(5);
        color: #ffffff;
    }
 
    .searchBox {
        display: flex;
        height: half(38);
        gap: 0 half(6);
        padding: 0 half(20);
 
        .el-input {
            height: 100%;
            font-size: half(15);
        }
    }
 
    .listBoxBlock {
        padding: 0 half(20);
        border-radius: half(10) half(10) 0 0;
        overflow: hidden;
        flex-grow: 1;
        width: 100%;
        display: flex;
        flex-direction: column;
 
        .listBox {
            flex-grow: 1;
            overflow: auto;
            width: 100%;
 
            :deep() {
                .van-list__finished-text {
                    background: rgba(15, 15, 15, 0.9);
                    color: #ffffff;
                    font-size: half(13);
                    height: half(45);
                    line-height: half(45);
                }
            }
        }
    }
}
</style>