import {
|
getLocalCameraTree,
|
getGB28181CameraTree,
|
addAreaTreeData,
|
delAreaTreeData,
|
updateAreaTreeData,
|
refreshGB28181Tree
|
} from "@/api/area";
|
|
export default class TreeDataPool {
|
public openeds: Array<boolean>;
|
public treeData: Array<object>;
|
public gb28181Data: Array<object>;
|
public treeDataPure: Array<object>;
|
public gb28181DataPure: 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 showTreeBox: boolean;
|
public selectedNodes: Array<string>;
|
public selectedNode: any;
|
// 记录当前操作的树
|
public treeType: string;
|
|
constructor() {
|
this.openeds = [true, true, false];
|
this.treeData = [];
|
this.gb28181Data = [];
|
this.treeDataPure = [];
|
this.gb28181DataPure = [];
|
this.videoArr = new Array(8);
|
this.searchCamType = 0;
|
this.searchInput = "";
|
this.activeVideoIndex = 0;
|
this.activeVideoId = "";
|
this.activeForceChoose = false;
|
this.showTreeBox = false;
|
this.readonly = true;
|
this.gbReadonly = true;
|
this.multiple = false;
|
this.selectedNodes = [];
|
this.selectedNode = {};
|
this.treeType = ""
|
}
|
|
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);
|
});
|
}
|
}
|
this.treeData.forEach((n: any) => {
|
nodeFilter(n);
|
});
|
|
this.gb28181Data.forEach((n: any) => {
|
nodeFilter(n);
|
});
|
}
|
|
getParent(id: string): 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;
|
}
|
|
nodeFilter(this.treeData);
|
|
return parent;
|
}
|
|
clean() {
|
this.treeData = JSON.parse(JSON.stringify(this.treeDataPure));
|
this.gb28181Data = JSON.parse(JSON.stringify(this.gb28181DataPure));
|
this.selectedNodes = [];
|
this.selectedNode = {};
|
}
|
|
cleanTree(tree) {
|
if (tree === "localTree") {
|
this.treeData = JSON.parse(JSON.stringify(this.treeDataPure));
|
}
|
if (tree === "gb28182Tree") {
|
this.gb28181Data = JSON.parse(JSON.stringify(this.gb28181DataPure));
|
}
|
}
|
|
async fetchLocalTree() {
|
const rsp: any = await getLocalCameraTree({
|
searchType: this.searchCamType,
|
cameraName: this.searchInput,
|
isPlatform: 1
|
});
|
|
if (rsp && rsp.success) {
|
this.treeData = rsp.data
|
this.treeData.sort(function (obj1: any, obj2: any) {
|
var val1 = obj1.id;
|
var val2 = obj2.id;
|
if (val1 < val2) {
|
return -1;
|
} else if (val1 > val2) {
|
return 1;
|
} else {
|
return 0;
|
}
|
});
|
|
this.treeDataPure = JSON.parse(JSON.stringify(this.treeData));
|
}
|
}
|
|
async fetchGbTree() {
|
const rsp: any = await getGB28181CameraTree({
|
searchType: this.searchCamType,
|
cameraName: this.searchInput
|
});
|
|
if (rsp && rsp.success) {
|
this.gb28181Data = rsp.data
|
this.gb28181Data.sort(function (obj1: any, obj2: any) {
|
var val1 = obj1.id;
|
var val2 = obj2.id;
|
if (val1 < val2) {
|
return -1;
|
} else if (val1 > val2) {
|
return 1;
|
} else {
|
return 0;
|
}
|
});
|
|
this.gb28181DataPure = JSON.parse(JSON.stringify(this.gb28181Data));
|
}
|
}
|
|
async fetchTreeData() {
|
if (this.openeds[0]) {
|
this.fetchLocalTree()
|
}
|
if (this.openeds[1]) {
|
this.fetchGbTree()
|
}
|
}
|
|
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) {
|
await updateAreaTreeData({
|
id: id,
|
name: name,
|
parentId: this.getParent(id),
|
alias: alias
|
});
|
|
this.fetchTreeData();
|
}
|
|
async refreshGB28181() {
|
await refreshGB28181Tree()
|
this.fetchGbTree()
|
}
|
}
|