ZZJ
2022-06-10 58bf48cea61c6c5b4381a4b8ff5b4a39eb4671eb
src/pages/cameraAccess/components/SeparateRules.vue
@@ -7,7 +7,7 @@
            <span>
              <span class="label">视频分析处理</span>
              <el-switch
                style="margin-left: 10px;"
                style="margin-left: 10px"
                v-model="Camera.analytics"
                @change="pollEnable"
                :disabled="!Camera.cameraId"
@@ -15,26 +15,44 @@
            </span>
          </div>
          <div v-if="Camera.analytics" class="flex-box" v-show="cameraType === 'camera'">
          <div
            v-if="Camera.analytics"
            class="flex-box"
            v-show="cameraType === 'camera'"
          >
            <span class="label">处理方式</span>
            <toggle-button
              :value="Camera.dealWay"
              :width="60"
              :labels="{checked: '实时', unchecked: '轮询'}"
              :color="{checked: '#3D68E1', unchecked: '#FF7733', disabled: '#CCCCCC'}"
              :labels="{ checked: '实时', unchecked: '轮询' }"
              :color="{
                checked: '#3D68E1',
                unchecked: '#FF7733',
                disabled: '#CCCCCC',
              }"
              :sync="true"
              @change="changePoll"
            />
          </div>
          <div v-if="Camera.analytics" class="flex-box" v-show="cameraType === 'camera'">
            <span
              class="label"
            >分辨率: {{(Camera.camearInfo.resolution_width == 0 || Camera.camearInfo.resolution_height == 0) ? '本机分辨率': `${Camera.camearInfo.resolution_width} * ${Camera.camearInfo.resolution_height}` }}</span>
          <div
            v-if="Camera.analytics"
            class="flex-box"
            v-show="cameraType === 'camera'"
          >
            <span class="label"
              >分辨率:
              {{
                Camera.camearInfo.resolution_width == 0 ||
                Camera.camearInfo.resolution_height == 0
                  ? "本机分辨率"
                  : `${Camera.camearInfo.resolution_width} * ${Camera.camearInfo.resolution_height}`
              }}</span
            >
          </div>
          <div v-if="Camera.analytics" class="flex-box">
            <span class="label">SmartAI节点: {{ Camera.runServerName}}</span>
            <span class="label">SmartAI节点: {{ Camera.runServerName }}</span>
          </div>
          <div v-if="Camera.analytics" class="flex-box">
@@ -47,19 +65,27 @@
                popper-class="atooltip"
              >
                <span
                  style="color:#3D68E1;cursor: pointer;font-size:23px;"
                  style="color: #3d68e1; cursor: pointer; font-size: 23px"
                  @click="ctrlC"
                  class="iconfont iconfuzhiguize"
                ></span>
              </el-tooltip>
              <el-tooltip
                effect="dark"
                :content="!TreeDataPool.ctrlCameraId?'粘贴算法规则':`粘贴算法规则,来源:${TreeDataPool.ctrlCameraName}`"
                :content="
                  !TreeDataPool.ctrlCameraId
                    ? '粘贴算法规则'
                    : `粘贴算法规则,来源:${TreeDataPool.ctrlCameraName}`
                "
                placement="bottom"
                popper-class="atooltip"
              >
                <span
                  :style="!TreeDataPool.ctrlCameraId?'cursor: not-allowed;font-size:23px;':'color:#3D68E1;font-size:23px;cursor: pointer;'"
                  :style="
                    !TreeDataPool.ctrlCameraId
                      ? 'cursor: not-allowed;font-size:23px;'
                      : 'color:#3D68E1;font-size:23px;cursor: pointer;'
                  "
                  @click="ctrlV"
                  class="iconfont iconniantie ml5"
                ></span>
@@ -74,7 +100,7 @@
    <div class="top">
      <p class="task-css">
        <b style="font-size: 14px; line-height: 18px;">场景</b>
        <b style="font-size: 14px; line-height: 18px">场景</b>
      </p>
      <div class="clearfix">
        <slide-scene :sceneData="Camera.rules"></slide-scene>
@@ -83,7 +109,7 @@
            :showRealPoll="cameraType === 'camera'"
            :ShowLocalVedio="cameraType === 'dataStack'"
            v-if="showSysInfo"
            style="margin-top:-10px"
            style="margin-top: -10px"
          />
        </div>
      </div>
@@ -99,15 +125,17 @@
              <span
                class="el-dropdown-link"
                @click="drawBaseImg"
                style="position: relative;top: 5px; cursor:pointer"
                style="position: relative; top: 5px; cursor: pointer"
              >
                <i class="iconfont iconbianji1" style="font-size: 28px; "></i>
                <i class="iconfont iconbianji1" style="font-size: 28px"></i>
              </span>
            </div>
            <div style="width:590px;height:16px;">
              <b
                style="font-size:14px"
              >{{ Camera.camearInfo.alias ? Camera.camearInfo.alias: Camera.camearInfo.name }}</b>
            <div style="width: 590px; height: 16px">
              <b style="font-size: 14px">{{
                Camera.camearInfo.alias
                  ? Camera.camearInfo.alias
                  : Camera.camearInfo.name
              }}</b>
            </div>
            <div class="img-box">
              <template v-if="TreeDataPool.treeActiveName == 'camera'">
@@ -132,21 +160,25 @@
                ></polygon-canvas>
              </template>
              <template v-else>
                <div style="width:100%" v-loading="getStackFileLoading">
                <div style="width: 100%" v-loading="getStackFileLoading">
                  <swiper
                    ref="swiper"
                    :auto-update="true"
                    :options="canvasSwiperOption"
                    @slideChange="swiperSlideChange"
                    class="swiper-box-container2"
                    style="width:100%"
                    style="width: 100%"
                  >
                    <swiper-slide v-for="(data, index) in swipercanvasData" :key="index">
                    <swiper-slide
                      v-for="(data, index) in swipercanvasData"
                      :key="index"
                    >
                      <div>
                        <b
                          class="video-title"
                          style="font-size:14px;margin-top:-10px"
                        >{{ data.name }}</b>
                          style="font-size: 14px; margin-top: -10px"
                          >{{ data.name }}</b
                        >
                        <polygon-canvas
                          class="cavas"
                          ref="canvas"
@@ -172,7 +204,7 @@
                  </swiper>
                  <div
                    class="swiper-local-prev"
                    v-show="swipercanvasData.length>1"
                    v-show="swipercanvasData.length > 1"
                    @click="prevClick"
                  >
                    <div class="icon-btn" slot="button-prev">
@@ -181,7 +213,7 @@
                  </div>
                  <div
                    class="swiper-local-next"
                    v-show="swipercanvasData.length>1"
                    v-show="swipercanvasData.length > 1"
                    @click="nextClick"
                  >
                    <div class="icon-btn" slot="button-next">
@@ -192,12 +224,16 @@
              </template>
            </div>
          </div>
          <div style="float:left;width:calc(10% - 90px);height:100%;"></div>
          <div style="float: left; width: calc(10% - 90px); height: 100%"></div>
          <div
            class="time-box"
            style="width:calc(90% + 90px - 576px);overflow-x:auto;overflow-y:hidden"
            style="
              width: calc(90% + 90px - 576px);
              overflow-x: auto;
              overflow-y: hidden;
            "
          >
            <p style="text-align:left;padding: 10px;box-sizing: border-box">
            <p style="text-align: left; padding: 10px; box-sizing: border-box">
              <b style="font-size: 14px">时间段</b>
            </p>
            <time-slider ref="timeSlider" :type="'sep'" />
@@ -219,13 +255,9 @@
<script>
import { savePolygon } from "@/api/polygon";
import {
  pasteRules
} from '@/api/task';
import { pasteRules } from "@/api/task";
import {
  saveCameraScene,
} from '@/api/scene'
import { saveCameraScene } from "@/api/scene";
import { changeRunType } from "@/api/pollConfig";
import { findAllFileByStackId } from "@/api/localVedio";
@@ -243,19 +275,21 @@
    polygonCanvas,
    Sysinfo,
    SceneRule,
    SlideScene
    SlideScene,
  },
  directives: {
    focus: {
      inserted: function (el) {
        el.querySelector('input').focus()
      }
    }
        el.querySelector("input").focus();
      },
    },
  },
  computed: {
    cameraType() {
      return this.TreeDataPool.treeActiveName === 'camera' ? "camera" : "dataStack"
    }
      return this.TreeDataPool.treeActiveName === "camera"
        ? "camera"
        : "dataStack";
    },
  },
  data() {
    return {
@@ -268,12 +302,12 @@
        grabCursor: true,
        pagination: {
          el: ".swiper-pagination",
          type: "fraction"
          type: "fraction",
        },
        navigation: {
          nextEl: ".swiper-local-next",
          prevEl: ".swiper-local-prev"
        }
          prevEl: ".swiper-local-prev",
        },
      },
      // swiperOption: {
      //   slidesPerView: 5,
@@ -294,7 +328,7 @@
      showCanvas: true,
      canvasWidth: 576,
      canvasHeight: 324,
      stackId: '',
      stackId: "",
      swiperIndex: 0,
      swipercanvasData: [],
      stackFilesPage: 1,
@@ -304,10 +338,9 @@
  mounted() {
    this.mockAsync();
    this.PollData.statistics();
  },
  watch: {
    'Camera.cameraId': {
    "Camera.cameraId": {
      handler(n, o) {
        if (n) {
          if (this.TreeDataPool.treeActiveName == "dataStack") {
@@ -316,12 +349,12 @@
            this.stackId = n;
            if (this.stackId) {
              this.swipercanvasData = [];
              this.getStackFiles()
              this.getStackFiles();
            }
          }
        }
      }
    }
      },
    },
  },
  methods: {
    prevClick() {
@@ -331,11 +364,10 @@
          this.getStackFiles(true);
        } else {
          this.$message({
            type: 'info',
            message: '当前已是第一页'
            type: "info",
            message: "当前已是第一页",
          });
        }
      }
    },
    nextClick() {
@@ -347,41 +379,53 @@
    getStackFiles(onClick = false) {
      this.getStackFileLoading = true;
      let _this = this;
      findAllFileByStackId({ name: '', stackId: this.stackId, page: this.stackFilesPage, size: this.stackFilesSize, type: 0 }).then(res => {
        if (res && res.success) {
          if (res.data.dataList.length > 0) {
            this.swipercanvasData = [];
            this.swipercanvasData = res.data.dataList.map(item => {
              return {
                name: item.name,
                stackId: item.stack_id,
                baseImg: item.type == 2 ? `/files/${item.path.substr(item.path.lastIndexOf('/') + 1)}` : item.snapshot_url,
                type: item.type,
                id: item.id,
                loading: false
              }
            });
            this.swiperIndex = 0;
            this.$refs.swiper.swiper.activeIndex = 0;
          } else {
            if (onClick) {
              this.$message({
                type: 'warning',
                message: '已无更多数据!'
      findAllFileByStackId({
        name: "",
        stackId: this.stackId,
        page: this.stackFilesPage,
        size: this.stackFilesSize,
        type: 0,
      })
        .then((res) => {
          if (res && res.success) {
            if (res.data.dataList.length > 0) {
              this.swipercanvasData = [];
              this.swipercanvasData = res.data.dataList.map((item) => {
                return {
                  name: item.name,
                  stackId: item.stack_id,
                  baseImg:
                    item.type == 2
                      ? `/files/${item.path.substr(
                          item.path.lastIndexOf("/") + 1
                        )}`
                      : item.snapshot_url,
                  type: item.type,
                  id: item.id,
                  loading: false,
                };
              });
              this.swiperIndex = 0;
              this.$refs.swiper.swiper.activeIndex = 0;
            } else {
              if (onClick) {
                this.$message({
                  type: "warning",
                  message: "已无更多数据!",
                });
              }
            }
          } else {
            this.$message({
              type: "error",
              message: "数据请求失败,请稍后重试!",
            });
          }
        } else {
          this.$message({
            type: 'error',
            message: '数据请求失败,请稍后重试!'
          });
        }
        this.getStackFileLoading = false;
      }).catch(e => {
        this.getStackFileLoading = false;
      });
          this.getStackFileLoading = false;
        })
        .catch((e) => {
          this.getStackFileLoading = false;
        });
    },
    swiperSlideChange() {
      this.swiperIndex = this.$refs.swiper.swiper.activeIndex;
@@ -389,7 +433,11 @@
    mockAsync() {
      setTimeout(() => {
        this.mockSceneData = [
          { scenename: "name1", id: 1, icon: ["iconrenlianjiance", "icongetijingzhi"] },
          {
            scenename: "name1",
            id: 1,
            icon: ["iconrenlianjiance", "icongetijingzhi"],
          },
          { scenename: "name2", id: 2, icon: ["iconchouyan-copy"] },
          {
            scenename: "name3",
@@ -398,19 +446,23 @@
              "iconrenshukouzhao",
              "iconchouyan-copy",
              "iconrenlianjiance",
              "icongetijingzhi"
            ]
              "icongetijingzhi",
            ],
          },
          {
            scenename: "name4",
            id: 4,
            icon: ["iconchouyan-copy", "iconrenlianjiance", "icongetijingzhi"]
            icon: ["iconchouyan-copy", "iconrenlianjiance", "icongetijingzhi"],
          },
          { scenename: "name5", id: 5, icon: ["icongetijingzhi"] },
          { scenename: "name6", id: 6, icon: ["iconrenshukouzhao", "icongetijingzhi"] },
          { scenename: "name7", id: 7, icon: ["iconrenlianjiance"] }
          {
            scenename: "name6",
            id: 6,
            icon: ["iconrenshukouzhao", "icongetijingzhi"],
          },
          { scenename: "name7", id: 7, icon: ["iconrenlianjiance"] },
        ];
      }, 3000)
      }, 3000);
    },
    drawBaseImg() {
      if (Array.isArray(this.$refs.canvas)) {
@@ -424,51 +476,55 @@
    getCanvasData(data) {
      let polyon = { ...data };
      polyon.camera_id = this.Camera.cameraId;
      savePolygon(polyon).then(rsp => {
      savePolygon(polyon).then((rsp) => {
        this.Camera.getPolygon();
        //this.Camera.getCameraTask();
      });
    },
    refresh(url) {
      this.Camera.baseImg = url
      this.Camera.baseImg = url;
    },
    // 初始化摄像机信息,父组件调用
    async initCameraData(id) {
    async initCameraData(id, type) {
      this.Camera = new VideoRuleData();
      console.log("121212");
      console.log(type);
      if (id && id !== "") {
        this.loading = false;
        this.Camera.cameraId = id;
        await this.Camera.update();
        if (type === 1) {
          await this.Camera.update(true);
        } else {
          await this.Camera.update();
        }
      }
      this.$refs.timeSlider.activeTab = this.VideoManageData.TimeRules[0].id;
      this.showSysInfo = true
      this.showSysInfo = true;
      // 判断正在执行实时或者轮询任务
      this.PollData.CameraList.forEach(element => {
      this.PollData.CameraList.forEach((element) => {
        if (element.id === this.Camera.cameraId) {
          this.runType = element.run_type;
        }
      })
      });
    },
    saveSceneRule(groupRule) {
      const payload = { ...groupRule }
      const payload = { ...groupRule };
      payload.cameraIds = [this.Camera.cameraId];
      let _this = this;
      saveCameraScene(payload).then(rsp => {
      saveCameraScene(payload).then((rsp) => {
        if (rsp && rsp.success) {
          this.Camera.update();
          this.$notify({
            type: "success",
            message: "策略保存成功!"
            message: "策略保存成功!",
          });
          //刷新左侧树
          _this.$root.$children[0].$children[0].querySearchAsync('camera')
          _this.$root.$children[0].$children[0].querySearchAsync("camera");
        }
      });
    },
@@ -476,90 +532,93 @@
      this.Camera.update();
    },
    changeLoading(params) {
      this.loading = params
      this.loading = params;
    },
    //是否进行视频分析处理
    pollEnable(row) {
      let val = 0
      let val = 0;
      if (row) {
        if (this.PollData.RealTimeSum < this.PollData.channelTotal) {
          this.Camera.dealWay = true
          val = 1
          this.Camera.dealWay = true;
          val = 1;
        } else {
          this.Camera.dealWay = false
          val = 0
          this.Camera.dealWay = false;
          val = 0;
        }
      } else {
        this.Camera.dealWay = false
        val = -1
        this.Camera.dealWay = false;
        val = -1;
      }
      if (this.Camera.cameraId && this.Camera.cameraId !== undefined) {
      debugger
        changeRunType({ camera_ids: [this.Camera.cameraId], run_type: val }).then(
          rsp => {
            if (rsp && rsp.success) {
              this.$notify({
                type: "success",
                message: "配置成功"
              });
            } else {
              this.$notify({
                type: "error",
                message: "配置失败"
              });
            }
            this.TreeDataPool.fetchTreeData();
        debugger;
        changeRunType({
          camera_ids: [this.Camera.cameraId],
          run_type: val,
        }).then((rsp) => {
          if (rsp && rsp.success) {
            this.$notify({
              type: "success",
              message: "配置成功",
            });
          } else {
            this.$notify({
              type: "error",
              message: "配置失败",
            });
          }
        );
          this.TreeDataPool.fetchTreeData();
        });
      }
      this.PollData.statisticTaskInfo();
    },
    //实时、轮询切换
    changePoll(row) {
      //判断是新增还是更新
      debugger
      debugger;
      if (this.Camera.cameraId && this.Camera.cameraId !== undefined) {
        if (this.PollData.RealTimeSum < this.PollData.channelTotal) {
          if (row.value) {
            this.Camera.dealWay = true
            this.Camera.dealWay = true;
          } else {
            this.Camera.dealWay = false
            this.Camera.dealWay = false;
          }
      debugger
          changeRunType({ camera_ids: [this.Camera.cameraId], run_type: this.Camera.dealWay ? 1 : 0 }).then(
            rsp => {
          debugger;
          changeRunType({
            camera_ids: [this.Camera.cameraId],
            run_type: this.Camera.dealWay ? 1 : 0,
          }).then((rsp) => {
            if (rsp && rsp.success) {
              this.$notify({
                type: "success",
                message: "配置成功",
              });
            } else {
              this.$notify({
                type: "error",
                message: "配置失败",
              });
            }
          });
        } else {
          if (this.Camera.dealWay) {
            this.Camera.dealWay = false;
            debugger;
            changeRunType({
              camera_ids: [this.Camera.cameraId],
              run_type: this.Camera.dealWay ? 1 : 0,
            }).then((rsp) => {
              if (rsp && rsp.success) {
                this.$notify({
                  type: "success",
                  message: "配置成功"
                  message: "配置成功",
                });
              } else {
                this.$notify({
                  type: "error",
                  message: "配置失败"
                  message: "配置失败",
                });
              }
            }
          );
        } else {
          if (this.Camera.dealWay) {
            this.Camera.dealWay = false
      debugger
            changeRunType({ camera_ids: [this.Camera.cameraId], run_type: this.Camera.dealWay ? 1 : 0 }).then(
              rsp => {
                if (rsp && rsp.success) {
                  this.$notify({
                    type: "success",
                    message: "配置成功"
                  });
                } else {
                  this.$notify({
                    type: "error",
                    message: "配置失败"
                  });
                }
              }
            );
            });
          }
        }
        this.TreeDataPool.fetchTreeData();
@@ -572,41 +631,43 @@
      this.TreeDataPool.ctrlCameraName = this.Camera.cameraName;
      this.$notify({
        type: "success",
        message: "复制算法成功!"
      })
        message: "复制算法成功!",
      });
    },
    ctrlV() {
      if (this.Camera.cameraId === this.TreeDataPool.ctrlCameraId) {
        this.$notify({
          type: "warning",
          message: "不能粘贴本摄像机的算法到本摄像机!"
        })
          message: "不能粘贴本摄像机的算法到本摄像机!",
        });
        return false;
      }
      pasteRules({
        sourceId: this.TreeDataPool.ctrlCameraId,
        targetIds: [this.Camera.cameraId]
      }).then((res) => {
        if (res && res.success) {
          this.$notify({
            type: "success",
            message: "粘贴算法成功!"
          })
          this.initCameraData(this.Camera.cameraId)
        } else {
        targetIds: [this.Camera.cameraId],
      })
        .then((res) => {
          if (res && res.success) {
            this.$notify({
              type: "success",
              message: "粘贴算法成功!",
            });
            this.initCameraData(this.Camera.cameraId);
          } else {
            this.$notify({
              type: "error",
              message: "粘贴算法失败!",
            });
          }
        })
        .catch((err) => {
          this.$notify({
            type: "error",
            message: "粘贴算法失败!"
          })
        }
      }).catch(err => {
        this.$notify({
          type: "error",
          message: "粘贴算法失败!"
        })
      })
            message: "粘贴算法失败!",
          });
        });
    },
  }
  },
};
</script>
<style lang="scss">