ZZJ
2021-11-09 ccee429d379e0108b7445f72ade8d97c110a6fb3
src/Pool/TreeData.ts
@@ -5,13 +5,16 @@
  addAreaTreeData,
  delAreaTreeData,
  updateAreaTreeData,
  getGb28181Pool,
  refreshGB28181Tree,
  updateCameraArea
  updateCameraArea,
  getCameraBaseImage
} from '@/api/area'
import { findAllFile, show, changeEnable } from '@/api/localVedio'
export default class TreeDataPool {
  public openeds: Array<boolean>
  public activeTreeData: Array<object>
  public treeData: Array<object>
  public clusterData: Array<object>
  public gb28181Data: Array<object>
@@ -37,20 +40,6 @@
  public foldNodeList: object
  //记录左侧tab:activeName
  public treeActiveName: string
  //本地视频:视频分析处理
  public vedioAnaliyseSwitch: boolean
  //本地视频列表
  public localVedioList: Array<any>
  //本地视频当前页
  public localCurrentPage: number
  //本地视频每页查询20条
  public localPageSize: number
  //本地视频总条数
  public localTotal: number
  //勾选的本地视频
  public checkedLocalVedio: Array<any>
  //当前选中的本地视频
  public clickLocalVideo: object
  //控制开始、暂停按钮显示状态
  public btnStaus: string
  //本地视频类型
@@ -60,8 +49,24 @@
  //记录复制的摄像机name
  public ctrlCameraName: string
  // 是否使用ztree
  public zTree: boolean
  public checkedTreeNode: Array<object>
  // 选中的摄像机个数
  public gb28181CheckedCount: number
  // 总摄像机个数
  public gb28181ChildNodeCount: number
  // 国标摄像机池的底图
  public cameraNameForBaseImage: string
  public gb28181CameraBaseImage: string
  public baseImageLoading: boolean
  constructor() {
    this.openeds = [true, true, false]
    this.activeTreeData = []
    this.treeData = []
    this.gb28181Data = []
    this.clusterData = []
@@ -82,19 +87,21 @@
    this.selectedNode = {}
    this.treeType = ''
    this.foldNodeList = {}
    this.vedioAnaliyseSwitch = false
    this.treeActiveName = 'camera'
    this.searchLocalType = 0
    this.localVedioList = []
    this.checkedLocalVedio = []
    this.clickLocalVideo = {}
    //1:暂停状态;2:等待状态;3:置灰
    this.btnStaus = '3'
    this.localCurrentPage = 1
    this.localPageSize = 20
    this.localTotal = 0
    this.ctrlCameraId = ''
    this.ctrlCameraName = ''
    this.zTree = false
    this.checkedTreeNode = []
    this.gb28181CheckedCount = 0
    this.gb28181ChildNodeCount = 0
    this.cameraNameForBaseImage = ""
    this.gb28181CameraBaseImage = ""
    this.baseImageLoading = false
  }
  setVideoArr(index: number, value: object, vue: any): void {
@@ -109,7 +116,6 @@
      return
    }
    let _selected = this.selectedNodes
    console.log(this.selectedNodes)
    function nodeFilter(node: any) {
      if (node.type === '4' && node.selected) {
        _selected.push(node.id)
@@ -143,6 +149,30 @@
    //     nodeFilter(n);
    //   });
    // }
  }
  updateZTreeCheckNodes(checkedNodes) {
    let _this = this
    _this.selectedNodes = []
    if (!_this.multiple) {
      _this.selectedNodes = [checkedNodes.id]
      return
    }
    function nodeFilter(node: any) {
      if (node.type === '4' && (node.selected || node.checked)) {
        _this.selectedNodes.push(node.id)
      }
      if (node.children) {
        node.children.forEach((n: any) => {
          nodeFilter(n)
        })
      }
    }
    checkedNodes.forEach((n: any) => {
      nodeFilter(n)
    })
  }
  getCameraInfoByIp(ipaddr) {
@@ -235,8 +265,6 @@
    this.isFold(this.gb28181Data)
    this.selectedNodes = []
    this.selectedNode = {}
    this.cleanLocalVedio()
  }
  cleanTree(tree) {
@@ -253,8 +281,13 @@
      return
    }
    node.forEach(n => {
      // vue-js-tree 默认展开,控制部分折叠. z-tree 默认折叠, 控制部分展开
      if (this.foldNodeList[n.id]) {
        n.opened = false
        if (this.zTree) {
          n.open = false
        } else {
          n.opened = false
        }
      }
      if (n.children && n.children.length > 0) {
        this.isFold(n.children)
@@ -281,7 +314,7 @@
    if (!node) {
      return
    }
    node.sort(function(obj1: any, obj2: any) {
    node.sort(function (obj1: any, obj2: any) {
      var val1 = obj1.name
      var val2 = obj2.name
      if (val1 < val2) {
@@ -295,6 +328,9 @@
    node.forEach(n => {
      if (n.children && n.children.length > 0) {
        if (this.zTree) {
          n.open = true
        }
        this.sortTreeData(n.children)
      }
    })
@@ -323,14 +359,13 @@
      this.isFold(this.treeData)
    }
  }
  async fetchClusterTree() {
    const rsp: any = await getClusterTree({
      searchType: this.searchCamType,
      cameraName: this.searchInput
    })
    if (rsp && rsp.success) {
      console.log(rsp.data)
      this.clusterData = rsp.data ? rsp.data : []
      if (this.clusterData && this.clusterData.length > 0) {
        this.sortTreeData(this.clusterData)
@@ -364,8 +399,6 @@
    if (this.openeds[1]) {
      this.fetchGbTree()
    }
    this.findAllFile({})
  }
  async add(name: string, parent: string) {
@@ -401,109 +434,106 @@
    // this.fetchGbTree()
  }
  async findAllFile(params: any) {
    ;(params.fileName = this.searchInput), (params.type = this.searchLocalType)
    params.page = this.localCurrentPage
    params.size = this.localPageSize
    let res: any = await findAllFile(params)
    if (res && res.success) {
      let list = res.data.dataList.map(i => {
        let obj: any = {}
        Object.assign(obj, i)
        if (i.ruleType == 0) {
          obj.iconStatus2 = '0'
        } else {
          obj.iconStatus2 = '1'
        }
        if (!i.snapshot_url) {
          // obj.snapshot_url = require('@/assets/nobody.png')
          obj.snapshot_url = ''
        } else {
          obj.snapshot_url = '/httpImage/' + obj.snapshot_url
        }
        if (i.is_running) {
          obj.iconStatus1 = '1'
        } else if (i.progress == 100) {
          obj.iconStatus1 = '2'
        } else if (i.status == 1 && i.progress == 0 && i.hasRule) {
          obj.iconStatus1 = '3'
        } else if (!i.hasRule && i.progress == 0) {
          obj.iconStatus1 = '4'
        }
        obj.checkStatus = false
        obj.clickStatus = false
        obj.showCheckBox = false
        return obj
      })
      this.localVedioList = list
      this.localTotal = res.data.total
      // console.log(this.localVedioList,this.searchInput,'本地视频列表')
    }
  }
  async show() {
    let res: any = await show()
    if (res && res.success) {
      this.vedioAnaliyseSwitch = res.data.videoEnable
    }
  }
  async changeEnable() {
    let res: any = await changeEnable({
      enable: this.vedioAnaliyseSwitch
    })
  }
  getCheckedFiles() {
    this.checkedLocalVedio = this.localVedioList.filter(i => {
      return i.checkStatus
    })
    this.clickLocalVideo = this.localVedioList.filter(i => {
      return i.clickStatus
    })[0]
    if (this.checkedLocalVedio.length === 0) {
      this.btnStaus = '3'
      return false
    }
    this.checkedLocalVedio.every((i, index) => {
      let t = ''
      if (i.status == 0 && i.hasRule) {
        t = '1'
      } else if (i.status == 1 && i.hasRule && !i.is_running) {
        t = '2'
      } else {
        t = '3'
      }
      if (index == 0) {
        this.btnStaus = t
      } else {
        if (this.btnStaus !== t) {
          this.btnStaus = '3'
          return false
        }
      }
    })
  }
  filterLocalVideoWell() {
    if (this.localVedioList.length !== 0) {
      this.localVedioList = this.localVedioList.filter(i => {
        return i.progress == 100
      })
    }
  }
  cleanLocalVedio() {
    this.localVedioList.map(i => {
      i.checkStatus = false
      i.clickStatus = false
    })
    this.checkedLocalVedio = []
    this.btnStaus = '3'
  }
  async dropNode(cameraId, areaId) {
  async dropNode(cameraId: string, areaId: string) {
    await updateCameraArea({ cameraId: cameraId, areaId: areaId })
  }
  getAllChildrenNodes(treeNode, arr) {
    for (var i = 0; i < treeNode.length; i++) {
      var sonList = treeNode[i].children;
      if (!sonList) {
        if (treeNode[i].type == "camera") {
          arr.push(treeNode[i]);
          if (treeNode[i].checked) {
            this.gb28181CheckedCount += 1;
          }
        }
      } else {
        this.getAllChildrenNodes(sonList, arr);
      }
    }
    return arr;
  }
  countChildrenNodes(treeNode) {
    let arry = []
    this.getAllChildrenNodes(treeNode, arry)
    return arry.length
  }
  async fetchVideosvrCameras(update: Boolean) {
    let fn = getGb28181Pool
    if (update) {
      fn = refreshGB28181Tree
    }
    const rsp: any = await fn()
    if (rsp && rsp.success) {
      this.selectedNode = {}
      this.treeData = rsp.data ? rsp.data : []
      if (this.treeData && this.treeData.length > 0) {
        this.sortTreeData(this.treeData)
      }
      // 设置禁止拖拽摄像机到摄像机节点
      this.setDropDisable(this.treeData)
      this.isFold(this.treeData)
      this.activeTreeData = this.treeData
      this.gb28181CheckedCount = 0;
      this.gb28181ChildNodeCount = this.countChildrenNodes(this.treeData)
    }
  }
  removeNoCheckedNode(nodes: Array<any>) {
    for (let i = 0; i < nodes.length;) {
      if (!nodes[i].checked) {
        nodes.splice(i, 1)
        continue
      }
      if (nodes[i].children && nodes[i].children.length) {
        this.removeNoCheckedNode(nodes[i].children)
      }
      i++
    }
  }
  countCheckedNodes(nodes: Array<any>) {
    let count = 0
    nodes.forEach(n => {
      if (n.type == "camera") {
        count++
      }
    })
    this.gb28181CheckedCount = count
  }
  newTreeByChecked(nodes: Array<object>) {
    let newTree = JSON.parse(JSON.stringify(nodes))
    this.removeNoCheckedNode(newTree)
    return newTree
  }
  async showBaseImage(node: any) {
    this.baseImageLoading = true
    this.gb28181CameraBaseImage = ""
    this.cameraNameForBaseImage = node.name
    try {
      const rsp: any = await getCameraBaseImage({ id: node.id })
      if (rsp && rsp.data) {
        this.gb28181CameraBaseImage = rsp.data
      }
    } catch (error) {
      console.log(error)
    }
    this.baseImageLoading = false
  }
}