SplitVideoView.vue 2.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<template>
    <div class="video">
      <div style="height: 5%;padding: 6px;">
        <el-dropdown @command="handleCommand" trigger="click">
          <span class="el-dropdown-link">
            <img src="@/assets/images/spilt.png" alt="spilt" style="width: 18px;height: 18px">
            分屏设置
          </span>
          <el-dropdown-menu slot="dropdown" style="width:100px">
            <el-dropdown-item command="1">1x1 </el-dropdown-item>
            <el-dropdown-item command="4">2x2</el-dropdown-item>
            <el-dropdown-item command="9">3x3</el-dropdown-item>
            <el-dropdown-item command="16">4x4</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>

      <div style="height: 95%;width: 100%;" ref="playVideo">
        <div v-for="num in spiltNum" class="videoShow" :style="{'width': countWidth,'height':countHeight}" @click="changeVideo('play'+num,num)">
          <PlayVideo
            :playId="'play'+num"
            :isChoice="showVideoNum == num"
            :ref="'play'+num"
          >
          </PlayVideo>

        </div>
      </div>

    </div>
</template>

<script>
  import PlayVideo from "@/components/Video/PlayVideo"
    export default {
      name: "split-videoview",
      components:{
        PlayVideo
      },
      data(){
        return{
          spiltNum: 0,
          showVideoNum: 1,
          playId: "play1",
        }
      },
      mounted(){
        this.spiltNum = 4;
      },
50 51 52 53 54 55 56 57 58 59 60
      watch: {
        spiltNum(newVal, oldVal) {
          this.$nextTick(() => {
              /*现在数据已经渲染完毕*/
              for (var i = 1; i <= this.spiltNum; i++) {
              const playId = "play" + i;
              this.$refs[playId][0].fit();
            }
          });
        },
      },
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
      computed:{
        countWidth(){
          return (this.$refs.playVideo.offsetWidth-2)/Math.sqrt(this.spiltNum) + 'px';
        },
        countHeight(){
          return (this.$refs.playVideo.offsetHeight-2)/Math.sqrt(this.spiltNum) + 'px';
        }
      },
      methods:{
        changeVideo(playId,num){
          this.playId = playId;
          this.showVideoNum = num;
        },
        handleCommand(val){
          this.spiltNum = eval(val);
          this.playId = "play1";
          this.showVideoNum = 1;
        },
        playVideo(video){
          this.$refs[this.playId][0].playVideo(video);
        }
      }
    }
</script>

<style scoped lang="scss">
  .videoShow{
    float: left;
    padding: 6px;
  }
  .video{
    height: 100%;
    width: 100%;
    margin-left: 6px;
    float: left;
    background: #fff;
  }

</style>