wws преди 1 година
родител
ревизия
e4f1758360

+ 2 - 47
src/components/live-header/LiveHeader.vue

@@ -1,11 +1,9 @@
 <script>
 import LiveNotice from "@/components/notcie/LiveNotice.vue";
-import TestSmallWin from "@/components/test-small-win/TestSmallWin.vue";
-// import {WebViewBridge} from "@polyv/web-view-bridge";
 
 export default {
   name: "LiveHeader",
-  components: {TestSmallWin, LiveNotice},
+  components: {LiveNotice},
   props: {
     // 是否全屏
     isFullScreen: {
@@ -19,47 +17,6 @@ export default {
       show: false,
     }
   },
-  async mounted() {
-    /*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)
-    });*/
-  },
-  methods: {
-    // 进入小窗
-    handleSmallWindow() {
-      this.webviewBridge?.sendData('clickProduct', {
-        newPage: false,
-        ...{width: 375, height: 180,}
-      });
-    },
-
-    // 退出小窗
-    handleExitSmallWindow() {
-      this.webviewBridge?.sendData('changeToNormal', {});
-    },
-
-    // 关闭页面
-    handleCloseWindow() {
-      this.webviewBridge?.sendData('closeWindow', {});
-    }
-  },
   computed: {
     headerClass() {
       return this.isFullScreen ? 'horiz' : "vertical"
@@ -84,7 +41,7 @@ export default {
       </div>
 
       <div class="header-r">
-        <img src="@/assets/fenestrule.png" class="header-r-icon" @click="show = true" />
+        <img src="@/assets/fenestrule.png" class="header-r-icon" @click="$emit('smallWin')" />
         <img src="@/assets/more.png" class="header-r-icon" />
       </div>
     </div>
@@ -96,8 +53,6 @@ export default {
       <img src="@/assets/undulate.png" class="undulate-icon" />
       <span>直播中</span>
     </div>
-
-    <test-small-win :show="show"/>
   </div>
 </template>
 

+ 1 - 0
src/components/live-header/css/vertical.scss

@@ -10,6 +10,7 @@
     }
 
     .header-l {
+        flex-shrink: 0;
         display: flex;
         align-items: center;
     }

+ 1 - 1
src/components/live/LiveInteract.vue

@@ -204,7 +204,7 @@ export default {
       </van-swipe-item>
       <van-swipe-item @click="handleClickSwiperItem">
         <div class="interact-box">
-          <live-header @back="handleClickBack" :is-full-screen="isLandscape" :noticeContent="noticeContent" />
+          <live-header @back="handleClickBack" :is-full-screen="isLandscape" :noticeContent="noticeContent" v-on="$listeners" />
           <div class="footer">
             <chat-wrapper :list="chatList" v-show="!isLandscape" />
             <live-footer

+ 60 - 27
src/components/small-video/SmallVideo.vue

@@ -1,5 +1,6 @@
 <script>
 import Player from "@/utils/Player";
+import {WebViewBridge} from "@polyv/web-view-bridge";
 
 export default {
   name: "SmallVideo",
@@ -7,37 +8,64 @@ export default {
     return {
       playerInstance: null,
       width: 0,
-      height: 0
-    }
+      height: 0,
+      showSmallWindow: false,
+      webviewBridge: null,
+  }
+  },
+  mounted() {
+    // this.handleInitPlayer();
   },
-  async mounted() {
-    this.playerInstance = new Player();
-    this.$nextTick( async() => {
-      await this.playerInstance.loadPlayerScript();
-      this.playerInstance.loadPlayer();
-      setTimeout(() => {
-        this.playerInstance.play();
-      }, 1000)
-    })
+  methods: {
+    // 初始化播放器
+    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)
+      this.webviewBridge = new WebViewBridge();
+    },
 
-    const smallVideo = document.querySelector(".small-video");
-    this.width = smallVideo.clientWidth;
-    this.height = smallVideo.clientHeight;
-    console.log("playerInstance", this.playerInstance)
+
+    //  进入小窗
+    handleSmallWindow() {
+      this.showSmallWindow = true;
+      this.$nextTick(() => {
+        this.handleInitPlayer();
+        this.webviewBridge?.sendData('clickProduct', {
+          newPage: false,
+          ...{width: 375, height: 180,}
+        });
+      })
+    },
+
+    // 退出小窗
+    handleExitSmallWindow() {
+      this.webviewBridge?.sendData('changeToNormal', {});
+      this.showSmallWindow = false;
+      this.$emit("exit");
+    },
   }
 }
 </script>
 
 <template>
-  <div class="small-video">
+  <div class="small-video" v-show="showSmallWindow">
     <div class="video-container"
          :style="{'--width': width + 'px', '--height': height + 'px'}"
          :id="playerInstance?.playerId"></div>
 
-    <div class="mask-box">
-
-    </div>
 
+    <div class="close-btn" @click="handleExitSmallWindow">关闭小窗</div>
   </div>
 </template>
 
@@ -45,14 +73,16 @@ export default {
 
 .small-video {
   width: 100%;
-  height: 100%;
-  position: relative;
+  height: 180px;
+  position: fixed;
+  left: 0;
+  top: 0;
+  z-index: 9999;
 }
 
 .video-container {
   width: 100%;
   height: 100%;
-  //background: pink;
 }
 
 /deep/ .plv-player-container {
@@ -60,13 +90,16 @@ export default {
   height: var(--height);
 }
 
-.mask-box {
+.close-btn {
   position: absolute;
-  top: 0;
-  bottom: 0;
-  left: 0;
   right: 0;
-  background: transparent;
+  top: 0;
+  z-index: 9999;
+  box-sizing: border-box;
+  padding: 8px 12px;
+  border-radius: 8px;
+  color: #FFFFFF;
+  background: #000000;
 }
 
 </style>

+ 1 - 6
src/router/index.js

@@ -4,10 +4,6 @@ import VueRouter from 'vue-router'
 Vue.use(VueRouter)
 
 const routes = [
-  // {
-  //   path: '/video',
-  //   component: () => import( '../views/video/VideoItem.vue')
-  // },
   {
     // path: '/live',
     path: '/',
@@ -26,8 +22,7 @@ const routes = [
     component: () => import( '../views/feed/FeedList.vue')
   },
   {
-    path: '/test-small',
-    // path: '/',
+    path: '/test',
     name: "测试小窗",
     component: () => import( '../views/test-small/TestSmall.vue')
   },

+ 54 - 6
src/views/live/LiveItem.vue

@@ -2,6 +2,7 @@
 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";
 
 export default {
   name: "LiveItem",
@@ -10,7 +11,11 @@ export default {
     return {
       fullScreen: false,
       // 直播实例
-      liveInstance: null
+      liveInstance: null,
+
+      // 小窗
+      showSmallWin: false,
+      webviewBridge: null,
     }
   },
   mounted() {
@@ -21,12 +26,28 @@ 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;
+    },
   }
 }
 </script>
@@ -34,10 +55,12 @@ export default {
 <template>
   <div class="live-item">
     <div class="live-video-box">
-      <div class="video-box" :class="{'full-video-box': fullScreen}">
+      <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>
       <div class="video-tip">
         市场有风险 投资需谨慎
@@ -45,7 +68,12 @@ export default {
       <img src="@/assets/live/live-full.png" class="full-icon" @click="fullScreen = true" />
     </div>
 
-    <live-interact :liveInstance="liveInstance" class="interact1" v-model="fullScreen"  style="flex: 1" />
+    <live-interact
+        @smallWin="handleSmallWindow"
+        :liveInstance="liveInstance"
+        class="interact1"
+        v-model="fullScreen"
+        style="flex: 1" />
   </div>
 </template>
 
@@ -54,7 +82,8 @@ export default {
 .live-item {
   width: 100vw;
   height: 100vh;
-  background: transparent;
+  /*background: transparent;*/
+  background: rgba(0, 0, 0, 0.2);
   display: flex;
   flex-direction: column;
 }
@@ -93,6 +122,7 @@ export default {
 .video-box {
   transition: all 0.3s;
   background: #000000;
+  position: relative;
 }
 
 .full-video-box {
@@ -102,9 +132,27 @@ export default {
   top: calc(50% - 50vw);
   left: calc(50% - 50vh);
   z-index: 10;
-  //background: transparent;
   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>

+ 17 - 16
src/views/test-small/TestSmall.vue

@@ -3,29 +3,30 @@ import SmallVideo from "@/components/small-video/SmallVideo.vue";
 
 export default {
   name: "TestSmall",
-  components: {SmallVideo}
+  components: {SmallVideo},
+  data() {
+    return {
+      showBtn: true,
+    }
+  },
+  methods: {
+    handlePlay() {
+      this.showBtn = false;
+      this.$refs.small.handleSmallWindow();
+    },
+    handleClose() {
+      this.showBtn = true;
+    }
+  }
 }
 </script>
 
 <template>
   <div class="test-wrapper">
-
-    <div class="test">
-      <small-video />
-    </div>
-
+    <small-video ref="small" @exit="handleClose" />
+    <button @click="handlePlay" v-show="showBtn">打开小窗</button>
   </div>
 </template>
 
 <style scoped>
-
-.test-wrapper {
-
-}
-
-.test {
-  width: 100vw;
-  height: 200px;
-}
-
 </style>

+ 71 - 33
src/views/test/Test1.vue

@@ -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>