wws před 1 rokem
rodič
revize
17805c9ecc

+ 4 - 4
src/components/small-video/SmallVideo.vue

@@ -1,6 +1,6 @@
 <script>
 import Player from "@/utils/Player";
-import {WebViewBridge} from "@polyv/web-view-bridge";
+// import {WebViewBridge} from "@polyv/web-view-bridge";
 
 export default {
   name: "SmallVideo",
@@ -14,7 +14,7 @@ export default {
   }
   },
   mounted() {
-    // this.handleInitPlayer();
+    this.handleInitPlayer();
   },
   methods: {
     // 初始化播放器
@@ -32,7 +32,7 @@ export default {
       this.width = smallVideo.clientWidth;
       this.height = smallVideo.clientHeight;
       console.log("playerInstance", this.playerInstance)
-      this.webviewBridge = new WebViewBridge();
+      // this.webviewBridge = new WebViewBridge();
     },
 
 
@@ -65,7 +65,7 @@ export default {
          :id="playerInstance?.playerId"></div>
 
 
-    <div class="close-btn" @click="handleExitSmallWindow">关闭小窗</div>
+<!--    <div class="close-btn" @click="handleExitSmallWindow">关闭小窗</div>-->
   </div>
 </template>
 

+ 103 - 0
src/components/small-win/SmallWin.vue

@@ -0,0 +1,103 @@
+<script>
+import {WebViewBridge} from "@polyv/web-view-bridge";
+
+export default {
+  name: "SmallWin",
+  props: {
+    open: {
+      type: Boolean,
+      default: false,
+    }
+  },
+  data() {
+    return {
+      // 小窗
+      showSmallWin: false,
+      webviewBridge: null,
+    }
+  },
+  mounted() {
+    this.webviewBridge = new WebViewBridge();
+
+    //初始化
+    // webview 被小窗化
+    this.webviewBridge.on('changeToSmall', (event) => {
+      console.log("event:changeToSmall:", event)
+    });
+
+    // webview 取消小窗化
+    this.webviewBridge.on('changeToNormal', (event) => {
+      console.log("event:changeToNormal:", event)
+      this.showSmallWin = false;
+    });
+
+    // 关闭页面
+    this.webviewBridge.on('callWebViewEvent', (event) => {
+      console.log("event:callWebViewEvent:", event)
+      this.showSmallWin = false;
+    });
+
+  },
+  methods: {
+    // 打开小窗
+    handleSmallWindow() {
+      this.showSmallWin = true;
+      this.webviewBridge?.sendData('clickProduct', {
+        newPage: false,
+        ...{width: 375, height: 180,}
+      });
+    },
+
+    // 退出小窗
+    handleExitSmallWindow() {
+      this.webviewBridge?.sendData('changeToNormal', {});
+      this.showSmallWin = false;
+    },
+  }
+}
+</script>
+
+<template>
+  <div class="small-window" :class="{'fixed': showSmallWin}">
+    <!-- 小窗内容  -->
+    <slot :show="showSmallWin"></slot>
+
+    <!--  互动层  -->
+    <div class="interact-box" v-if="showSmallWin">
+      <img src="@/assets/close.png" class="close-icon" @click="handleExitSmallWindow" />
+    </div>
+  </div>
+</template>
+
+<style scoped>
+
+.small-window {
+  width: 375px;
+  height: 180px;
+}
+
+.interact-box {
+  position: absolute;
+  top: 0;
+  left: 0;
+  z-index: 9999;
+  width: 100%;
+  height: 100%;
+}
+
+.close-icon {
+  width: 28px;
+  height: 28px;
+}
+
+.fixed {
+  width: 100%;
+  height: 180px;
+  position: fixed;
+  top: 0;
+  left: 0;
+  z-index: 9999;
+  overflow: hidden;
+}
+
+</style>

+ 20 - 49
src/views/live/LiveItem.vue

@@ -2,20 +2,17 @@
 import LiveInteract from "@/components/live/LiveInteract.vue";
 import LiveVideo from "@/components/live-video/LiveVideo.vue";
 import Live from "@/utils/Live";
-import {WebViewBridge} from "@polyv/web-view-bridge";
+import SmallWin from "@/components/small-win/SmallWin.vue";
 
 export default {
   name: "LiveItem",
-  components: {LiveVideo, LiveInteract},
+  components: {SmallWin, LiveVideo, LiveInteract},
   data() {
     return {
       fullScreen: false,
       // 直播实例
       liveInstance: null,
 
-      // 小窗
-      showSmallWin: false,
-      webviewBridge: null,
     }
   },
   mounted() {
@@ -26,27 +23,20 @@ export default {
       // 测试获取公告
 
     });
-
-    this.webviewBridge = new WebViewBridge();
   },
   methods: {
-    handleClick() {
-      console.log("测试点击")
-      this.fullScreen = true
-    },
-
     handleSmallWindow() {
-      console.log('出发')
-      this.showSmallWin = true;
-      this.webviewBridge?.sendData('clickProduct', {
-        newPage: false,
-        ...{width: 375, height: 180,}
-      });
-    },
-
-    handleExitSmallWindow() {
-      this.webviewBridge?.sendData('changeToNormal', {});
-      this.showSmallWin = false;
+      this.fullScreen = false;
+      if(this.fullScreen) {
+        this.fullScreen = false;
+        this.$refs.interact.isLandscape = false;
+        // 全屏下需要延迟一下
+        setTimeout(() => {
+          this.$refs.smallWin.handleSmallWindow();
+        }, 300)
+        return;
+      }
+      this.$refs.smallWin.handleSmallWindow();
     },
   }
 }
@@ -55,12 +45,12 @@ export default {
 <template>
   <div class="live-item">
     <div class="live-video-box">
-      <div class="video-box" :class="{'full-video-box': fullScreen, 'small-win':showSmallWin}">
-        <live-video>
-          <div id="livePlayer"></div>
-        </live-video>
-
-        <div class="close-btn" @click="handleExitSmallWindow" v-if="showSmallWin">关闭小窗</div>
+      <div class="video-box" :class="{'full-video-box': fullScreen}">
+        <small-win ref="smallWin">
+          <live-video>
+            <div id="livePlayer"></div>
+          </live-video>
+        </small-win>
       </div>
       <div class="video-tip">
         市场有风险 投资需谨慎
@@ -69,6 +59,7 @@ export default {
     </div>
 
     <live-interact
+        ref="interact"
         @smallWin="handleSmallWindow"
         :liveInstance="liveInstance"
         class="interact1"
@@ -135,24 +126,4 @@ export default {
   transform: rotate(90deg);
   background: #000000;
 }
-
-.small-win {
-  position: fixed;
-  top: 0;
-  left: 0;
-  z-index: 9999;
-}
-
-.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;
-}
-
 </style>

+ 67 - 7
src/views/test-small/TestSmall.vue

@@ -1,18 +1,36 @@
 <script>
-import SmallVideo from "@/components/small-video/SmallVideo.vue";
+import SmallWin from "@/components/small-win/SmallWin.vue";
+import Player from "@/utils/Player";
 
 export default {
   name: "TestSmall",
-  components: {SmallVideo},
+  components: {SmallWin},
   data() {
     return {
       showBtn: true,
+      playerInstance: null,
+      width: 0,
+      height: 0,
     }
   },
+  mounted() {
+    this.handleInitPlayer();
+  },
   methods: {
-    handlePlay() {
-      this.showBtn = false;
-      this.$refs.small.handleSmallWindow();
+    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)
     },
     handleClose() {
       this.showBtn = true;
@@ -23,10 +41,52 @@ export default {
 
 <template>
   <div class="test-wrapper">
-    <small-video ref="small" @exit="handleClose" />
-    <button @click="handlePlay" v-show="showBtn">打开小窗</button>
+    <button @click="$refs.smallWin.handleSmallWindow()">打开小窗</button>
+    <div class="content" v-for="item in 7" :key="item">内容{{item}}</div>
+    <small-win ref="smallWin">
+      <div class="small-video">
+        <div class="video-container"
+             :style="{'--width': width + 'px', '--height': height + 'px'}"
+             :id="playerInstance?.playerId"></div>
+      </div>
+
+    </small-win>
   </div>
 </template>
 
 <style scoped>
+
+.content {
+  width: 100%;
+  height: 100px;
+}
+
+
+.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;
+}
+
 </style>

+ 10 - 6
src/views/video/VideoItem.vue

@@ -4,10 +4,11 @@ import ProgressLine from "@/components/progress/ProgressLine.vue";
 import VideoSetPopup from "@/components/set-popup/VideoSetPopup.vue";
 import PolyvPlayer from "@/components/video-container/PolyvPlayer.vue";
 import Player from "@/utils/Player";
+import SmallWin from "@/components/small-win/SmallWin.vue";
 
 export default {
   name: "VideoItem",
-  components: {PolyvPlayer, VideoSetPopup, ProgressLine, VideoInfo},
+  components: {SmallWin, PolyvPlayer, VideoSetPopup, ProgressLine, VideoInfo},
   props: {
     currentIndex: {
       type: Number,
@@ -94,15 +95,18 @@ export default {
     <div class="header">
       <div class="left"></div>
       <div class="header-right">
-        <img src="@/assets/fenestrule.png" class="header-icon" />
+        <img src="@/assets/fenestrule.png" class="header-icon" @click="$refs.smallWin.handleSmallWindow()" />
         <img src="@/assets/more.png" class="header-icon" @click="showSetPopup = true" />
       </div>
     </div>
 
-    <polyv-player
-        :playerInstance="playerInstance"
-        v-model="fullScreen"
-        ref="player" />
+    <small-win ref="smallWin">
+      <polyv-player
+          :playerInstance="playerInstance"
+          v-model="fullScreen"
+          ref="player" />
+    </small-win>
+
 
 
     <div class="footer" :style="{bottom: isIos ? '20px' : '0px'}" v-show="!fullScreen" safe-area-inset-bottom>