Newer
Older
safe_production_front / src / views / ycjg / sjhf / index-isc.vue
wangxitong on 16 Aug 5 KB first commit
<script lang="ts" setup name="ResourceList">
import type { Ref } from 'vue'
import { getCurrentInstance, nextTick, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { videoTree } from '@/api/ycjg/aqbb'
import dayjs from "dayjs";
const router = useRouter()

const treeRef = ref(null)
const filterText = ref('')
const timeRange = ref<[any, any]>(['', ''])
// 默认查询条件
const defaultQuery = {
  id: '',
  startTime: '',
  endTime: '',
}
const listQuery = reactive({ ...defaultQuery })

const data = ref([])
//   id: 1,
//   name: '一级 1',
//   children: [{
//     id: 4,
//     name: '二级 1-1',
//     children: [{
//       id: 9,
//       name: '三级 1-1-1',
//     }, {
//       id: 10,
//       name: '三级 1-1-2',
//     }],
//   }],
// }, {
//   id: 2,
//   name: '一级 2',
//   children: [{
//     id: 5,
//     name: '二级 2-1',
//   }, {
//     id: 6,
//     name: '二级 2-2',
//   }],
// }, {
//   id: 3,
//   name: '一级 3',
//   children: [{
//     id: 7,
//     name: '二级 3-1',
//   }, {
//     id: 8,
//     name: '二级 3-2',
//   }],
// }])

const defaultProps = ref({
  children: 'children',
  label: 'name',
  isDisabled: 'disabled',
})

const { proxy } = getCurrentInstance() as any
const width = ref(0)
const height = ref(0)
const loading = ref(false)
const src = ref('')

const resize = () => {
  const divPlugin = document.getElementById('home')
  console.log(divPlugin)
  width.value = divPlugin.clientWidth - 20
  height.value = divPlugin.clientHeight - 60
}

function filterNode(value: any, data: { name: string | any[] }) {
  if (value === '' || value === null) {
    return true
  }
  return data.name.includes(value)
}

let treeClickCount = 0
const currentCameras = {}

function recordStart(type) {
  const codeMap = { MP4: 5, PS: 2 }
  let player = this.player,
    index = player.currentWindowIndex,
    fileName = `${moment().format('YYYYMMDDHHmm')}.mp4`
  typeCode = codeMap[type]

  player.JS_StartSaveEx(index, fileName, typeCode).then(
    () => { console.log('record start ...') },
    e => { console.error(e) }
  )
}

function recordStop() {
  let player = this.player
  index = player.currentWindowIndex

  player.JS_StopSave(index).then(
    () => { console.log('record stoped, saving ...') },
    e => { console.error(e) }
  )
}

function handleNodeClick(data: any, node: any, self: any) {
  const now = new Date().getTime()
  if (now - treeClickCount < 300) { // 双击事件的判断,300毫秒内重复点击
    console.log('Double click on:', data)
    if (data.hasOwnProperty('children')) { // 点击父亲
      return
    }
    src.value = data.url // todo 视频地址
    currentCameras = data
  }
  treeClickCount = now
}

const unwatch = watch(filterText, (newVal) => {
  treeRef.value.filter(newVal)
})

function search() {

}

// 搜索重置
function reset() {
  Object.assign(listQuery, defaultQuery)
  listQuery.startTime = dayjs(Date.now() - 7 * 24 * 60 * 60 * 1000).format('YYYY-MM-DD HH:mm:ss')
  listQuery.endTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
  listQuery.id = ''
  timeRange.value = [listQuery.startTime, listQuery.endTime]
  search()
}

onBeforeUnmount(() => {
  unwatch()
  window.removeEventListener('resize', resize)
})

onMounted(() => {
  videoTree().then((response) => {
    if (response.code === 200) {
      data.value = response.data
    }
  })
  resize()
  reset()
  window.addEventListener('resize', resize)
})
</script>

<template>
  <app-container style="height: calc(100vh - 110px)">
    <div style="display: flex;height: 100%">
      <el-card class="left">
        <el-input
          placeholder="设备名称过滤"
          v-model="filterText">
        </el-input>
        <el-tree
          ref="treeRef"
          class="filter-tree"
          style="width: 100%;height: 100%"
          :data="data"
          :filter-node-method="filterNode"
          node-key="id"
          :default-expand-all="true"
          :props="defaultProps"
          @node-click="handleNodeClick"/>
      </el-card>
      <div id="home" class="right">
        <div style="display:flex;">
          <search-area :need-clear="true" @search="search" @clear="reset" style="width: calc(100% - 268px)">
            <search-item>
              <el-date-picker
                v-model="timeRange"
                type="datetimerange"
                range-separator="到"
                format="YYYY-MM-DD HH:mm:ss"
                value-format="YYYY-MM-DD HH:mm:ss"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                style="width: 450px;"
                :clearable="false"
              />
            </search-item>
          </search-area>
          <div style="position: absolute;right: 20px;top: 22px">
            <el-button type="primary" @click="recordStart('MP4')" plain>录制MP4</el-button>
            <el-button @click="recordStop" type="info" plain>停止录制并保存文件</el-button>
          </div>
        </div>
        <div id="player"></div>
        <video id="video0" :src="src" autoPlay :width="width" :height="height" style="margin: 0 10px"/>
      </div>
    </div>
  </app-container>
</template>

<style lang="scss" scoped>
.left {
  width: 300px;
  height: 100%;
  padding: 10px;
  overflow-y: scroll;
}
.right {
  width: calc(100% - 310px);
  margin-left: 10px;
  background-color: white;
}
.video-container {
  display: flex;
  flex: 1;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  margin-bottom: 5px;
}
video {
  position: relative;
  object-fit: fill;
  overflow: hidden;
  background: #000;
}
</style>