zhangzengfei
2020-09-29 19ccf9686a266fe617b1f59e3b909e5ef2a57a9a
完善事件推送
1个文件已修改
148 ■■■■ 已修改文件
src/pages/datapush/index/RightEvent.vue 148 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/datapush/index/RightEvent.vue
@@ -3,12 +3,17 @@
    <div class="s-right-config">
      <el-form>
        <el-form-item label="名称">
          <el-input v-model="eventData.name" placeholder="请输入名称" size="small" style="width:400px"></el-input>
          <el-input
            v-model="taskEditData.name"
            placeholder="请输入名称"
            size="small"
            style="width:400px"
          ></el-input>
        </el-form-item>
        <el-form-item label="时间">
          <el-date-picker
            v-model="eventData.time"
            v-model="taskEditData.time"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
@@ -41,9 +46,9 @@
        </div>
        <el-form-item label="联动方式" style="margin-top: 20px;width:100">
          <el-select v-model="eventData.lineWay" placeholder="请选择" size="small">
          <el-select v-model="taskEditData.lineWay" placeholder="请选择" size="small">
            <el-option
              v-for="item in eventData.lineOptions"
              v-for="item in taskEditData.lineOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
@@ -52,8 +57,8 @@
        </el-form-item>
        <el-form-item label="标签">
          <el-radio v-model="eventData.radioValue" label="1">满足全部</el-radio>
          <el-radio v-model="eventData.radioValue" label="2">满足任意一个</el-radio>
          <el-radio v-model="taskEditData.radioValue" label="1">满足全部</el-radio>
          <el-radio v-model="taskEditData.radioValue" label="2">满足任意一个</el-radio>
        </el-form-item>
      </el-form>
    </div>
@@ -177,7 +182,7 @@
      <div class="rule-title2">
        <b>规则</b>
        <div class="div-border" v-html="eventData.eventTxt"></div>
        <div class="div-border" v-html="taskEditData.eventTxt"></div>
      </div>
      <div class="save-btn">
        <el-button type="info" size="small" @click="onCancle" style="color:#222">取消</el-button>
@@ -204,59 +209,12 @@
  },
  computed: {
    urls() {
      return this.eventData.urls
    },
    ips() {
      return this.eventData.urls.filter(item => {
        return item.type === 'ip';
      })
    },
    domains() {
      return this.eventData.urls.filter(item => {
        return item.type === 'domain';
      })
    }
  },
  watch: {
    eventObject: {
      handler(newVal, oldVal) {
        this.eventData.enable = this.eventObject.enable;
        if (newVal !== oldVal) {
          if (this.eventData.id !== newVal.id) {
            this.dataList = [];
            this.eventData.id = newVal.id;
            this.eventData.name = newVal.name;
            this.eventData.time = [
              this.eventObject.time_start,
              this.eventObject.time_end
            ];
            this.eventData.serverIp = newVal.ip_ports;
            this.eventData.urls = newVal.urls;
            this.eventData.lineWay = newVal.link_type;
            this.eventData.eventTxt = newVal.rule_text;
            this.eventData.radioValue = newVal.is_satisfy_all ? "1" : "2";
            if (!this.eventData.urls) {
              this.$set(this.eventData, "urls", [])
            }
            if (newVal.rules) {
              newVal.rules.forEach(element => {
                let newRule = Object.assign(JSON.parse(JSON.stringify(this.baseRule)), element)
                this.dataList.push(newRule)
                this.selectTopic(newRule);
                this.selectOperator(newRule);
              })
            }
          }
        }
      },
      deep: true
      return this.taskEditData.urls
    }
  },
  data() {
    return {
      eventData: {},
      taskEditData: {},
      dataList: [],
      dictionary: [],
      cameras: [],
@@ -280,6 +238,43 @@
      },
    };
  },
  watch: {
    eventObject: {
      handler(newVal, oldVal) {
        this.taskEditData.enable = this.eventObject.enable;
        if (newVal !== oldVal) {
          if (this.taskEditData.id !== newVal.id) {
            this.dataList = [];
            this.taskEditData.id = newVal.id;
            this.taskEditData.name = newVal.name;
            this.taskEditData.time = [
              this.eventObject.time_start,
              this.eventObject.time_end
            ];
            this.taskEditData.serverIp = newVal.ip_ports;
            this.taskEditData.urls = newVal.urls;
            this.taskEditData.lineWay = newVal.link_type;
            this.taskEditData.eventTxt = newVal.rule_text;
            this.taskEditData.radioValue = newVal.is_satisfy_all ? "1" : "2";
            if (!this.taskEditData.urls) {
              this.$set(this.taskEditData, "urls", [])
            }
            if (newVal.rules) {
              newVal.rules.forEach(element => {
                let newRule = Object.assign(JSON.parse(JSON.stringify(this.baseRule)), element)
                this.dataList.push(newRule)
                this.selectTopic(newRule);
                this.selectOperator(newRule);
              })
            }
          }
        }
      },
      deep: true
    }
  },
  created() {
    this.reAdd();
  },
@@ -291,28 +286,28 @@
  },
  methods: {
    addUrl() {
      this.eventData.urls.push({
      this.taskEditData.urls.push({
        checked: true,
        hash: Math.random().toString(36).substr(2),
        url: "",
      });
    },
    delUrl(index) {
      this.$set(this.eventData.urls, index, this.baseRule)
      this.eventData.urls.splice(index, 1)
      this.$set(this.taskEditData.urls, index, this.baseRule)
      this.taskEditData.urls.splice(index, 1)
    },
    // 保存
    async eventPushsSave() {
      // 判断保存的ip是否符合格式要求
      if (this.eventData.urls.length < 1) {
      if (this.taskEditData.urls.length < 1) {
        this.$notify({
          type: "warning",
          message: "请配置至少一台推送服务器"
        });
        return;
      }
      for (let i = 0; i < this.eventData.urls.length; i++) {
        if (this.eventData.urls[i].url.length < 1) {
      for (let i = 0; i < this.taskEditData.urls.length; i++) {
        if (this.taskEditData.urls[i].url.length < 1) {
          this.$notify({
            type: "warning",
            message: "接口URL地址不允许为空"
@@ -353,22 +348,22 @@
      });
      let json = {
        enable: this.eventData.enable,
        id: this.eventData.id,
        ip_ports: this.eventData.serverIp,
        name: this.eventData.name,
        enable: this.taskEditData.enable,
        id: this.taskEditData.id,
        ip_ports: this.taskEditData.serverIp,
        name: this.taskEditData.name,
        rule_text: ruleDesc.join("<br/>"),
        rules: ruleList,
        time_start: this.eventData.time[0],
        time_end: this.eventData.time[1],
        urls: this.eventData.urls,
        is_satisfy_all: this.eventData.radioValue === "1",
        link_type: this.eventData.lineWay
        time_start: this.taskEditData.time[0],
        time_end: this.taskEditData.time[1],
        urls: this.taskEditData.urls,
        is_satisfy_all: this.taskEditData.radioValue === "1",
        link_type: this.taskEditData.lineWay
      };
      let res = await eventPushsSave(json);
      if (res && res.success) {
        this.eventData.eventTxt = ruleDesc.join("<br/>");
        this.taskEditData.eventTxt = ruleDesc.join("<br/>");
        this.$emit("updateList", res.data.id);
        this.$notify({
          type: "success",
@@ -383,7 +378,12 @@
        this.dictionary = Object.assign(this.dictionary, res.data)
        this.baseRule.topicTypeOptions = this.dictionary.EVENTRULETOPIC
        this.baseRule.operatorTypeOpionts = this.dictionary.EVENTTYPECOMPUTE
        this.dictionary['alarmLevel'] = this.dictionary.ALARMLEVEL
        this.dictionary['alarmLevel'] = this.dictionary.ALARMLEVEL.map(el => {
          return {
            name: el.name,
            value: el.name
          }
        })
      }
    },
    async getCameras() {
@@ -488,7 +488,7 @@
    },
    // 清空重新新增
    reAdd() {
      this.eventData = {
      this.taskEditData = {
        id: "",
        name: "",
        time: [