From e37e45cfe1123928dba5d9c5a427b0ee497b7ad6 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期二, 23 八月 2022 03:21:32 +0800
Subject: [PATCH] 修复算法配置的字段内容

---
 src/Pool/TreeData.ts |  226 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 140 insertions(+), 86 deletions(-)

diff --git a/src/Pool/TreeData.ts b/src/Pool/TreeData.ts
index 330295e..7598c5b 100644
--- a/src/Pool/TreeData.ts
+++ b/src/Pool/TreeData.ts
@@ -9,9 +9,9 @@
   refreshGB28181Tree,
   updateCameraArea,
   getCameraBaseImage
-} from '@/api/area'
+} from "@/api/area"
 
-import {getClusterDevList} from '@/api/clusterManage'
+import { getClusterDevList } from "@/api/clusterManage"
 
 export default class TreeDataPool {
   public openeds: Array<boolean>
@@ -32,7 +32,7 @@
   public readonly: boolean
   public gbReadonly: boolean
   public multiple: boolean
-  public searchFrom: string = ''
+  public searchFrom: string = ""
   public showTreeBox: boolean
   public selectedNodes: Array<string>
   public selectedNode: any
@@ -67,7 +67,11 @@
   public baseImageLoading: boolean
 
   public activeNode: string
+  public clusterId: string
+  public devId: string
 
+  // 璁板綍鎽勫儚鏈烘墍灞炵殑鐖惰妭鐐瑰悕绉�
+  public cameraParents: object
 
   constructor() {
     this.openeds = [true, true, false]
@@ -78,11 +82,11 @@
     this.treeDataPure = []
     this.gb28181DataPure = []
     this.clusterDataPure = []
-    this.videoArr = ['']
+    this.videoArr = [""]
     this.searchCamType = 0
-    this.searchInput = ''
-    this.activeVideoIndex = ''
-    this.activeVideoId = ''
+    this.searchInput = ""
+    this.activeVideoIndex = ""
+    this.activeVideoId = ""
     this.activeForceChoose = false
     this.showTreeBox = true
     this.readonly = true
@@ -90,15 +94,15 @@
     this.multiple = false
     this.selectedNodes = []
     this.selectedNode = {}
-    this.treeType = ''
+    this.treeType = ""
     this.foldNodeList = {}
-    this.treeActiveName = 'camera'
+    this.treeActiveName = "camera"
     this.searchLocalType = 0
 
     //1:鏆傚仠鐘舵�侊紱2锛氱瓑寰呯姸鎬�;3:缃伆
-    this.btnStaus = '3'
-    this.ctrlCameraId = ''
-    this.ctrlCameraName = ''
+    this.btnStaus = "3"
+    this.ctrlCameraId = ""
+    this.ctrlCameraName = ""
     this.zTree = false
     this.checkedTreeNode = []
     this.gb28181CheckedCount = 0
@@ -107,11 +111,11 @@
     this.cameraNameForBaseImage = ""
     this.gb28181CameraBaseImage = ""
     this.baseImageLoading = false
-    this.activeNode = ''
-
-
+    this.activeNode = ""
+    this.clusterId = ""
+    this.devId = ""
+    this.cameraParents = {}
   }
-
 
   setVideoArr(index: number, value: object, vue: any): void {
     vue.$set(this.videoArr, index, value)
@@ -126,9 +130,9 @@
     }
     let _selected = this.selectedNodes
     function nodeFilter(node: any) {
-      if (node.type === '4' && node.selected) {
+      if (node.type === "4" && node.selected) {
         _selected.push(node.id)
-        sessionStorage.setItem('cameraDevId',node.devId)
+        sessionStorage.setItem("cameraDevId", node.devId)
       }
       if (node.children) {
         node.children.forEach((n: any) => {
@@ -138,11 +142,11 @@
     }
     if (this.selectedNode.cameraType === 0) {
       //鎽勫儚鏈烘爲
-      if (this.treeActiveName == 'camera') {
+      if (this.treeActiveName == "camera") {
         this.treeData.forEach((n: any) => {
           nodeFilter(n)
         })
-      } else if (this.treeActiveName == 'cluster') {
+      } else if (this.treeActiveName == "cluster") {
         //闆嗙兢鏍�
         this.clusterData.forEach((n: any) => {
           nodeFilter(n)
@@ -162,27 +166,17 @@
   }
 
   updateZTreeCheckNodes(checkedNodes) {
-    let _this = this
-    _this.selectedNodes = []
-    if (!_this.multiple) {
-      _this.selectedNodes = [checkedNodes.id]
+    this.selectedNodes = []
+    if (!this.multiple) {
+      this.selectedNodes = [checkedNodes.id]
       return
     }
 
-    function nodeFilter(node: any) {
-      if (node.type === '4' && (node.selected || node.checked)) {
-      sessionStorage.setItem("cameraDevId", node.devId);
-        _this.selectedNodes.push(node.id)
+    checkedNodes.forEach((node) => {
+      if (node.type === "4" && (node.selected || node.checked)) {
+        sessionStorage.setItem("cameraDevId", node.devId)
+        this.selectedNodes.push(node.id)
       }
-      if (node.children) {
-        node.children.forEach((n: any) => {
-          nodeFilter(n)
-        })
-      }
-    }
-
-    checkedNodes.forEach((n: any) => {
-      nodeFilter(n)
     })
   }
 
@@ -214,7 +208,7 @@
     return camera
   }
 
-  getCameraInfoById(id) {
+  getCameraInfoById(id: string) {
     let camera = null
 
     function nodeFilter(node: any) {
@@ -243,7 +237,7 @@
   }
 
   getParent(id: string, isGB: boolean): string {
-    let parent = '0'
+    let parent = "0"
 
     function nodeFilter(node: Array<any>): any {
       for (let i = 0; i < node.length; i++) {
@@ -278,11 +272,19 @@
     this.selectedNode = {}
   }
 
+  reset() {
+    this.treeData = []
+    this.gb28181Data = []
+
+    this.selectedNodes = []
+    this.selectedNode = {}
+  }
+
   cleanTree(tree) {
-    if (tree === 'localTree') {
+    if (tree === "localTree") {
       this.treeData = JSON.parse(JSON.stringify(this.treeDataPure))
     }
-    if (tree === 'gb28182Tree') {
+    if (tree === "gb28182Tree") {
       this.gb28181Data = JSON.parse(JSON.stringify(this.gb28181DataPure))
     }
   }
@@ -291,7 +293,7 @@
     if (!node) {
       return
     }
-    node.forEach(n => {
+    node.forEach((n) => {
       // vue-js-tree 榛樿灞曞紑,鎺у埗閮ㄥ垎鎶樺彔. z-tree 榛樿鎶樺彔, 鎺у埗閮ㄥ垎灞曞紑
       if (this.foldNodeList[n.id]) {
         if (this.zTree) {
@@ -310,22 +312,22 @@
     if (!node) {
       return
     }
-    node.forEach(n => {
+    node.forEach((n) => {
       if (n.children && n.children.length > 0) {
         this.setDropDisable(n.children)
       } else {
-        if (n.type === '4') {
+        if (n.type === "4") {
           n.dropDisabled = true
         }
       }
     })
   }
 
-  sortTreeData(node) {
+  sortTreeData(node, parentName = "") {
     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) {
@@ -337,42 +339,65 @@
       }
     })
 
-    node.forEach(n => {
+    node.forEach((n) => {
       if (n.children && n.children.length > 0) {
         if (this.zTree) {
           n.open = true
         }
-        this.sortTreeData(n.children)
+        let pname = parentName === "" ? n.name : parentName + "/" + n.name
+        // console.log("pname", pname)
+        this.sortTreeData(n.children, pname)
+      } else {
+        if (n.type != "MENU") {
+          this.cameraParents[n.id] = parentName
+        }
       }
     })
   }
 
   async fetchLocalTree() {
     let params: any = {
-      parentId:"",
+      parentId: "",
       searchType: this.searchCamType,
-      cameraName: this.searchInput,
-    
+      cameraName: this.searchInput
+
       //isPlatform: 1
     }
-    if (this.searchFrom == 'cluster') {
+    if (this.searchFrom == "cluster") {
       params.isPlatform = 1
     }
-  
-
     const rsp: any = await getLocalCameraTree(params)
 
     if (rsp && rsp.success) {
-    
       this.treeData = rsp.data.treeMenu ? rsp.data.treeMenu : []
       if (this.treeData && this.treeData.length > 0) {
         this.sortTreeData(this.treeData)
+        // console.log("cameraParents", this.cameraParents)
       }
 
       // 璁剧疆绂佹鎷栨嫿鎽勫儚鏈哄埌鎽勫儚鏈鸿妭鐐�
       this.setDropDisable(this.treeData)
       this.treeDataPure = JSON.parse(JSON.stringify(this.treeData))
       this.isFold(this.treeData)
+
+      // 娓呯悊娌℃湁鏉冮檺绠$悊鐨勬憚鍍忔満, 鍚庣淇鍚庡垹闄�
+      let userInfo = JSON.parse(sessionStorage.getItem("userInfo"))
+
+      // 绠$悊鍛樻潈闄�
+      if (userInfo.username == "Administrator") {
+        return
+      }
+
+      let checkedCameras = userInfo.email
+
+      // basic 涓哄瓙璐︽埛榛樿鐨勭┖瀛楁,琛ㄧず鍙鐞嗙殑鎽勫儚鏈虹洰褰曚负绌�
+      if (checkedCameras == "basic") {
+        this.treeData = []
+      } else {
+        let cameraIds = checkedCameras.split(",")
+        console.log("cameraIds", cameraIds)
+        this.removeNoAuthorizedNode(this.treeData, cameraIds)
+      }
     }
   }
 
@@ -392,36 +417,37 @@
   }
 
   async fetchGbTree() {
-    // 鍚庨棬
-    // const rsp: any = await getGB28181CameraTree({
-    //   searchType: this.searchCamType,
-    //   cameraName: this.searchInput
-    // })
+    const rsp: any = await getGB28181CameraTree({
+      parentId: "",
+      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)
-    //   }
+    if (rsp && rsp.success) {
+      this.gb28181Data = rsp.data.treeMenu ? rsp.data.treeMenu : []
+      if (this.gb28181Data && this.gb28181Data.length > 0) {
+        this.sortTreeData(this.gb28181Data)
+      }
 
-    //   this.gb28181DataPure = JSON.parse(JSON.stringify(this.gb28181Data))
-    //   this.isFold(this.gb28181Data)
-    // }
+      this.gb28181DataPure = JSON.parse(JSON.stringify(this.gb28181Data))
+      this.isFold(this.gb28181Data)
+    }
   }
 
   async fetchTreeData() {
+    this.cameraParents = {}
     if (this.openeds[0]) {
-      this.fetchLocalTree()
+      await this.fetchLocalTree()
     }
     if (this.openeds[1]) {
-      this.fetchGbTree()
+      await this.fetchGbTree()
     }
   }
 
   async add(name: string, parent: string) {
     await addAreaTreeData({
       name: name,
-      parentId: parent,
+      parentId: parent
     })
 
     this.fetchTreeData()
@@ -429,7 +455,7 @@
 
   async del(id: string) {
     await delAreaTreeData({
-      id: id,
+      id: id
     })
 
     this.fetchTreeData()
@@ -440,14 +466,14 @@
       id: id,
       name: name,
       parentId: this.getParent(id, isGb),
-      alias: alias,
+      alias: alias
     })
 
     this.fetchTreeData()
   }
 
   async refreshGB28181() {
-    await refreshGB28181Tree()
+    await refreshGB28181Tree({})
     // this.fetchGbTree()
   }
 
@@ -457,20 +483,20 @@
 
   getAllChildrenNodes(treeNode, arr) {
     for (var i = 0; i < treeNode.length; i++) {
-      var sonList = treeNode[i].children;
+      var sonList = treeNode[i].children
       if (!sonList) {
         if (treeNode[i].type == "camera") {
-          arr.push(treeNode[i]);
+          arr.push(treeNode[i])
 
           if (treeNode[i].checked) {
-            this.gb28181CheckedCount += 1;
+            this.gb28181CheckedCount += 1
           }
         }
       } else {
-        this.getAllChildrenNodes(sonList, arr);
+        this.getAllChildrenNodes(sonList, arr)
       }
     }
-    return arr;
+    return arr
   }
   countChildrenNodes(treeNode) {
     let arry = []
@@ -485,7 +511,10 @@
     if (update) {
       fn = refreshGB28181Tree
     }
-    const rsp: any = await fn()
+    const rsp: any = await fn({
+      clusterId: this.clusterId,
+      devId: this.devId
+    })
 
     if (rsp && rsp.success) {
       this.selectedNode = {}
@@ -498,15 +527,14 @@
       this.setDropDisable(this.treeData)
       this.isFold(this.treeData)
 
-      this.activeTreeData = this.treeData
-
-      this.gb28181CheckedCount = 0;
+      this.gb28181CheckedCount = 0
       this.gb28181ChildNodeCount = this.countChildrenNodes(this.treeData)
+      this.activeTreeData = this.treeData
     }
   }
 
   removeNoCheckedNode(nodes: Array<any>) {
-    for (let i = 0; i < nodes.length;) {
+    for (let i = 0; i < nodes.length; ) {
       if (!nodes[i].checked) {
         nodes.splice(i, 1)
         continue
@@ -519,9 +547,31 @@
     }
   }
 
+  removeNoAuthorizedNode(nodes: Array<any>, authList: Array<any>) {
+    for (let i = 0; i < nodes.length; ) {
+      if (nodes[i].children && nodes[i].children.length) {
+        this.removeNoAuthorizedNode(nodes[i].children, authList)
+      }
+
+      if (nodes[i].type === "4") {
+        if (authList.indexOf(nodes[i].id) < 0) {
+          nodes.splice(i, 1)
+          continue
+        }
+      } else {
+        if (!nodes[i].children || !nodes[i].children.length) {
+          nodes.splice(i, 1)
+          continue
+        }
+      }
+
+      i++
+    }
+  }
+
   countCheckedNodes(nodes: Array<any>) {
     let count = 0
-    nodes.forEach(n => {
+    nodes.forEach((n) => {
       if (n.type == "camera") {
         count++
       }
@@ -542,7 +592,11 @@
     this.cameraNameForBaseImage = node.name
 
     try {
-      const rsp: any = await getCameraBaseImage({ id: node.id })
+      const rsp: any = await getCameraBaseImage({
+        id: node.id,
+        clusterId: this.clusterId,
+        devId: this.devId
+      })
 
       if (rsp && rsp.data) {
         this.gb28181CameraBaseImage = rsp.data

--
Gitblit v1.8.0