import {
|
getLocalCameraTree,
|
getGB28181CameraTree,
|
getClusterTree,
|
addAreaTreeData,
|
delAreaTreeData,
|
updateAreaTreeData,
|
refreshGB28181Tree,
|
updateCameraArea
|
} from '@/api/area'
|
import { findAllFile, show, changeEnable } from '@/api/localVedio'
|
|
export default class TreeDataPool {
|
public openeds: Array<boolean>
|
public treeData: Array<object>
|
public clusterData: Array<object>
|
public gb28181Data: Array<object>
|
public treeDataPure: Array<object>
|
public gb28181DataPure: Array<object>
|
public clusterDataPure: Array<object>
|
public videoArr: Array<string | undefined | object>
|
public searchCamType: number
|
public searchInput: string
|
public activeVideoIndex: number | string
|
public activeVideoId: number | string
|
public activeForceChoose: boolean
|
public readonly: boolean
|
public gbReadonly: boolean
|
public multiple: boolean
|
public searchFrom: string = ''
|
public showTreeBox: boolean
|
public selectedNodes: Array<string>
|
public selectedNode: any
|
// 记录当前操作的树
|
public treeType: string
|
// 记录收起的节点
|
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
|
//本地视频类型
|
public searchLocalType: number
|
//记录复制的摄像机id
|
public ctrlCameraId: string
|
//记录复制的摄像机name
|
public ctrlCameraName: string
|
|
public zTree: boolean
|
|
constructor() {
|
this.openeds = [true, true, false]
|
this.treeData = []
|
this.gb28181Data = []
|
this.clusterData = []
|
this.treeDataPure = []
|
this.gb28181DataPure = []
|
this.clusterDataPure = []
|
this.videoArr = ['']
|
this.searchCamType = 0
|
this.searchInput = ''
|
this.activeVideoIndex = ''
|
this.activeVideoId = ''
|
this.activeForceChoose = false
|
this.showTreeBox = true
|
this.readonly = true
|
this.gbReadonly = true
|
this.multiple = false
|
this.selectedNodes = []
|
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
|
}
|
|
setVideoArr(index: number, value: object, vue: any): void {
|
vue.$set(this.videoArr, index, value)
|
this.activeForceChoose = false
|
}
|
|
updateSelectedNodes() {
|
this.selectedNodes = []
|
if (!this.multiple) {
|
this.selectedNodes = [this.selectedNode.id]
|
return
|
}
|
let _selected = this.selectedNodes
|
function nodeFilter(node: any) {
|
if (node.type === '4' && node.selected) {
|
_selected.push(node.id)
|
}
|
if (node.children) {
|
node.children.forEach((n: any) => {
|
nodeFilter(n)
|
})
|
}
|
}
|
if (this.selectedNode.cameraType === 0) {
|
//摄像机树
|
if (this.treeActiveName == 'camera') {
|
this.treeData.forEach((n: any) => {
|
nodeFilter(n)
|
})
|
} else if (this.treeActiveName == 'cluster') {
|
//集群树
|
this.clusterData.forEach((n: any) => {
|
nodeFilter(n)
|
})
|
}
|
}
|
if (this.selectedNode.cameraType === 1) {
|
this.gb28181Data.forEach((n: any) => {
|
nodeFilter(n)
|
})
|
}
|
// if (this.selectedNode.cameraType === -1) {
|
// this.clusterData.forEach((n: any) => {
|
// 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) {
|
let camera = null
|
|
function nodeFilter(node: any) {
|
if (node.rtsp && node.rtsp.indexOf(ipaddr) != -1) {
|
camera = node
|
return
|
}
|
if (node.children) {
|
node.children.forEach((n: any) => {
|
nodeFilter(n)
|
})
|
}
|
}
|
|
this.treeData.forEach((n: any) => {
|
nodeFilter(n)
|
})
|
|
if (!camera) {
|
this.gb28181Data.forEach((n: any) => {
|
nodeFilter(n)
|
})
|
}
|
|
return camera
|
}
|
|
getCameraInfoById(id) {
|
let camera = null
|
|
function nodeFilter(node: any) {
|
if (node.id === id) {
|
camera = node
|
return
|
}
|
if (node.children) {
|
node.children.forEach((n: any) => {
|
nodeFilter(n)
|
})
|
}
|
}
|
|
this.treeData.forEach((n: any) => {
|
nodeFilter(n)
|
})
|
|
if (!camera) {
|
this.gb28181Data.forEach((n: any) => {
|
nodeFilter(n)
|
})
|
}
|
|
return camera
|
}
|
|
getParent(id: string, isGB: boolean): string {
|
let parent = '0'
|
|
function nodeFilter(node: Array<any>): any {
|
for (let i = 0; i < node.length; i++) {
|
if (node[i].id == id) {
|
return true
|
}
|
if (node[i].children && node[i].children.length > 0) {
|
if (nodeFilter(node[i].children)) {
|
parent = node[i].id
|
}
|
}
|
}
|
return false
|
}
|
|
if (isGB) {
|
nodeFilter(this.gb28181Data)
|
} else {
|
nodeFilter(this.treeData)
|
}
|
|
return parent
|
}
|
|
clean() {
|
this.treeData = JSON.parse(JSON.stringify(this.treeDataPure))
|
this.gb28181Data = JSON.parse(JSON.stringify(this.gb28181DataPure))
|
|
this.isFold(this.treeData)
|
this.isFold(this.gb28181Data)
|
this.selectedNodes = []
|
this.selectedNode = {}
|
|
this.cleanLocalVedio()
|
}
|
|
cleanTree(tree) {
|
if (tree === 'localTree') {
|
this.treeData = JSON.parse(JSON.stringify(this.treeDataPure))
|
}
|
if (tree === 'gb28182Tree') {
|
this.gb28181Data = JSON.parse(JSON.stringify(this.gb28181DataPure))
|
}
|
}
|
|
isFold(node) {
|
if (!node) {
|
return
|
}
|
node.forEach(n => {
|
// vue-js-tree 默认展开,控制部分折叠. z-tree 默认折叠, 控制部分展开
|
if (this.foldNodeList[n.id]) {
|
if (this.zTree) {
|
n.open = true
|
} else {
|
n.opened = false
|
}
|
}
|
if (n.children && n.children.length > 0) {
|
this.isFold(n.children)
|
}
|
})
|
}
|
|
setDropDisable(node) {
|
if (!node) {
|
return
|
}
|
node.forEach(n => {
|
if (n.children && n.children.length > 0) {
|
this.setDropDisable(n.children)
|
} else {
|
if (n.type === '4') {
|
n.dropDisabled = true
|
}
|
}
|
})
|
}
|
|
sortTreeData(node) {
|
if (!node) {
|
return
|
}
|
node.sort(function (obj1: any, obj2: any) {
|
var val1 = obj1.name
|
var val2 = obj2.name
|
if (val1 < val2) {
|
return -1
|
} else if (val1 > val2) {
|
return 1
|
} else {
|
return 0
|
}
|
})
|
|
node.forEach(n => {
|
if (n.children && n.children.length > 0) {
|
this.sortTreeData(n.children)
|
}
|
})
|
}
|
|
async fetchLocalTree() {
|
let params: any = {
|
searchType: this.searchCamType,
|
cameraName: this.searchInput
|
//isPlatform: 1
|
}
|
if (this.searchFrom == 'cluster') {
|
params.isPlatform = 1
|
}
|
const rsp: any = await getLocalCameraTree(params)
|
|
if (rsp && rsp.success) {
|
this.treeData = rsp.data ? rsp.data : []
|
if (this.treeData && this.treeData.length > 0) {
|
this.sortTreeData(this.treeData)
|
}
|
|
// 设置禁止拖拽摄像机到摄像机节点
|
this.setDropDisable(this.treeData)
|
this.treeDataPure = JSON.parse(JSON.stringify(this.treeData))
|
this.isFold(this.treeData)
|
}
|
}
|
|
async fetchClusterTree() {
|
const rsp: any = await getClusterTree({
|
searchType: this.searchCamType,
|
cameraName: this.searchInput
|
})
|
if (rsp && rsp.success) {
|
this.clusterData = rsp.data ? rsp.data : []
|
if (this.clusterData && this.clusterData.length > 0) {
|
this.sortTreeData(this.clusterData)
|
}
|
this.clusterDataPure = JSON.parse(JSON.stringify(this.clusterData))
|
this.isFold(this.clusterData)
|
}
|
}
|
|
async fetchGbTree() {
|
const rsp: any = await getGB28181CameraTree({
|
searchType: this.searchCamType,
|
cameraName: this.searchInput
|
})
|
|
if (rsp && rsp.success) {
|
this.gb28181Data = rsp.data ? rsp.data : []
|
if (this.gb28181Data && this.gb28181Data.length > 0) {
|
this.sortTreeData(this.gb28181Data)
|
}
|
|
this.gb28181DataPure = JSON.parse(JSON.stringify(this.gb28181Data))
|
this.isFold(this.gb28181Data)
|
}
|
}
|
|
async fetchTreeData() {
|
if (this.openeds[0]) {
|
this.fetchLocalTree()
|
}
|
if (this.openeds[1]) {
|
this.fetchGbTree()
|
}
|
|
this.findAllFile({})
|
}
|
|
async add(name: string, parent: string) {
|
await addAreaTreeData({
|
name: name,
|
parentId: parent
|
})
|
|
this.fetchTreeData()
|
}
|
|
async del(id: string) {
|
await delAreaTreeData({
|
id: id
|
})
|
|
this.fetchTreeData()
|
}
|
|
async update(name: string, id: string, alias: string, isGb: boolean) {
|
await updateAreaTreeData({
|
id: id,
|
name: name,
|
parentId: this.getParent(id, isGb),
|
alias: alias
|
})
|
|
this.fetchTreeData()
|
}
|
|
async refreshGB28181() {
|
await refreshGB28181Tree()
|
// 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) {
|
await updateCameraArea({ cameraId: cameraId, areaId: areaId })
|
}
|
}
|