fix(projects): 添加西瓜视频实例在onUnMounted的销毁,多页签居中距离精确
This commit is contained in:
parent
c429cd0293
commit
738964a769
@ -71,13 +71,13 @@ function setDropdownConfig(x: number, y: number, currentPath: string) {
|
|||||||
|
|
||||||
// 获取当前激活的tab的clientX
|
// 获取当前激活的tab的clientX
|
||||||
const tabRef = ref<HTMLElement | null>(null);
|
const tabRef = ref<HTMLElement | null>(null);
|
||||||
async function getActiveChromeTabClientX() {
|
async function getActiveTabClientX() {
|
||||||
await nextTick();
|
await nextTick();
|
||||||
const index = app.activeMultiTabIndex;
|
const index = app.activeMultiTabIndex;
|
||||||
if (tabRef.value) {
|
if (tabRef.value) {
|
||||||
const activeTabElement = tabRef.value.children[index];
|
const activeTabElement = tabRef.value.children[index];
|
||||||
const { x, width } = activeTabElement.getBoundingClientRect();
|
const { x, width } = activeTabElement.getBoundingClientRect();
|
||||||
const clientX = x + width;
|
const clientX = x + width / 2;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
emit('scroll', clientX);
|
emit('scroll', clientX);
|
||||||
}, 50);
|
}, 50);
|
||||||
@ -103,7 +103,7 @@ useEventListener(window, 'beforeunload', () => {
|
|||||||
watch(
|
watch(
|
||||||
() => app.activeMultiTabIndex,
|
() => app.activeMultiTabIndex,
|
||||||
() => {
|
() => {
|
||||||
getActiveChromeTabClientX();
|
getActiveTabClientX();
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
immediate: true
|
immediate: true
|
||||||
|
@ -7,24 +7,30 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted, onUnmounted } from 'vue';
|
||||||
import { NCard } from 'naive-ui';
|
import { NCard } from 'naive-ui';
|
||||||
import Player from 'xgplayer';
|
import Player from 'xgplayer';
|
||||||
|
|
||||||
const domRef = ref<HTMLElement | null>(null);
|
const domRef = ref<HTMLElement | null>(null);
|
||||||
|
const player = ref<Player | null>(null);
|
||||||
|
|
||||||
function renderXgPlayer() {
|
function renderXgPlayer() {
|
||||||
const url = 'https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/byted-player-videos/1.0.0/xgplayer-demo.mp4';
|
const url = 'https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/byted-player-videos/1.0.0/xgplayer-demo.mp4';
|
||||||
const player = new Player({
|
player.value = new Player({
|
||||||
el: domRef.value!,
|
el: domRef.value!,
|
||||||
url,
|
url,
|
||||||
playbackRate: [0.5, 0.75, 1, 1.5, 2]
|
playbackRate: [0.5, 0.75, 1, 1.5, 2]
|
||||||
});
|
});
|
||||||
return player;
|
}
|
||||||
|
function destroyXgPlayer() {
|
||||||
|
player.value?.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
renderXgPlayer();
|
renderXgPlayer();
|
||||||
});
|
});
|
||||||
|
onUnmounted(() => {
|
||||||
|
destroyXgPlayer();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
Loading…
Reference in New Issue
Block a user