zhangzengfei
2022-06-18 c208b104011e0bbdc824960ed025b597d081c78f
src/Pool/VideoRuleData.ts
@@ -1,164 +1,160 @@
import { getCameraInfo,getGB28181CameraInfo } from "@/api/camera";
import { getAllPolygon } from "@/api/polygon";
import { getDirDetails, findAllFileByStackId } from "@/api/localVedio";
import { getCameraSceneRule } from '@/api/scene'
import { getCameraInfo, getGB28181CameraInfo } 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 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 loading: boolean
  public analytics: boolean;
  public dealWay: boolean;
  public runServerName: string;
  public analytics: boolean
  public dealWay: boolean
  public runServerName: string
  public resolutionOption: Array<any>;
  public selectResolution: string;
  public hasCtrlC: boolean;
  public resolutionOption: Array<any>
  public selectResolution: string
  public hasCtrlC: boolean
  public gb28181: boolean
  constructor(id: string,isGB:boolean) {
    this.loading = false;
    this.baseImg = "";
    this.cameraId = id ? id : "";
    this.cameraName = "";
    this.selectTask = [];
    this.polygonData = [];
    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 = [];
    this.camearInfo = {}
    this.analytics = false
    this.dealWay = false
    this.runServerName = ""
    this.rules = []
    if (id && id !== "") {
      this.update(isGB);
      this.update(isGB)
    }
    this.resolutionOption = [
      {
        value: '1001',
        label: '1280*720'
        value: "1001",
        label: "1280*720"
      },
      {
        value: '1002',
        label: '1920*1080'
        value: "1002",
        label: "1920*1080"
      },
      {
        value: '1003',
        label: '2560*1440'
        value: "1003",
        label: "2560*1440"
      }
    ]
    this.selectResolution = '1002'
    this.selectResolution = "1002"
    this.hasCtrlC = false
    this.gb28181 = isGB ? isGB : false
  }
  public async update(isGB) {
    await this.getInfo(isGB);
    await this.getSceneRule();
    await this.getPolygon();
    await this.getInfo(isGB)
    await this.getSceneRule()
    await this.getPolygon()
  }
  public async getInfo(isGB) {
    // 判断选中的是摄像机还是数据栈
    if (this.cameraId.indexOf("stack") === -1) {
      //处理国标摄像机
      if(isGB) {
        try {
        const rsp: any = await getGB28181CameraInfo(this.cameraId);
          const rsp: any = await getGB28181CameraInfo(this.cameraId)
        if (rsp.success) {
          this.cameraName = rsp.data.name ? rsp.data.name : "";
            this.cameraName = rsp.data.name ? rsp.data.name : ""
        }
      } catch {
        this.cameraName = "";
          this.cameraName = ""
      }
      }
      else {
        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 });
        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;
        let snapshots = rsp.data.dataList.map((obj) => {
          return obj.snapshot_url
        })
        this.baseImg = snapshots[0];
        this.baseImg = snapshots[0]
        // console.log(snapshots)
      }
    }
  }
  public async getPolygon() {
    this.polygonData = [];
    this.polygonData = []
    const rsp: any = await getAllPolygon({ cameraId: this.cameraId });
    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 : "";
        this.baseImg = rsp.data.snapshot_url ? rsp.data.snapshot_url : ""
        if (!this.baseImg) {
          this.loading = true;
          this.loading = true
        } else {
          this.loading = false;
          this.loading = false
        }
      }
      const newObj = item => {
      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);
      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];
        this.polygonData = [...polygon, ...line, ...rect]
      }
    }
  }
  public async getSceneRule() {
    const rsp: any = await getCameraSceneRule({ cameraId: this.cameraId });
    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.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