这块我用的是组件,有些组件传值和组件调用方法
<template>
<div class="block">
<div>
<!-- <span>
当前第{{ FactoryVideosObj.currentpage }}页/共{{
FactoryVideosObj.totalpage
}}页
</span> -->
<button v-if="fanhui" class="button topbutton" @click="goback">返回</button>
<div v-else @click="to('/risk-warning-video?facID=' + facID)">
<i class="el-icon-copy-document icon-sy"></i>
</div>
<!-- <el-carousel
indicator-position="none"
:autoplay="false"
trigger="click"
@change="changeFn"
:height="type == 3 ? '600px' : ''"
>
<el-carousel-item v-for="(item,i) in Number(FactoryVideosObj.totalpage) ? Number(FactoryVideosObj.totalpage) : 1" :key="i">
<div class="video_box" style="height:100%;" >
<div style="display:flex;flex-wrap:wrap;height:100%;">
<video controls id="myVideo1" :style="height == '400px' ? 'height:100%':'height:50%'" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source :src="FactoryVideosObj.video1" width="100%" height="220" type="application/x-mpegURL" />
</video>
<video controls id="myVideo2" :style="height == '400px' ? 'height:100%':'height:50%'" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source :src="FactoryVideosObj.video2" height="220" type="application/x-mpegURL" />
</video>
<video controls id="myVideo3" :style="height == '400px' ? 'height:100%':'height:50%'" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source :src="FactoryVideosObj.video3" height="220" type="application/x-mpegURL" />
</video>
<video controls id="myVideo4" :style="height == '400px' ? 'height:100%':'height:50%'" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source :src="FactoryVideosObj.video4" height="220" type="application/x-mpegURL" />
</video>
</div> -->
<!-- <video controls >
<source
:src="FactoryVideosObj.video1"
:height="height"
type="video/mp4"
/>
<source src="movie.ogg" :height="height" type="video/ogg" />
</video>
<video controls :style="height == '400px' ? 'height:100%':''">
<source
:src="FactoryVideosObj.video2"
:height="height"
type="video/mp4"
/>
<source src="movie.ogg" :height="height" type="video/ogg" />
</video>
<video controls :style="height == '400px'? 'height:100%':''">
<source
:src="FactoryVideosObj.video3"
:height="height"
type="video/mp4"
/>
<source src="movie.ogg" :height="height" type="video/ogg" />
</video>
<video controls :style="height == '400px'? 'height:100%':''">
<source
:src="FactoryVideosObj.video4"
:height="height"
type="video/mp4"
/>
<source src="movie.ogg" :height="height" type="video/ogg" />
</video> -->
<!-- </div>
</el-carousel-item>
</el-carousel> -->
<div class="video_box">
<div id="video_box_cont" style="display:flex;flex-wrap:wrap" v-html="dom">
<!-- <video controls id="myVideo" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source src="http://1252093142.vod2.myqcloud.com/4704461fvodcq1252093142/48c8a9475285890781000441992/playlist.m3u8" height="220" type="application/x-mpegURL" />
</video> -->
</div>
<div class="text">
<i class="el-icon-caret-left" @click="next2"></i> 第 {{FactoryVideosForm.currentPage + 1}} 页,共 {{totalpage}} 页 <i class="el-icon-caret-right" @click="next1"></i><div>共 {{this.FactoryVideosObj.totalvideo}} 条</div>
</div>
</div>
</div>
</div>
</template>
<script>
import '@/styles/video.css'
import videojs from "video.js";
import "videojs-contrib-hls";
import { FactoryVideos, HroomVideos , getVideoList } from "@/api/enterprise";
export default {
name: "tabsvideo",
data() {
return {
// 企业监控—右侧视频列表
FactoryVideosObj: {
// currentpage:0,
},
FactoryVideosForm: {
currentPage: 0,
opt: 'next',
},
totalpage: 0,
facID: "",
myVideo1:null,
myVideo2:null,
myVideo3:null,
myVideo4:null,
dom:''
};
},
props: {
type: [Number, String],
height:{
type:[Number,String],
default: '220px'
},
fanhui:{
type:[Number,Boolean],
default:false
},
},
created() {
this.getFunc();
},
mounted() {
},
destroyed(){
this.disposeFn()
},
methods: {
disposeFn(){
this.myVideo1.dispose(),
this.myVideo2.dispose(),
this.myVideo3.dispose(),
this.myVideo4.dispose(),
this.dom = `
<video controls id="myVideo1" autoplay muted style="height:${this.height};width:50%" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source src="${this.FactoryVideosObj.video1 || ''}" width="100%" height="220" type="application/x-mpegURL" />
</video>
<video controls id="myVideo2" autoplay muted style="height:${this.height};width:50%" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source src="${this.FactoryVideosObj.video2 || ''}" width="100%" height="220" type="application/x-mpegURL" />
</video>
<video controls id="myVideo3" autoplay muted style="height:${this.height};width:50%" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source src="${this.FactoryVideosObj.video3 || ''}" width="100%" height="220" type="application/x-mpegURL" />
</video>
<video controls id="myVideo4" autoplay muted style="height:${this.height};width:50%" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source src="${this.FactoryVideosObj.video4 || ''}" width="100%" height="220" height="220" type="application/x-mpegURL" />
</video>
`
this.initFn()
},
to(url) {
this.$router.push("/enterprise" + url);
},
getFunc() {
this.$on("video", (res) => {
// callMethod我们在父组件定义的方法名
// 企业监控—危险源/反馈数(危险区域基本信息)
if (res.init) {
this.FactoryVideosForm.currentPage = 0
}
if(res.treeid){
if(this.type == 3){
this.FactoryVideosForm.facid = res.treeid
}else {
this.FactoryVideosForm.facID = res.treeid;
}
}
if(res.hRoomLocation){
this.FactoryVideosForm.hRoomLocation = res.hRoomLocation;
}
if(res.opt){
this.FactoryVideosForm.opt = res.opt;
}
if(res.time){
this.FactoryVideosForm.createDate = res.time;
}
this.facID = res.treeid;
console.log(this.FactoryVideosForm);
// 企业监控—右侧视频列表
this.getList('init');
});
},
changeFn(val) {
this.FactoryVideosForm.currentPage = val;
this.getList();
},
getList(type) {
if(type == 'init'){
this.dom = `
<video controls autoplay muted id="myVideo1" style="height:${this.height};width:50%" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source src="${this.FactoryVideosObj.video1 || ''}" width="100%" height="220" type="application/x-mpegURL" />
</video>
<video controls autoplay muted id="myVideo2" style="height:${this.height};width:50%" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source src="${this.FactoryVideosObj.video2 || ''}" width="100%" height="220" type="application/x-mpegURL" />
</video>
<video controls autoplay muted id="myVideo3" style="height:${this.height};width:50%" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source src="${this.FactoryVideosObj.video3 || ''}" width="100%" height="220" type="application/x-mpegURL" />
</video>
<video controls autoplay muted id="myVideo4" style="height:${this.height};width:50%" class="video-js vjs-default-skin vjs-big-play-centered" preload="auto" data-setup='{}'>
<source src="${this.FactoryVideosObj.video4 || ''}" width="100%" height="220" height="220" type="application/x-mpegURL" />
</video>
`
}
if (this.type == 1) {
FactoryVideos(this.FactoryVideosForm).then((res) => {
this.FactoryVideosObj = res.data;
this.initFn(type)
this.totalpage = res.data.totalpage;
});
} else if (this.type == 2) {
HroomVideos(this.FactoryVideosForm).then((res) => {
this.FactoryVideosObj = res.data;
this.initFn(type)
this.totalpage = res.data.totalpage;
});
} else if(this.type == 3){
getVideoList(this.FactoryVideosForm).then((res) => {
this.FactoryVideosObj = res.data;
this.initFn(type)
this.totalpage = res.data.totalpage;
});
}
},
initFn(type){
if(type == 'init'){
this.myVideo1 = videojs('myVideo1', {
bigPlayButton: true,
textTrackDisplay: false,
posterImage: false,
errorDisplay: false,
})
this.myVideo2 = videojs('myVideo2', {
bigPlayButton: true,
textTrackDisplay: false,
posterImage: false,
errorDisplay: false,
})
this.myVideo3 = videojs('myVideo3', {
bigPlayButton: true,
textTrackDisplay: false,
posterImage: false,
errorDisplay: false,
})
this.myVideo4 = videojs('myVideo4', {
bigPlayButton: true,
textTrackDisplay: false,
posterImage: false,
errorDisplay: false,
})
this.$nextTick(()=>{
var myVideo1 = document.getElementById('myVideo1')
var myVideo2 = document.getElementById('myVideo2')
var myVideo3 = document.getElementById('myVideo3')
var myVideo4 = document.getElementById('myVideo4')
myVideo1.children[0].style.width = '100%'
myVideo2.children[0].style.width = '100%'
myVideo3.children[0].style.width = '100%'
myVideo4.children[0].style.width = '100%'
myVideo1.children[0].style.height = '100%'
myVideo2.children[0].style.height = '100%'
myVideo3.children[0].style.height = '100%'
myVideo4.children[0].style.height = '100%'
})
}
for(var i =0;i<4;i++){
if(this.FactoryVideosObj['video' + (i + 1)]){
if (/\.m3u8$/.test(this.FactoryVideosObj['video' + (i + 1)])) { //判断视频源是否是m3u8的格式
this['myVideo' + (i + 1)].src({
src: this.FactoryVideosObj['video' + (i + 1)],
type: 'application/x-mpegURL' //在重新添加视频源的时候需要给新的type的值
})
} else {
this['myVideo' + (i + 1)].src(this.FactoryVideosObj['video' + (i + 1)])
}
}else{
// 如果没有视频源就清除一下播放器
this['myVideo' + (i + 1)].src({
src: '',
type: 'application/x-mpegURL' //在重新添加视频源的时候需要给新的type的值
})
}
}
},
goback(){
this.$emit('fanhuiFn')
},
next1(){
console.log(this.FactoryVideosForm.currentPage < Number(this.totalpage) - 1)
if(this.FactoryVideosForm.currentPage < Number(this.totalpage) - 1){
this.FactoryVideosForm.currentPage = this.FactoryVideosForm.currentPage + 1
this.getList()
}else{
this.FactoryVideosForm.currentPage = Number(this.totalpage) - 1
}
},
next2(){
if(this.FactoryVideosForm.currentPage > 0){
this.FactoryVideosForm.currentPage = this.FactoryVideosForm.currentPage - 1
this.getList()
}else{
this.FactoryVideosForm.currentPage = 0
}
}
},
};
</script>
<style lang="less" scoped>
#myVideo1,
#myVideo2,
#myVideo3,
#myVideo4{
width: 50%;
height: 200px;
// margin-right: 5px;
video{
max-height: 400px;
width:100%;
}
}
.text{
display: flex;
align-items: center;
margin-top: 10px;
font-size: 16px;
i{
font-size: 20px !important;
margin: 0 10px;
cursor: pointer;
}
}
.icon-sy {
position: absolute;
right: 20px;
top: -15px;
font-size: 20px;
}
.icon-sy:hover {
cursor: pointer;
color: var(--theme);
}
</style>