ZZJ
2022-03-25 52ad37fba37a1ae72f124106627227a09836be5b
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { getCameraInfo } from "@/api/camera";
import { getAllPolygon } from "@/api/polygon";
import { getDirDetails, findAllFileByStackId } from "@/api/localVedio";
import { getCameraSceneRule } from '@/api/scene'
 
export default class VideoRuleData {
  public selectTask: Array<object>;
  public rules: Array<object>;
  public polygonData: Array<object>;
  public cameraId: string = "";
  public canvasData: object;
  public baseImg: string;
  public cameraName: string;
  public camearInfo: object;
 
  public loading: boolean;
 
  public analytics: boolean;
  public dealWay: boolean;
  public runServerName: string;
 
  public resolutionOption: Array<any>;
  public selectResolution: string;
  public hasCtrlC: boolean;
 
  constructor(id: string) {
    this.loading = false;
    this.baseImg = "";
    this.cameraId = id ? id : "";
    this.cameraName = "";
    this.selectTask = [];
    this.polygonData = [];
    this.canvasData = {
      line: [],
      arrow: [],
      polygon: [],
      rect: []
    };
 
    this.camearInfo = {};
    this.analytics = false;
    this.dealWay = false;
    this.runServerName = "";
    this.rules = [];
 
    if (id && id !== "") {
      this.update();
    }
 
    this.resolutionOption = [
      {
        value: '1001',
        label: '1280*720'
      },
      {
        value: '1002',
        label: '1920*1080'
      },
      {
        value: '1003',
        label: '2560*1440'
      }
    ]
    this.selectResolution = '1002'
    this.hasCtrlC = false
  }
 
  public async update() {
    await this.getInfo();
    await this.getSceneRule();
    
    await this.getPolygon();
  }
 
  public async getInfo() {
    // 判断选中的是摄像机还是数据栈
    if (this.cameraId.indexOf("stack") === -1) {
      try {
        const rsp: any = await getCameraInfo(this.cameraId);
        if (rsp.success) {
          this.cameraName = rsp.data.name ? rsp.data.name : "";
        }
      } catch {
        this.cameraName = "";
      }
    } else {
      const rsp: any = await findAllFileByStackId({ stackId: this.cameraId });
      if (rsp.success && rsp.data.dataList.length) {
        let snapshots = rsp.data.dataList.map(obj => {
          return obj.snapshot_url;
        })
 
        this.baseImg = snapshots[0];
        // console.log(snapshots)
      }
    }
 
  }
 
  public async getPolygon() {
    this.polygonData = [];
 
    const rsp: any = await getAllPolygon({ cameraId: this.cameraId });
    if (rsp && rsp.success) {
      this.canvasData = {
        line: rsp.data.line,
        arrow: rsp.data.arrow,
        polygon: rsp.data.polygon,
        rect: rsp.data.rect
      };
 
      // 只对摄像机数据底图进行处理
      if (this.cameraId.indexOf("stack") < 0) {
        this.baseImg = rsp.data.snapshot_url ? rsp.data.snapshot_url : "";
        if (!this.baseImg) {
          this.loading = true;
        } else {
          this.loading = false;
        }
      }
 
      const newObj = item => {
        return {
          id: item.id,
          name: item.name,
          defence_state: item.defence_state
        };
      };
 
      let line = rsp.data.line.map(newObj);
      let polygon = rsp.data.polygon.map(newObj);
      let rect = rsp.data.rect.map(newObj);
 
      if (line.length !== 0 || polygon.length !== 0 || rect.length !== 0) {
        this.polygonData = [...polygon, ...line, ...rect];
      }
    }
  }
 
  public async getSceneRule() {
    const rsp: any = await getCameraSceneRule({ cameraId: this.cameraId });
    if (rsp && rsp.success) {
      let rspData = rsp.data.taskList ? rsp.data.taskList : []
      this.rules = rsp.data.rules ? rsp.data.rules : []
      this.camearInfo = rsp.data.cameraInfo ? rsp.data.cameraInfo : {};
      this.analytics = rsp.data.cameraInfo.run_type !== -1 ? true : false
      this.dealWay = rsp.data.cameraInfo.run_type === 1 ? true : false
      this.runServerName = rsp.data.cameraInfo.runServerName
    }
  
    
  }
}