From 3e4904fda5c78cfd8b40fa925fd2970b01850224 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期五, 19 八月 2022 22:21:30 +0800
Subject: [PATCH] 添加摄像机权限

---
 src/Pool/TreeData.ts |   76 ++++++++++++++++++++++++++++---------
 1 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/src/Pool/TreeData.ts b/src/Pool/TreeData.ts
index 16b1ca3..7598c5b 100644
--- a/src/Pool/TreeData.ts
+++ b/src/Pool/TreeData.ts
@@ -166,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) {
+    checkedNodes.forEach((node) => {
       if (node.type === "4" && (node.selected || node.checked)) {
         sessionStorage.setItem("cameraDevId", node.devId)
-        _this.selectedNodes.push(node.id)
+        this.selectedNodes.push(node.id)
       }
-      if (node.children) {
-        node.children.forEach((n: any) => {
-          nodeFilter(n)
-        })
-      }
-    }
-
-    checkedNodes.forEach((n: any) => {
-      nodeFilter(n)
     })
   }
 
@@ -218,7 +208,7 @@
     return camera
   }
 
-  getCameraInfoById(id) {
+  getCameraInfoById(id: string) {
     let camera = null
 
     function nodeFilter(node: any) {
@@ -278,6 +268,14 @@
 
     this.isFold(this.treeData)
     this.isFold(this.gb28181Data)
+    this.selectedNodes = []
+    this.selectedNode = {}
+  }
+
+  reset() {
+    this.treeData = []
+    this.gb28181Data = []
+
     this.selectedNodes = []
     this.selectedNode = {}
   }
@@ -368,7 +366,6 @@
     if (this.searchFrom == "cluster") {
       params.isPlatform = 1
     }
-
     const rsp: any = await getLocalCameraTree(params)
 
     if (rsp && rsp.success) {
@@ -382,6 +379,25 @@
       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)
+      }
     }
   }
 
@@ -421,10 +437,10 @@
   async fetchTreeData() {
     this.cameraParents = {}
     if (this.openeds[0]) {
-      this.fetchLocalTree()
+      await this.fetchLocalTree()
     }
     if (this.openeds[1]) {
-      this.fetchGbTree()
+      await this.fetchGbTree()
     }
   }
 
@@ -531,6 +547,28 @@
     }
   }
 
+  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) => {

--
Gitblit v1.8.0