index.vue 3.12 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1 2
<template>

3 4 5
  <div class="app-container" style="">
    <div style="height: 100%;">
      <el-col style="border:1px solid #cccccc;height: 100%;" :span="4">
耿迪迪's avatar
耿迪迪 committed
6 7
        <el-tree :data="videoData" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
      </el-col>
8 9
      <el-col :span="20" style="height: 100%;">
        <div id="player"></div>
耿迪迪's avatar
耿迪迪 committed
10
      </el-col>
11
    </div>
耿迪迪's avatar
耿迪迪 committed
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 50 51 52 53 54 55 56 57 58 59 60 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
  </div>
</template>
<script>
import { getVideoTree } from "@/api/video/manager";
import { getPreviewURLs } from "@/api/video/artemis"
const IS_MOVE_DEVICE = document.body.clientWidth < 992 // 是否移动设备
const MSE_IS_SUPPORT = !!window.MediaSource // 是否支持mse
export default {
  name: "Video",
  components: {
  },
  data() {
    return {
      videoData: [],
      defaultProps: {
        children: 'childrenVideo',
        label: 'videoName'
      },
      queryParam: {
        cameraIndexCode: ""
      },
      player: null,
      videoOpenNum: -1,
      cameraIndexCode: ""
    }
  },
  created() {
    this.getVideoData();
  },
  methods: {
    getVideoData(){
      getVideoTree().then(response =>{
        this.videoData = response.data;
      })
    },
    handleNodeClick(data){
      if(this.cameraIndexCode == data.resourceId){
        return;
      }
      this.cameraIndexCode = data.resourceId;
      if(data.resourceId){
        this.queryParam.cameraIndexCode = data.resourceId;
        getPreviewURLs(this.queryParam).then(response =>{
            if(response.data.code == '0'){
                this.videoOpenNum++;
                let url = response.data.data.url;
                //let index = this.player.currentWindowIndex;
                this.player.JS_Play(url,{playURL: url, mode:"0" }, this.videoOpenNum%4).then(() => {
                  console.log('realplay success')
                },
                  e => { console.error(e) }
                )
            }
        });
      }
    },
    init() {
      // 设置播放容器的宽高并监听窗口大小变化
      window.addEventListener('resize', () => {
            this.player.JS_Resize()
      })
    },
    createPlayer() {
      this.player = new window.JSPlugin({
        szId: 'player',
        szBasePath: "/h5player",
        iMaxSplit: 4,
        iCurrentSplit: IS_MOVE_DEVICE ? 1 : 2,
        openDebug: true,
        oStyle: {
          borderSelect: IS_MOVE_DEVICE ? '#000' : '#FFCC00',
        }
      })
    },
    loadScript(src){
      return new Promise(reslove =>{
        let scpritE1 = document.createElement("script");
          scpritE1.type = "text/javascript";
          scpritE1.src = src;
          scpritE1.onload = () => {
          reslove();
        }
      document.body.appendChild(scpritE1);
    })
    }

  },
  mounted() {
    //this.$el.style.setProperty('display', 'block')
    if(!window.JSPlugin){
      this.loadScript("/h5player/h5player.min.js").then(() =>{
        this.createPlayer();
        this.init()
      })

    }else{
      this.createPlayer();
      this.init()
    }

  }
};
</script>
115 116 117 118 119 120 121 122 123 124 125 126
<style scoped lang="scss">
  .app-container{
    position:absolute;
    top:0;
    bottom:0;
    width: 100%;
  }
  #player{
     width: 100% ;
     height: 100% ;
  }
</style>