|
|
@@ -1,12 +1,17 @@
|
|
|
<script>
|
|
|
import {WebViewBridge} from '@polyv/web-view-bridge';
|
|
|
+import Player from "@/utils/Player";
|
|
|
|
|
|
export default {
|
|
|
name: "TestPage",
|
|
|
data() {
|
|
|
return {
|
|
|
muted: true,
|
|
|
- webviewBridge: null
|
|
|
+ playerInstance: null,
|
|
|
+ width: 0,
|
|
|
+ height: 0,
|
|
|
+ showSmallWindow: false,
|
|
|
+ webviewBridge: null,
|
|
|
}
|
|
|
},
|
|
|
async mounted() {
|
|
|
@@ -15,31 +20,28 @@ export default {
|
|
|
}, 1000)
|
|
|
|
|
|
this.webviewBridge = new WebViewBridge();
|
|
|
-
|
|
|
- console.log("webviewBridge", this.webviewBridge)
|
|
|
-
|
|
|
-
|
|
|
- //初始化
|
|
|
- await this.webviewBridge.connectWebViewBridge();
|
|
|
- // webview 被小窗化
|
|
|
- this.webviewBridge.on('changeToSmall', (event) => {
|
|
|
- console.log("event:changeToSmall:", event)
|
|
|
- });
|
|
|
-
|
|
|
- // webview 取消小窗化
|
|
|
- this.webviewBridge.on('changeToNormal', (event) => {
|
|
|
- console.log("event:changeToNormal:", event)
|
|
|
- });
|
|
|
-
|
|
|
- this.webviewBridge.on('callWebViewEvent', (event) => {
|
|
|
- console.log("event:callWebViewEvent:", event)
|
|
|
- });
|
|
|
+ this.handleInitPlayer();
|
|
|
},
|
|
|
methods: {
|
|
|
- handlePlay() {
|
|
|
- this.$refs.video.play();
|
|
|
+ // 初始化播放器
|
|
|
+ handleInitPlayer() {
|
|
|
+ this.playerInstance = new Player();
|
|
|
+ this.$nextTick(async () => {
|
|
|
+ await this.playerInstance.loadPlayerScript();
|
|
|
+ this.playerInstance.loadPlayer();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.playerInstance.play();
|
|
|
+ }, 1000)
|
|
|
+ })
|
|
|
+
|
|
|
+ const smallVideo = document.querySelector(".small-video");
|
|
|
+ this.width = smallVideo.clientWidth;
|
|
|
+ this.height = smallVideo.clientHeight;
|
|
|
+ console.log("playerInstance", this.playerInstance)
|
|
|
},
|
|
|
+
|
|
|
handleSmallWindow() {
|
|
|
+ this.showSmallWindow = true;
|
|
|
this.webviewBridge?.sendData('clickProduct', {
|
|
|
newPage: false,
|
|
|
...{width: 375, height: 180,}
|
|
|
@@ -48,6 +50,7 @@ export default {
|
|
|
|
|
|
handleExitSmallWindow() {
|
|
|
this.webviewBridge?.sendData('changeToNormal', {});
|
|
|
+ this.showSmallWindow = false;
|
|
|
},
|
|
|
|
|
|
|
|
|
@@ -59,24 +62,59 @@ export default {
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
- <div
|
|
|
- style="display: flex; align-items: center; justify-content: center;flex-direction: column;width:100vw;height: 100vh;">
|
|
|
- <div @click="handleSmallWindow" style="height: 48px">进入小窗</div>
|
|
|
- <div @click="handleExitSmallWindow" style="height: 48px">退出小窗</div>
|
|
|
- <div @click="handleCloseWindow" style="height: 48px">关闭页面</div>
|
|
|
+ <div>
|
|
|
+ <button @click="handleSmallWindow">打开小窗</button>
|
|
|
+ <div class="content">内容</div>
|
|
|
+ <div class="small-video" :class="{'small-win': showSmallWindow}">
|
|
|
+ <div class="video-container"
|
|
|
+ :style="{'--width': width + 'px', '--height': height + 'px'}"
|
|
|
+ :id="playerInstance?.playerId"></div>
|
|
|
+
|
|
|
+
|
|
|
+ <div class="close-btn" @click="handleExitSmallWindow" v-show="showSmallWindow">关闭小窗</div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
-.icon {
|
|
|
- width: 28px;
|
|
|
- height: 28px;
|
|
|
+.content {
|
|
|
+ width: 100%;
|
|
|
+ height: 500px;
|
|
|
+}
|
|
|
+
|
|
|
+.small-video {
|
|
|
+ width: 100%;
|
|
|
+ height: 180px;
|
|
|
+}
|
|
|
+
|
|
|
+.video-container {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+}
|
|
|
+
|
|
|
+/deep/ .plv-player-container {
|
|
|
+ width: var(--width);
|
|
|
+ height: var(--height);
|
|
|
+}
|
|
|
+
|
|
|
+.close-btn {
|
|
|
+ position: absolute;
|
|
|
+ right: 0;
|
|
|
+ top: 0;
|
|
|
+ z-index: 9999;
|
|
|
+ box-sizing: border-box;
|
|
|
+ padding: 8px 12px;
|
|
|
+ border-radius: 8px;
|
|
|
+ color: #FFFFFF;
|
|
|
+ background: #000000;
|
|
|
}
|
|
|
|
|
|
-.video {
|
|
|
- width: 100vw;
|
|
|
- height: 300px;
|
|
|
+.small-win {
|
|
|
+ position: fixed;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ z-index: 99999;
|
|
|
}
|
|
|
|
|
|
</style>
|