wvp-GB28181-pro/web_src/src/components/live.vue

347 lines
8.6 KiB
Vue
Raw Normal View History

<template>
<div id="devicePosition" style="width:100vw; height: 91vh">
2022-04-24 00:30:31 +08:00
<el-container v-loading="loading" style="height: 91vh;" element-loading-text="拼命加载中">
2024-09-12 17:49:16 +08:00
<el-aside width="400px" style="background-color: #ffffff">
2022-04-24 00:30:31 +08:00
<DeviceTree :clickEvent="clickEvent" :contextMenuEvent="contextMenuEvent"></DeviceTree>
</el-aside>
<el-container>
<el-header height="5vh" style="text-align: left;font-size: 17px;line-height:5vh">
分屏:
2024-09-12 17:49:16 +08:00
<i class="iconfont icon-a-mti-1fenpingshi btn" :class="{active:spiltIndex === 0}" @click="spiltIndex=0"/>
<i class="iconfont icon-a-mti-4fenpingshi btn" :class="{active: spiltIndex === 1}" @click="spiltIndex=1"/>
<i class="iconfont icon-a-mti-6fenpingshi btn" :class="{active: spiltIndex === 2}" @click="spiltIndex=2"/>
<i class="iconfont icon-a-mti-9fenpingshi btn" :class="{active: spiltIndex === 3}" @click="spiltIndex=3"/>
</el-header>
2024-09-12 17:49:16 +08:00
<el-main style="padding: 0; margin: 0 auto; background-color: #a9a8a8" >
<div :style="{width: '151vh', height: '85vh', display: 'grid', gridTemplateColumns: layout[spiltIndex].columns,
gridTemplateRows: layout[spiltIndex].rows, gap: '4px', backgroundColor: '#a9a8a8'}">
<div v-for="i in layout[spiltIndex].spilt" :key="i" class="play-box" :class="getPlayerClass(spiltIndex, i)"
@click="playerIdx = (i-1)">
2024-09-12 17:49:16 +08:00
<div v-if="!videoUrl[i-1]" style="color: #ffffff;font-size: 15px;font-weight: bold;"></div>
<player ref="player" v-else :videoUrl="videoUrl[i-1]" fluent autoplay @screenshot="shot"
@destroy="destroy"/>
</div>
</div>
</el-main>
</el-container>
</el-container>
</div>
</template>
<script>
2024-09-12 17:49:16 +08:00
2022-04-24 00:30:31 +08:00
import uiHeader from "../layout/UiHeader.vue";
import player from './common/jessibuca.vue'
import DeviceTree from './common/DeviceTree.vue'
2022-04-24 00:30:31 +08:00
export default {
name: "live",
components: {
uiHeader, player, DeviceTree
},
2024-09-12 17:49:16 +08:00
2022-04-24 00:30:31 +08:00
data() {
return {
videoUrl: [''],
2024-09-12 17:49:16 +08:00
spiltIndex: 2,//分屏
2022-04-24 00:30:31 +08:00
playerIdx: 0,//激活播放器
2022-04-24 00:30:31 +08:00
updateLooper: 0, //数据刷新轮训标志
count: 15,
total: 0,
2022-04-24 00:30:31 +08:00
//channel
2024-09-12 17:49:16 +08:00
loading: false,
layout: [
{
spilt: 1,
columns: "1fr",
rows: "1fr",
style: function (){}
},
{
spilt: 4,
columns: "1fr 1fr",
rows: "1fr 1fr",
style: function (){}
},
{
spilt: 6,
columns: "1fr 1fr 1fr",
rows: "1fr 1fr 1fr",
style: function (index){
console.log(index)
if (index === 0) {
return {
gridColumn: ' 1 / span 2',
gridRow: ' 1 / span 2',
}
}
}
},
{
spilt: 9,
columns: "1fr 1fr 1fr",
rows: "1fr 1fr 1fr",
style: function (){}
},
]
2022-04-24 00:30:31 +08:00
};
},
mounted() {
2022-04-24 00:30:31 +08:00
},
created() {
this.checkPlayByParam()
},
2022-04-24 00:30:31 +08:00
computed: {
liveStyle() {
let style = {width: '100%', height: '100%'}
switch (this.spilt) {
case 4:
style = {width: '49%', height: '49%'}
break
case 9:
style = {width: '32%', height: '32%'}
break
}
this.$nextTick(() => {
for (let i = 0; i < this.spilt; i++) {
const player = this.$refs.player
player && player[i] && player[i].updatePlayerDomSize()
}
})
return style
2022-04-24 00:30:31 +08:00
}
},
watch: {
spilt(newValue) {
console.log("切换画幅;" + newValue)
let that = this
for (let i = 1; i <= newValue; i++) {
if (!that.$refs['player' + i]) {
continue
}
this.$nextTick(() => {
if (that.$refs['player' + i] instanceof Array) {
that.$refs['player' + i][0].resize()
} else {
that.$refs['player' + i].resize()
}
2022-04-24 00:30:31 +08:00
})
2022-04-24 00:30:31 +08:00
}
window.localStorage.setItem('split', newValue)
},
'$route.fullPath': 'checkPlayByParam'
},
destroyed() {
clearTimeout(this.updateLooper);
},
methods: {
destroy(idx) {
console.log(idx);
this.clear(idx.substring(idx.length - 1))
},
2024-09-12 17:49:16 +08:00
clickEvent: function (channelId) {
this.sendDevicePush(channelId)
},
getPlayerClass: function (splitIndex, i) {
let classStr = "play-box-" + splitIndex + "-" +i
if (this.playerIdx === (i-1)) {
classStr += " redborder"
2022-04-24 00:30:31 +08:00
}
2024-09-12 17:49:16 +08:00
return classStr
2022-04-24 00:30:31 +08:00
},
2022-07-03 07:40:54 +08:00
contextMenuEvent: function (device, event, data, isCatalog) {
2022-04-24 00:30:31 +08:00
},
2022-04-24 00:30:31 +08:00
//通知设备上传媒体流
2024-09-12 17:49:16 +08:00
sendDevicePush: function (channelId) {
this.save(channelId)
2022-04-24 00:30:31 +08:00
let idxTmp = this.playerIdx
this.$axios({
method: 'get',
2024-09-12 17:49:16 +08:00
url: '/api/common/channel/play',
params: {
channelId: channelId
}
}).then((res)=> {
if (res.data.code === 0 && res.data.data) {
let videoUrl;
if (location.protocol === "https:") {
videoUrl = res.data.data.wss_flv;
} else {
videoUrl = res.data.data.ws_flv;
}
2024-09-12 17:49:16 +08:00
this.setPlayUrl(videoUrl, idxTmp);
2022-04-24 00:30:31 +08:00
} else {
2024-09-12 17:49:16 +08:00
this.$message.error(res.data.msg);
}
2022-04-24 00:30:31 +08:00
}).catch(function (e) {
}).finally(() => {
2024-09-12 17:49:16 +08:00
this.loading = false
2022-04-24 00:30:31 +08:00
});
},
setPlayUrl(url, idx) {
this.$set(this.videoUrl, idx, url)
let _this = this
setTimeout(() => {
window.localStorage.setItem('videoUrl', JSON.stringify(_this.videoUrl))
}, 100)
2022-04-24 00:30:31 +08:00
},
checkPlayByParam() {
2024-09-12 17:49:16 +08:00
let channelId = this.$route.query
if (channelId) {
this.sendDevicePush(channelId)
2022-04-24 00:30:31 +08:00
}
},
shot(e) {
// console.log(e)
// send({code:'image',data:e})
var base64ToBlob = function (code) {
let parts = code.split(';base64,');
let contentType = parts[0].split(':')[1];
let raw = window.atob(parts[1]);
let rawLength = raw.length;
let uInt8Array = new Uint8Array(rawLength);
for (let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
2022-04-24 00:30:31 +08:00
return new Blob([uInt8Array], {
type: contentType
});
2022-04-24 00:30:31 +08:00
};
let aLink = document.createElement('a');
let blob = base64ToBlob(e); //new Blob([content]);
let evt = document.createEvent("HTMLEvents");
evt.initEvent("click", true, true); //initEvent 不加后两个参数在FF下会报错 事件类型,是否冒泡,是否阻止浏览器的默认行为
aLink.download = '截图';
aLink.href = URL.createObjectURL(blob);
aLink.click();
},
save(item) {
let dataStr = window.localStorage.getItem('playData') || '[]'
let data = JSON.parse(dataStr);
data[this.playerIdx] = item
window.localStorage.setItem('playData', JSON.stringify(data))
},
clear(idx) {
let dataStr = window.localStorage.getItem('playData') || '[]'
let data = JSON.parse(dataStr);
data[idx - 1] = null;
console.log(data);
window.localStorage.setItem('playData', JSON.stringify(data))
},
}
};
</script>
<style>
2022-04-24 00:30:31 +08:00
.btn {
margin: 0 10px;
2022-04-24 00:30:31 +08:00
}
2022-04-24 00:30:31 +08:00
.btn:hover {
color: #409EFF;
}
.btn.active {
color: #409EFF;
}
.redborder {
2024-09-12 17:49:16 +08:00
border: 2px solid rgb(64, 158, 255) !important;
2022-04-24 00:30:31 +08:00
}
.play-box {
background-color: #000000;
2024-09-12 17:49:16 +08:00
//border: 2px solid #505050;
2022-04-24 00:30:31 +08:00
display: flex;
align-items: center;
justify-content: center;
}
2024-09-12 17:49:16 +08:00
.play-box-2-1 {
grid-column: 1 / span 2;
grid-row: 1 / span 2;
}
</style>
<style>
2022-04-24 00:30:31 +08:00
.videoList {
display: flex;
flex-wrap: wrap;
align-content: flex-start;
}
2022-04-24 00:30:31 +08:00
.video-item {
position: relative;
width: 15rem;
height: 10rem;
margin-right: 1rem;
background-color: #000000;
}
2022-04-24 00:30:31 +08:00
.video-item-img {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 100%;
height: 100%;
}
2022-04-24 00:30:31 +08:00
.video-item-img:after {
content: "";
display: inline-block;
position: absolute;
z-index: 2;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 3rem;
height: 3rem;
background-image: url("../assets/loading.png");
background-size: cover;
background-color: #000000;
}
2022-04-24 00:30:31 +08:00
.video-item-title {
position: absolute;
bottom: 0;
color: #000000;
background-color: #ffffff;
line-height: 1.5rem;
padding: 0.3rem;
width: 14.4rem;
}
2022-04-24 00:30:31 +08:00
.baidumap {
width: 100%;
height: 100%;
border: none;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
}
2022-04-24 00:30:31 +08:00
/* 去除百度地图版权那行字 和 百度logo */
.baidumap > .BMap_cpyCtrl {
display: none !important;
}
.baidumap > .anchorBL {
display: none !important;
}
</style>