HistoryPlayDialog.vue 4.35 KB
<template>
  <el-dialog
    :close-on-click-modal="true"
    :title="`${data.deviceId} 设备 - ${data.channelName} 历史视频回放`"
    :visible.sync="open"
    width="90%"
    center
    append-to-body
    @opened="onDialogOpened"
  >
    <el-container>
      <el-main style="display: flex;justify-content: center;align-items: center;background-color: #e9eef3;">
        <el-card class="box-card" shadow="always" :body-style="{ height: '100%', padding: '10px' }">
          <div class="main-play">
            <jess-video-player
              v-if="videoUrl"
              ref="histPlayer"
              :key="'hist-' + playSessionKey"
              class="hist-jess-player"
              :initial-play-url="videoUrl"
              :vod="true"
              :jessibuca-timeout="60"
              :ui-play-timeout-sec="45"
              :player-auto-resize="true"
            />
          </div>
        </el-card>
      </el-main>
    </el-container>
    <el-footer style="padding: 0;background-color: #2b2f33;">
      <TimeLine
        ref="time_line"
        @change="changeDate"
        :width="width"
        :mark-time="markTime"
        :time-range="time_range"
        :isAutoPlay="isAutoPlay"
        :startMeddleTime="startMeddleTime"
        @click="clickCanvas"
      />
    </el-footer>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import JessVideoPlayer from '../common/JessVideoPlayer.vue'
import TimeLine from './TimeLineCanvas.vue'

export default {
  name: 'HistoryPlayDialog',
  components: { TimeLine, JessVideoPlayer },
  data() {
    return {
      data: {},
      videoUrl: null,
      isAutoPlay: false,
      width: '100%',
      startMeddleTime: null,
      startTime: null,
      endTime: null,
      time_range: [],
      markTime: [],
      form: {
        code: '',
        startTime: '',
        endTime: ''
      },
      open: false,
      playSessionKey: 0
    }
  },
  watch: {
    data(val) {
      if (!val || !val.videoUrl) return
      this.playSessionKey += 1
      this.videoUrl = val.videoUrl
      this.startMeddleTime = val.startTime
      this.startTime = val.startTime
      this.endTime = val.endTime
      this.time_range = [val.startTime, val.endTime]
      this.markTime = [
        {
          beginTime: val.startTime,
          endTime: val.endTime,
          bgColor: 'green',
          text: '有视频'
        }
      ]
      this.form.startTime = this.startTime
      this.form.endTime = this.endTime
      this.$nextTick(() => {
        const p = this.$refs.histPlayer
        if (p && typeof p.tryResize === 'function') p.tryResize()
      })
    },
    videoUrl() {
      this.$nextTick(() => {
        const p = this.$refs.histPlayer
        if (p && typeof p.tryResize === 'function') p.tryResize()
      })
    }
  },
  methods: {
    onDialogOpened() {
      this.$nextTick(() => {
        const p = this.$refs.histPlayer
        if (p && typeof p.tryResize === 'function') p.tryResize()
      })
    },
    updateOpen(flag) {
      this.open = flag
    },
    clickCanvas(date) {
      const map = this.data.channelMapping != null ? String(this.data.channelMapping) : ''
      this.$axios({
        method: 'get',
        url: '/api/jt1078/query/send/request/io/history/' + this.data.sim + '/' + this.data.channel + '/' + this.data.startTime + '/' + date + '/' + encodeURIComponent(map)
      }).then(res => {
        if (res.data && res.data.data && res.data.data.data) {
          const d = res.data.data.data
          const videoUrl1 = location.protocol === 'https:'
            ? (d.wss_flv || d.ws_flv || d.flv)
            : (d.ws_flv || d.wss_flv || d.flv)
          if (videoUrl1) {
            this.playSessionKey += 1
            this.videoUrl = videoUrl1
          }
        } else if (res.data.data && res.data.data.msg) {
          this.$message.error(res.data.data.msg)
        } else if (res.data.msg) {
          this.$message.error(res.data.msg)
        }
      })
    },
    changeDate(date, status) {
      console.log('选择时间:' + date + '  播放状态:' + status)
    },
    handleClose() {
      this.open = false
    }
  }
}
</script>

<style scoped>
.main-play {
  width: 100%;
  height: 500px;
  background-color: #000000;
}

.hist-jess-player {
  width: 100%;
  height: 100%;
}

.box-card {
  width: 100%;
  max-width: 1280px;
}
</style>