zhangzengfei
2022-08-10 907a3504a77873a8e762adc2f684222c8946adec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { getCameraTask, initTaskData, monitorRealTimeTaskData } from "@/api/task"
 
export default class VideoTaskData {
  public tasks: Array<any> = []
  public taskCard: Array<object> = []
  public cameras: Array<string> = []
  public activeIndex: number
  public separateRulesTasks: object = []
 
  constructor() {
    this.tasks = []
    this.taskCard = []
    this.cameras = []
    this.activeIndex = 0
    this.separateRulesTasks = []
  }
 
  public async fetchTasks() {
    console.log("fetchTasks")
    // 根据选中摄像机,查找任务,去重
    const rsp: any = await getCameraTask({
      cameraId: this.cameras[0]
    })
    if (rsp && rsp.success) {
      //let taskIds = []
      let taskNames = []
      this.tasks = []
 
      // rsp.data.forEach((d: any) => {
      //   if (d.tasks) {
      //     d.tasks.forEach((t: any) => {
      //       if (taskIds.indexOf(t.taskid) < 0) {
      //         taskIds.push(t.taskid)
      //         if (t.taskname == "人脸测温") {
      //           this.tasks.unshift({
      //             taskName: t.taskname,
      //             taskId: t.taskid
      //           })
      //         } else {
      //           this.tasks.push({
      //             taskName: t.taskname,
      //             taskId: t.taskid
      //           })
      //         }
      //       }
      //     })
      //   }
      // })
      rsp.data.rules.forEach((d: any) => {
        if (taskNames.indexOf(d.scene_name) < 0) {
          taskNames.push(d.scene_name)
          this.tasks.push(d)
        } else {
          let repeatOne = this.tasks.find((one: any) => one.scene_name == d.scene_name)
          repeatOne.id += `,${d.id}`
          repeatOne.isDelete = repeatOne.isDelete && d.isDelete
        }
      })
 
      this.tasks = this.tasks.filter((d: any) => !d.isDelete)
      console.log(this.tasks)
 
      // 初始化第一任务的信息
      this.initTaskList()
    }
  }
 
  public async initTaskList() {
    // console.log(this.tasks, this.activeIndex, '初始化获取人数抓拍')
    this.taskCard.splice(0, this.taskCard.length)
    if (!this.tasks[this.activeIndex]) {
      return
    }
 
    const rsp: any = await initTaskData({
      //tasks: [this.tasks[this.activeIndex].taskId],
      tasks: this.tasks[this.activeIndex].id.split(","),
      treeNodes: this.cameras
    })
 
    if (rsp && rsp.success && rsp.data.datalist) {
      rsp.data.datalist.forEach((element) => {
        // this.taskCard.push({
        //   list: [element],
        //   activeObject: element
        // });
        this.taskCard.push(element)
      })
    }
  }
 
  public async monitorTaskData() {
    if (!this.tasks[this.activeIndex]) {
      return
    }
 
    const rsp: any = await monitorRealTimeTaskData({
      //tasks: [this.tasks[this.activeIndex].id],
      tasks: this.tasks[this.activeIndex].id.split(","),
      treeNodes: this.cameras
    })
    if (rsp && rsp.success) {
      if (rsp.data.datalist && rsp.data.datalist.length > 0) {
        rsp.data.datalist.reverse().forEach((element) => {
          let rt = this.taskCard.filter((c: any) => {
            return c.activeObject.id === element.activeObject.id
          })
          if (rt.length < 1) {
            // this.taskCard.unshift({
            //   list: [element],
            //   activeObject: element
            // });
            this.taskCard.unshift(element)
          }
        })
        this.taskCard.splice(20, this.taskCard.length - 20)
      }
    }
  }
}