|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
- <div class="video_area" :style="getAreaStyle()">
|
|
|
+ <div ref="videoArea" class="video_area" :style="getAreaStyle()">
|
|
|
<SerialNumberPosition :property="data.property" />
|
|
|
- <div ref="videoArea" class="main">
|
|
|
+ <div ref="videoAreaBox" class="main">
|
|
|
<ul v-if="'independent' === data.property.view_method" class="view-independent">
|
|
|
<li v-for="(file, i) in data.file_list" :key="i">
|
|
|
<VideoPlay
|
|
@@ -71,51 +71,57 @@ export default {
|
|
|
viewTopBottomBtn: false,
|
|
|
fileLen: 0,
|
|
|
translateY: 0,
|
|
|
+ elementID: '',
|
|
|
+ observersMap: {},
|
|
|
};
|
|
|
},
|
|
|
watch: {
|
|
|
data: {
|
|
|
handler(val) {
|
|
|
this.fileLen = val.file_list.length;
|
|
|
- if (this.fileLen > 0) {
|
|
|
- const ele = this.$refs.videoArea;
|
|
|
+ if (this.fileLen > 0 && this.data.property.view_method === 'list') {
|
|
|
+ const ele = this.$refs.videoAreaBox;
|
|
|
this.elementWidth = ele.clientWidth;
|
|
|
this.elementHeight = ele.clientHeight;
|
|
|
- window.addEventListener('resize', this.handleResize);
|
|
|
+ const mainEle = this.$refs.videoArea;
|
|
|
+ // 检查元素是否包含已知的类名
|
|
|
+ mainEle.classList.forEach((className) => {
|
|
|
+ // 排除已知的类名
|
|
|
+ if (className !== 'audio-area') {
|
|
|
+ // 打印另一个类名
|
|
|
+ this.elementID = className;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
deep: true,
|
|
|
},
|
|
|
- elementWidth(newWidth, oldWidth) {
|
|
|
- // console.log(`宽度从 ${oldWidth} 变为 ${newWidth}`);
|
|
|
+ elementWidth(newWidth) {
|
|
|
this.elementWidth = newWidth;
|
|
|
},
|
|
|
- elementHeight(newHeight, oldHeight) {
|
|
|
- // console.log(`高度从 ${oldHeight} 变为 ${newHeight}`);
|
|
|
+ elementHeight(newHeight) {
|
|
|
this.elementHeight = newHeight;
|
|
|
this.isViewTopBottomBtn();
|
|
|
},
|
|
|
},
|
|
|
mounted() {
|
|
|
this.$nextTick(() => {
|
|
|
- let _class = document.querySelector('.canvas');
|
|
|
- if (_class === null) return;
|
|
|
- if (_class.classList.contains('canvas')) {
|
|
|
- this.resizeObserver = new ResizeObserver((entries) => {
|
|
|
- for (let entry of entries) {
|
|
|
- this.elementWidth = entry.contentRect.width;
|
|
|
- this.elementHeight = entry.contentRect.height;
|
|
|
- }
|
|
|
- });
|
|
|
- this.resizeObserver.observe(this.$el);
|
|
|
- }
|
|
|
+ const canvasElement = document.querySelector('.canvas');
|
|
|
+ if (!canvasElement) return;
|
|
|
+ const instanceName = `observer_${this.elementID}`;
|
|
|
+ this.observersMap[instanceName] = new ResizeObserver((entries) => {
|
|
|
+ for (let entry of entries) {
|
|
|
+ this.elementWidth = entry.contentRect.width;
|
|
|
+ this.elementHeight = entry.contentRect.height;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.observersMap[instanceName].observe(this.$el);
|
|
|
});
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
- window.removeEventListener('resize', this.handleResize);
|
|
|
- if (this.resizeObserver) {
|
|
|
- this.resizeObserver.disconnect();
|
|
|
- }
|
|
|
+ Object.values(this.observersMap).forEach((observer) => {
|
|
|
+ observer.disconnect();
|
|
|
+ });
|
|
|
},
|
|
|
methods: {
|
|
|
handleAudioClick(index) {
|
|
@@ -144,7 +150,7 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
handleResize() {
|
|
|
- const width = this.$refs.videoArea.clientWidth;
|
|
|
+ const width = this.$refs.videoAreaBox.clientWidth;
|
|
|
if (width !== this.elementWidth) {
|
|
|
this.elementWidth = width;
|
|
|
}
|