zhongrj
2025-03-28 4ff3eee77b41466d08117970970d01be6e48ffe1
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
<template>
  <div class="drone-warp">
    <div class="tabs-list">
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
        <el-tab-pane label="机场" name="first">
          <el-select v-model="selectedValue" placeholder="请选择" style="width: 240px">
            <el-option
              v-for="item in cardList"
              :key="item.id"
              :label="item.nickname"
              :value="item.workspace_id"
            />
        </el-select>
        </el-tab-pane>
        <el-tab-pane label="遥控器" name="second">
          <el-select v-model="selectedValue" placeholder="请选择" style="width: 240px">
            <el-option
              v-for="item in cardList"
              :key="item.id"
              :label="item.nickname"
              :value="item.workspace_id"
            />
        </el-select>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="airport-type">
      <p>无人机型号</p>
    </div>
    <div class="video-play">
      <video v-show="videoUrl" class="video-js" :src="videoSrc" :id="videoPlayerId"></video>
      <el-empty v-show="videoUrl == ''" description="当前设备已关机,无法进行直播" :image="imageUrl"></el-empty>
    </div>
  </div>
</template>
 
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import type { TabsPaneContext } from 'element-plus'
import { projectCard } from './components/data'
import { getPlatformByUser } from '@/api/manage'
import videojs from 'video.js'
import { startLivestream, getLiveCapacity } from '@/api/manage'
import { CURRENT_CONFIG as config } from '@/api/http/config'
 
const activeName = ref('first')
 
const videoPlayerId = ref('videoPlayerId')
// loading
const spinning = ref<boolean>(false)
// 选中值
const selectedValue = ref<String>('')
const selectedId = ref<String>('')
// 机场/遥控器列表
const cardList = ref<projectCard[]>([])
// 视频地址
const videoUrl = ref<String>('')
// 设置图片地址
const imageUrl = new URL('@/assets/images/norecord.png', import.meta.url).href// ref<String>('@/assets/images/norecord.png')
 
// 下拉事件
const handleClick = (tab: TabsPaneContext, event: Event) => {
  console.log(tab, event)
}
 
const videoSrc = ref('')
 
// 页面初始化
const init = async () => {
  spinning.value = true
  const res = await getPlatformByUser().catch(e => {
    spinning.value = false
  })
  // 默认第一个机场
  selectedValue.value = res.data[0].nickname
  selectedId.value = res.data[0].workspace_id
  cardList.value = res.data
  // 加载视频接口
  loadVideo()
  // cesium.removeAllPoint()
  // cesium.removeAllDataSource()
  spinning.value = false
}
 
// 加载该设备的视频信息
const loadVideo = async () => {
  await getLiveCapacity({ id: selectedId.value }).then((res) => {
    console.log('草草草草', res)
    if (res.code != 0) return
      const resultData = res.data || {}
      const airport = resultData[1] // 会返回机场 和 无人机视频
      // if (airport == undefined) return
      const cameras_list = airport.cameras_list || []
      const videos_list = airport?.cameras_list?.[0].videos_list || []
      const videoId = airport.sn + '/' + cameras_list[0].index + '/' + videos_list[0].index
      const streamId = airport.sn + '-' + cameras_list[0].index + '-' + videos_list[0].index
    // 根据机场视频信息,更新无人机视频
    startLivestream({
      url: config.rtmpURL + streamId,
      video_id: videoId,
      url_type: 1,
      video_quality: 1,
      type: 2,
    }).then((res) => {
      console.log('获取视频地址',res)
      videoUrl.value = res.data.fmp4_url
      viewVideo(res.data.fmp4_url)
    })
  })
}
 
// 视频展示
async function viewVideo (url: string) {
  console.log(url, 'cccc')
  // videoSrc.value = url
  // return
  // showVideo.value = true
  // await nextTick()
  const player = videojs(videoPlayerId.value, {
    autoplay: true, // 自动播放
    controls: true, // 控件 设置为true,控件才会显示
    fullscreenToggle: true, // 是否显示全屏按钮
    playToggle: true, // 是否显示播放按钮
    progressControl: true, // 是否显示进度条。除了boolean,还可以设置一个ProgressControlOptions对象,更详细的配置进度条。
    volumePanel: true, // 是否显示音量。除了boolean,还可以设置一个VolumePanelOptions对象,更详细的配置音量组件。
    pictureInPictureToggle: false, // 是否显示画中画按钮
    remainingTimeDisplay: true, // 是否显示时长
 
  })
 
  player.src(url)
  player.on('ended', () => {
    // showVideo.value = false
  })
 
  player.on('error', () => {
    const error = player.error()
    console.log('video error:' + error.code + '-' + error.message)
  })
}
 
onMounted(() => {
  init()
})
 
</script>
 
<style lang="scss" scoped>
.drone-warp {
  height: 100vh;
  .airport-type {
    margin-top: 2%;
    height: 6%;
    width: 100%;
    background: rgba(31, 198, 255, 0.12);
    border: 1px solid rgba(0, 175, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    p {
      font-size: 16px;
      color: #1fc6ff;
      line-height: 40px;
      margin-left: 10px;
      cursor: pointer;
 
      &:first-child {
        margin: 0;
      }
    }
  }
  .video-play {
    width: 100%;
    height: calc(100vh - 50%);
  }
}
</style>