HHVideo.vue 2.38 KB
<template>
	<div>
		<video :id="videoName" class="video-monitor" muted autoplay></video>
	</div>
</template>
<script>
/**
 * @name HHVideo
 * @module src/components/HHVideo
 * @desc 用于页面显示各个监控信息组件
 * @author 胡菁
 * @date 2024年08月12日13:39
 * @example <hh-video></hh-video>
 */
export default {
	components: {},
	data() {
		return {
			webRtcServer: null,
			isShow: false,
			isLoad: false,
			videoName: 'videoMonitor' + Math.random() * 1000,
			configPar: null,
			channelPar: '',
			typePar: '',
			servicePar: '',
		}
	},
	props: {
		type: {
			type: String,
			default: '0',
		},
		config: {
			type: Object,
			default: null,
		},
		channel: {
			type: String,
			default: '',
		},
		service: {
			type: String,
			default: '',
		},
	},
	created() {},
	mounted() {
		this.configPar = this.$props.config
		this.channelPar = this.$props.channel
		this.typePar = this.$props.type
		this.servicePar = this.$props.service
	},
	destroyed() {},
	activated() {
		if (this.typePar != '0') {
			this.showVideo()
		}
	},
	deactivated() {
		if (this.webRtcServer != null) {
			this.hideVideo()
			this.isLoad = false
			this.webRtcServer.disconnect()
		}
	},
	methods: {
		//显示监控
		showVideo() {
			if (!this.isLoad) {
				if (this.webRtcServer == null) {
					this.webRtcServer = new WebRtcStreamer(this.videoName, location.protocol + '//' + this.servicePar)
				}
				if (this.configPar != null) {
					this.webRtcServer.connect(`rtsp://${this.configPar.name}:${this.configPar.password}@${this.configPar.ip}:554/Streaming/Channels/${this.channelPar}01`)
				}
				setTimeout(() => {
					this.isLoad = true
				}, 3000)
			}
			this.showHideDiv(true)
		},

		//隐藏监控
		hideVideo() {
			this.showHideDiv(false)
		},

		showHideDiv(fig) {
			this.isShow = fig
		},
	},
}
</script>
<style lang="scss" scoped>
.hh-video {
	position: absolute;
	z-index: 999;
	width: 100%;
	height: 100%;
	display: flex;
	text-align: center;
	align-items: center;
	justify-content: center;
	pointer-events: none;
}

.video-root {
	width: 50%;
	height: 55%;
	display: flex;
	align-items: center;
	justify-content: center;
}

.div-image {
	position: absolute;
	right: -30px;
	top: 0px;
	cursor: pointer;
	pointer-events: auto;
}

.video-monitor {
	width: 100%;
	height: 100%;
	object-fit: fill;
	//margin-top: 2%;
}

.show-area {
	opacity: 1;
	z-index: 9999;
}
.hidden-area {
	opacity: 0;
	z-index: -9999;
}
</style>