|
|
@@ -3,10 +3,11 @@
|
|
|
<div class="corner-deco tl"></div><div class="corner-deco tr"></div>
|
|
|
<div class="corner-deco bl"></div><div class="corner-deco br"></div>
|
|
|
<div class="panel-title">实验室视频监控</div>
|
|
|
- <div class="video-content">
|
|
|
- <webRTC v-if="webRtcType" class="video-for-min-box"></webRTC>
|
|
|
- <mpegts-video class="video-for-min-box" :videoProps="item" v-for="(item,index) in mpegtsList" :key="'mpegts_'+index"></mpegts-video>
|
|
|
- <videoForMod class="video-for-min-box" v-for="(item,index) in modList" :key="'video_'+index" :deviceNo="item.deviceNo"></videoForMod>
|
|
|
+ <div class="video-content" v-if="videoType">
|
|
|
+ <!--<webRTC v-if="webRtcType" class="video-for-min-box"></webRTC>-->
|
|
|
+ <!--<mpegts-video class="video-for-min-box" :videoProps="item" v-for="(item,index) in mpegtsList" :key="'mpegts_'+index"></mpegts-video>-->
|
|
|
+ <!--<videoForMod class="video-for-min-box" v-for="(item,index) in modList" :key="'video_'+index" :deviceNo="item.deviceNo"></videoForMod>-->
|
|
|
+ <videoForCarousel class="video-for-min-box-for" v-for="(item,index) in videoList" :key="'video_'+index" :deviceNo="item.deviceNo"></videoForCarousel>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
@@ -14,10 +15,11 @@
|
|
|
import { getVideoList,laboratoryLabScreenScreenConfigGet,iotDeviceList,laboratorySignInCheckGetKunYunToken } from '@/api/index'
|
|
|
import videoForMod from '@/components/videoForMod/videoForMod.vue'
|
|
|
import mpegtsVideo from '@/components/mpegtsVideo/mpegtsVideo.vue'
|
|
|
+ import videoForCarousel from '@/components/videoForMod/videoForCarousel/videoForCarousel.vue'
|
|
|
import webRTC from './webRTC.vue'
|
|
|
export default {
|
|
|
name: 'videoStats',
|
|
|
- components: { videoForMod,mpegtsVideo,webRTC },
|
|
|
+ components: { videoForMod,mpegtsVideo,webRTC,videoForCarousel },
|
|
|
data () {
|
|
|
return {
|
|
|
width:470,
|
|
|
@@ -27,15 +29,25 @@
|
|
|
pollTimer:null,
|
|
|
page:1,
|
|
|
webRtcType:false,
|
|
|
+ //轮播
|
|
|
+ videoList:[],
|
|
|
+ videoType:false,
|
|
|
+ videoQueryParams:{},
|
|
|
+ switchTimer: null, // 1s 延迟切换定时器(setTimeout)
|
|
|
+ videoLoading: false, // 请求防重入标识
|
|
|
}
|
|
|
},
|
|
|
created(){
|
|
|
|
|
|
},
|
|
|
mounted(){
|
|
|
- this.getData();
|
|
|
- this.pollTimer = setInterval(this.getData, 5 * 60 * 1000)
|
|
|
- // this.getVideoData();
|
|
|
+ //指定
|
|
|
+ // this.getData();
|
|
|
+ // this.pollTimer = setInterval(this.getData, 5 * 60 * 1000)
|
|
|
+ //轮播
|
|
|
+ this.getVideoData();
|
|
|
+ // this.pollTimer = setInterval(this.getVideoData, 5 * 60 * 1000)
|
|
|
+ this.pollTimer = setInterval(this.getVideoData, 30 * 1000)
|
|
|
},
|
|
|
methods:{
|
|
|
//指定视频
|
|
|
@@ -129,65 +141,126 @@
|
|
|
|
|
|
}
|
|
|
},
|
|
|
- //刷新视屏
|
|
|
- getVideoData(data) {
|
|
|
- let obj = {
|
|
|
- page: 1,
|
|
|
+ //轮播视频
|
|
|
+ // 轮播视频:保留上次 page,实现轮播推进
|
|
|
+ getVideoData() {
|
|
|
+ const page = this.videoQueryParams.page || 1; // 关键:不重置为 1
|
|
|
+ this.videoQueryParams = {
|
|
|
+ page,
|
|
|
pageSize: 4,
|
|
|
passageway: '',
|
|
|
- protocol: window.location.href.indexOf('https') !== -1 ? 'wss' : 'ws',
|
|
|
+ protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',
|
|
|
streamType: 1,
|
|
|
source: 4,
|
|
|
- subIds: data,
|
|
|
+ subIds: [],
|
|
|
};
|
|
|
- this.$set(this, 'videoQueryParams', obj);
|
|
|
- this.$nextTick(() => {
|
|
|
- this.videoInitialize()
|
|
|
- })
|
|
|
+ this.videoInitialize();
|
|
|
},
|
|
|
async videoInitialize() {
|
|
|
- let self = this;
|
|
|
- self.$set(self, 'videoType', false);
|
|
|
- self.$set(self, 'videoList', []);
|
|
|
+ if (this.videoLoading) return;
|
|
|
+ this.videoLoading = true;
|
|
|
+
|
|
|
+ const TARGET = this.videoQueryParams.pageSize || 4;
|
|
|
+ const MAX_LOOP = 20;
|
|
|
+ const list = [];
|
|
|
+
|
|
|
+ let page = this.videoQueryParams.page || 1;
|
|
|
+ let total = 0;
|
|
|
+ let loop = 0;
|
|
|
+ let wrapped = false;
|
|
|
+ let lastPage = page; // 记录本轮实际请求到的最后一个 page
|
|
|
+
|
|
|
try {
|
|
|
- // const res = await getVideoList(this.videoQueryParams)
|
|
|
-
|
|
|
- // 假数据开始
|
|
|
- let res = {
|
|
|
- data: {
|
|
|
- total: 100,
|
|
|
- records: [
|
|
|
- {streamUrl: '1', deviceNo: '1'},
|
|
|
- {streamUrl: '2', deviceNo: '2'},
|
|
|
- {streamUrl: '3', deviceNo: '3'},
|
|
|
- {streamUrl: '4', deviceNo: '4'},
|
|
|
- ],
|
|
|
+ while (list.length < TARGET && loop < MAX_LOOP) {
|
|
|
+ loop++;
|
|
|
+
|
|
|
+ const res = await getVideoList({
|
|
|
+ ...this.videoQueryParams,
|
|
|
+ page,
|
|
|
+ pageSize: TARGET,
|
|
|
+ });
|
|
|
+ const records = (res && res.data && res.data.records) || [];
|
|
|
+ total = (res && res.data && res.data.total) || 0;
|
|
|
+ lastPage = page; // 记录本轮请求到的 page
|
|
|
+
|
|
|
+ if (total === 0) break;
|
|
|
+ if (records.length === 0 && wrapped) break;
|
|
|
+
|
|
|
+ for (const item of records) {
|
|
|
+ if (list.length >= TARGET) break;
|
|
|
+ list.push({
|
|
|
+ width: this.width,
|
|
|
+ height: this.height,
|
|
|
+ url: item.streamUrl,
|
|
|
+ cameraIndexCode: item.deviceNo,
|
|
|
+ deviceNo: item.deviceNo,
|
|
|
+ });
|
|
|
}
|
|
|
- };
|
|
|
- // 假数据结束
|
|
|
|
|
|
- let list = [];
|
|
|
- for(let i=0;i<res.data.records.length;i++){
|
|
|
- list.push(
|
|
|
- {
|
|
|
- width: self.width, //(宽度:非必传-默认600)
|
|
|
- height: self.height, //(高度:非必传-默认338)
|
|
|
- url: res.data.records[i].streamUrl,
|
|
|
- cameraIndexCode: res.data.records[i].deviceNo,
|
|
|
- }
|
|
|
- )
|
|
|
+ if (list.length >= TARGET) break;
|
|
|
+
|
|
|
+ const totalPage = Math.max(Math.ceil(total / TARGET), 1);
|
|
|
+ page++;
|
|
|
+ if (page > totalPage) {
|
|
|
+ page = 1;
|
|
|
+ wrapped = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // —— 一条数据都没拿到 ——
|
|
|
+ if (list.length === 0) {
|
|
|
+ // 首次加载:让播放器容器渲染出来,避免一直黑屏(空态由模板/子组件处理)
|
|
|
+ // 后续轮播:保持旧视频继续播放,不切换
|
|
|
+ if (this.videoList.length === 0) {
|
|
|
+ this.videoType = true;
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
- this.$set(this,'videoList',list)
|
|
|
- this.$nextTick(()=>{
|
|
|
- setTimeout(function(){
|
|
|
- self.$set(self, 'videoType', true);
|
|
|
- },1000);
|
|
|
- })
|
|
|
+
|
|
|
+ // —— 先写数据、再切换 ——
|
|
|
+ this.videoType = false;
|
|
|
+ this.videoList = list;
|
|
|
+
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (this.switchTimer) clearTimeout(this.switchTimer);
|
|
|
+ this.switchTimer = setTimeout(() => {
|
|
|
+ this.videoType = true;
|
|
|
+ this.switchTimer = null;
|
|
|
+
|
|
|
+ // —— 渲染完成后,再统一刷新 page,供下次轮播使用 ——
|
|
|
+ const totalPage = Math.max(Math.ceil(total / TARGET), 1);
|
|
|
+ let nextPage;
|
|
|
+ if (lastPage >= totalPage) {
|
|
|
+ nextPage = 1; // 到达总数末尾,回到开头
|
|
|
+ } else {
|
|
|
+ nextPage = lastPage + 1; // 继续往后推进
|
|
|
+ }
|
|
|
+ this.videoQueryParams.page = nextPage;
|
|
|
+ }, 1000);
|
|
|
+ });
|
|
|
} catch (e) {
|
|
|
- console.error('VideoGrid:', e)
|
|
|
+ console.error('VideoGrid:', e);
|
|
|
+ // 首次加载失败也不至于一直黑屏(后续失败则保持旧视频)
|
|
|
+ if (this.videoList.length === 0) {
|
|
|
+ this.videoType = true;
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ this.videoLoading = false;
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
+ beforeDestroy() {
|
|
|
+ // 清理轮播轮询定时器
|
|
|
+ if (this.pollTimer) {
|
|
|
+ clearInterval(this.pollTimer);
|
|
|
+ this.pollTimer = null;
|
|
|
+ }
|
|
|
+ // 清理 1s 延迟切换定时器
|
|
|
+ if (this.switchTimer) {
|
|
|
+ clearTimeout(this.switchTimer);
|
|
|
+ this.switchTimer = null;
|
|
|
+ }
|
|
|
+ },
|
|
|
}
|
|
|
</script>
|
|
|
<style scoped lang="scss">
|
|
|
@@ -232,5 +305,24 @@
|
|
|
.video-for-min-box:nth-child(4){
|
|
|
/*margin:10px 0 0 0!important;*/
|
|
|
}
|
|
|
+ .video-for-min-box-for{
|
|
|
+ display: inline-block!important;
|
|
|
+ overflow: hidden!important;
|
|
|
+ border-radius:4px!important;
|
|
|
+ height:280px!important;
|
|
|
+ width:470px!important;
|
|
|
+ }
|
|
|
+ .video-for-min-box-for:nth-child(1){
|
|
|
+ margin:0 10px 0 0!important;
|
|
|
+ }
|
|
|
+ .video-for-min-box-for:nth-child(2){
|
|
|
+
|
|
|
+ }
|
|
|
+ .video-for-min-box-for:nth-child(3){
|
|
|
+ margin:10px 10px 0 0!important;
|
|
|
+ }
|
|
|
+ .video-for-min-box-for:nth-child(4){
|
|
|
+ margin:10px 0 0 0!important;
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|