ZZJ
2021-11-09 ccee429d379e0108b7445f72ade8d97c110a6fb3
src/pages/datapush/index/RightEvent.vue
@@ -186,7 +186,7 @@
      </div>
      <div class="config-item">
        <b>推送字段</b>
        <el-button type="primary" size="mini" @click="pushFieldDialog=true">设置</el-button>
        <el-button type="primary" size="mini" @click="openPushSetDialog">设置</el-button>
      </div>
      <div class="save-btn">
        <el-button type="info" size="small" @click="onCancle" style="color:#222">取消</el-button>
@@ -203,10 +203,10 @@
      <div slot="title" class="slot-title">
        <p>请选择想要推送的字段</p>
        <div class="right">
          <el-checkbox v-model="allFieldChecked"></el-checkbox>
          <el-checkbox v-model="allFieldChecked" @change="allCheckChange"></el-checkbox>
        </div>
      </div>
      <div class="check-area" v-for="configObj in pushFields" :key="configObj.id">
      <div class="check-area" v-for="configObj in tempPushSet" :key="configObj.id">
        <div class="header">
          <div class="title">{{configObj.name}}</div>
          <div class="right">
@@ -215,7 +215,7 @@
        </div>
        <div class="flex-box flex-wrap">
          <div class="param flex-box" v-for="param in configObj.children" :key="param.id">
            <el-checkbox v-model="param.checked"></el-checkbox>
            <el-checkbox v-model="param.checked" @change="checkChildren"></el-checkbox>
            <span class="param-name">{{param.name}}</span>
            <el-input
              v-model="param.alias"
@@ -228,7 +228,7 @@
        </div>
      </div>
      <div slot="footer" class="text-center">
        <el-button size="small">取消</el-button>
        <el-button size="small" @click="canclePushFieldSet">取消</el-button>
        <el-button
          size="small"
          type="primary"
@@ -241,7 +241,7 @@
</template>
<script>
import { eventPushsSave, findByEventTopic } from "@/api/event";
import { eventPushsSave, findByEventTopic, getPushSet } from "@/api/event";
import { findDictionaryByType, findDictionaryByID } from "@/api/dictionary";
import { getTaskList } from "@/api/search";
@@ -256,11 +256,11 @@
    }
  },
  computed: {
    urls () {
    urls() {
      return this.taskEditData.urls
    }
  },
  data () {
  data() {
    return {
      taskEditData: {},
      dataList: [],
@@ -277,7 +277,6 @@
        rule_values: [],
        topic_arg: "",
        topic_type: "",
        topicTypeOptions: {},
        topicArgOptions: {},
        operatorOptions: {},
@@ -285,6 +284,7 @@
        ruleValueOptions: []
      },
      pushFieldDialog: false,
      tempPushSet: [],
      pushFields: [],
      allFieldChecked: false,
      disabledPushFieldSet: true,
@@ -292,7 +292,7 @@
  },
  watch: {
    eventObject: {
      handler (newVal, oldVal) {
      handler(newVal, oldVal) {
        this.taskEditData.enable = this.eventObject.enable;
        if (newVal !== oldVal) {
          if (this.taskEditData.id !== newVal.id) {
@@ -313,6 +313,12 @@
            if (!this.taskEditData.urls) {
              this.$set(this.taskEditData, "urls", [])
            }
            //this.taskEditData.push_set = this.eventObject.push_set;
            if (!this.eventObject.push_set.length) {
              this.$set(this.taskEditData, "push_set", this.pushFields)
            } else {
              this.$set(this.taskEditData, "push_set", this.eventObject.push_set)
            }
            if (newVal.rules) {
              newVal.rules.forEach(element => {
                let newRule = Object.assign(JSON.parse(JSON.stringify(this.baseRule)), element)
@@ -326,8 +332,8 @@
      },
      deep: true
    },
    pushFields: {
      handler (n, o) {
    tempPushSet: {
      handler(n, o) {
        let _this = this;
        let flag = false;
        n.forEach(configObj => {
@@ -352,10 +358,10 @@
      deep: true
    }
  },
  created () {
  created() {
    this.reAdd();
  },
  mounted () {
  mounted() {
    // 加载字典
    this.findByType();
    this.getCameras();
@@ -363,11 +369,36 @@
    this.getPushFields();
  },
  methods: {
    varifyField (param) {
    openPushSetDialog() {
      this.pushFieldDialog = true;
      this.tempPushSet = JSON.parse(JSON.stringify(this.taskEditData.push_set));
      this.checkFlag()
    },
    checkFlag() {
      // debugger
      let flag = true
      this.tempPushSet.forEach(item => {
        if (item.checked == false) {
          flag = false
        }
      });
      this.allFieldChecked = flag
    },
    checkChildren(val) {
      console.log(val, 12121);
      if (val == false) {
        this.allFieldChecked = false
      } else if (val == true && this.allFieldChecked == false) {
        this.$nextTick(() => {
          this.checkFlag()
        })
      }
    },
    varifyField(param) {
      var reg = /^[A-Za-z]+[0-9-_]?$/;
      if (!reg.test(param.alias)) {
        this.$message('请输入合法字段名');
        debugger
        param.error = true;
      } else {
        param.error = false;
@@ -377,9 +408,22 @@
      // })
    },
    submitPushFieldSet () {
    canclePushFieldSet() {
      this.pushFieldDialog = false;
    },
    allCheckChange(val) {
      this.tempPushSet.forEach(function (item) {
        item.checked = val
        item.children.forEach(function (child) {
          child.checked = val
        })
      })
    },
    submitPushFieldSet() {
      let flag = false;
      this.pushFields.forEach(configObj => {
      //this.pushFields.forEach(configObj => {
      this.tempPushSet.forEach(configObj => {
        let errorOne = configObj.children.find(param => param.checked && param.error);
        if (errorOne) {
          this.$notify({
@@ -389,43 +433,55 @@
          flag = true
        }
      });
      if(flag){
      if (flag) {
        //NO SUBMIT
        return
      }
      alert('submit')
      this.taskEditData.push_set = this.tempPushSet;
      this.pushFieldDialog = false;
      // 保存规则
      this.eventPushsSave()
    },
    toggleConfigCheck (configObj) {
    toggleConfigCheck(configObj) {
      configObj.children.forEach(child => {
        child.checked = configObj.checked
      })
      this.checkFlag()
    },
    getPushFields () {
      this.pushFields = [
        {          id: 'sxjxx', name: '摄像机信息', checked: false, alias: '',
          children: [
            { name: '摄像机ID', checked: false, alias: 'cameraID', id: 'cameraID', children: null },
            { name: '摄像机名称', checked: false, alias: 'cameraName', id: 'cameraName', children: null },
            { name: '摄像机地址', checked: false, alias: 'cameraAddr', id: 'cameraAddr', children: null },
            { name: '摄像机址', checked: false, alias: 'cameraAdr', id: 'cameraAdr', children: null }
          ]        },
        {          id: 'cjxx', name: '场景信息', checked: false, alias: '',
          children: [{ name: '场景ID', checked: false, alias: 'taskId', id: 'tskId', children: null }]        },
      ];
    getPushFields() {
      let _this = this;
      getPushSet().then(res => {
        _this.pushFields = res.data;
      })
      // this.pushFields = [
      //   {          id: 'sxjxx', name: '摄像机信息', checked: false, alias: '',
      //     children: [
      //       { name: '摄像机ID', checked: false, alias: 'cameraID', id: 'cameraID', children: null },
      //       { name: '摄像机名称', checked: false, alias: 'cameraName', id: 'cameraName', children: null },
      //       { name: '摄像机地址', checked: false, alias: 'cameraAddr', id: 'cameraAddr', children: null },
      //       { name: '摄像机址', checked: false, alias: 'cameraAdr', id: 'cameraAdr', children: null }
      //     ]        },
      //   {          id: 'cjxx', name: '场景信息', checked: false, alias: '',
      //     children: [{ name: '场景ID', checked: false, alias: 'taskId', id: 'tskId', children: null }]        },
      // ];
    },
    addUrl () {
    addUrl() {
      this.taskEditData.urls.push({
        checked: true,
        hash: Math.random().toString(36).substr(2),
        url: "",
      });
    },
    delUrl (index) {
      this.$set(this.taskEditData.urls, index, this.baseRule)
      this.taskEditData.urls.splice(index, 1)
    delUrl(index) {
      this.$set(this.taskEditData.urls, index, this.baseRule);
      this.taskEditData.urls.splice(index, 1);
    },
    // 保存
    async eventPushsSave () {
    async eventPushsSave() {
      // 判断保存的ip是否符合格式要求
      if (this.taskEditData.urls.length < 1) {
        this.$notify({
@@ -458,10 +514,16 @@
          str += ' = ';
        }
        str += i.rule_value === "all*all" ? "全部" : i.rule_value;
        if (i.rule_value === "all*all") {
          str += "全部";
        } else if (i.rule_value === "null*null") {
          str += "空";
        } else {
          str += i.rule_value;
        }
        if (str.length > 0) {
          ruleDesc.push(str)
          ruleDesc.push(str);
        }
      });
      // 处理规则列表数据结构
@@ -486,7 +548,8 @@
        time_end: this.taskEditData.time[1],
        urls: this.taskEditData.urls,
        is_satisfy_all: this.taskEditData.radioValue === "1",
        link_type: this.taskEditData.lineWay
        link_type: this.taskEditData.lineWay,
        push_set: this.taskEditData.push_set
      };
      let res = await eventPushsSave(json);
@@ -500,7 +563,7 @@
      }
    },
    // 查找字典
    async findByType () {
    async findByType() {
      let res = await findDictionaryByType();
      if (res && res.success) {
        this.dictionary = Object.assign(this.dictionary, res.data)
@@ -514,10 +577,10 @@
        })
      }
    },
    async getCameras () {
    async getCameras() {
      let rsp = await findByEventTopic({ topic: 'camera', type: 'name' });
      if (rsp && rsp.success) {
        this.dictionary['camera'] = rsp.data
        this.dictionary['camera'] = rsp.data;
      }
      rsp = await findByEventTopic({ topic: 'dbtable' });
@@ -530,7 +593,7 @@
        })
      }
    },
    async getTasks () {
    async getTasks() {
      this.dictionary['task'] = []
      let rsp = await getTaskList();
      if (rsp && rsp.success) {
@@ -541,61 +604,78 @@
              value: task.name,
              name: task.name
            })
            hash[task.name] = true
            hash[task.name] = true;
          }
        })
      }
    },
    // 新建配置
    createSet () {
    createSet() {
      this.dataList.push(JSON.parse(JSON.stringify(this.baseRule)));
    },
    cleanSet () {
    cleanSet() {
      this.dataList.splice(0, this.dataList.length);
    },
    // 添加子规则
    addRule () {
    addRule() {
      this.dataList.push(JSON.parse(JSON.stringify(this.baseRule)));
    },
    // 删除子规则
    delRule (index) {
    delRule(index) {
      this.dataList.splice(index, 1);
    },
    // 规则中下拉框的选择回调
    selectTopic (rule, resetNext = false) {
    selectTopic(rule, resetNext = false) {
      rule.topicTypeOptions.forEach(element => {
        if (element.value === rule.topic_type) {
          rule.topicArgOptions = element.children;
          if (resetNext) {
            rule.topic_arg = rule.topicArgOptions[0].value
            this.selectArg(rule, resetNext)
            rule.topic_arg = rule.topicArgOptions[0].value;
            this.selectArg(rule, resetNext);
          }
        }
      });
    },
    selectArg (rule, resetNext = false) {
    selectArg(rule, resetNext = false) {
      debugger
      let argInfo = rule.topicArgOptions.filter(arg => {
        return arg.value === rule.topic_arg
        return arg.value === rule.topic_arg;
      })
      if (argInfo.length > 0) {
        let desc = argInfo[0].description.split(",")
        let desc = argInfo[0].description.split(",");
        if (desc.length > 0) {
          rule.operatorTypeOpionts = this.dictionary.EVENTTYPECOMPUTE.filter(el => {
            return desc.indexOf(el.value) >= 0
            return desc.indexOf(el.value) >= 0;
          })
        }
      }
      if (resetNext) {
        rule.operator_type = rule.operatorTypeOpionts[rule.operatorTypeOpionts.length - 1].value
        this.selectOperator(rule, resetNext)
        rule.operator_type = rule.operatorTypeOpionts[rule.operatorTypeOpionts.length - 1].value;
        this.selectOperator(rule, resetNext);
      }
    },
    selectOperator (rule, resetNext = false) {
    selectOperator(rule, resetNext = false) {
      if (rule.operator_type === "option") {
        rule.ruleValueOptions = this.dictionary[rule.topic_type] ? this.dictionary[rule.topic_type] : []
        rule.rule_values = rule.rule_value.split(",")
        rule.ruleValueOptions = this.dictionary[rule.topic_type] ? this.dictionary[rule.topic_type] : [];
        if (rule.rule_value != "") {
          rule.rule_values = rule.rule_value.split(",");
        }
        // 处理 全部/空
        for (let i = 0; i < rule.rule_values.length; i++) {
          if (rule.rule_values[i] === "all*all") {
            rule.rule_values[i] = "全部";
          }
          if (rule.rule_values[i] === "null*null") {
            rule.rule_values[i] = "空";
          }
        }
        this.setOptionsDisable(rule);
      }
      if (resetNext) {
@@ -603,11 +683,48 @@
        rule.rule_values = [];
      }
    },
    selectValue (rule, val) {
      rule.rule_value = val.join(",")
    selectValue(rule, val) {
      if (rule.operator_type === "option") {
        this.setOptionsDisable(rule);
        if (val.indexOf("全部") >= 0) {
          rule.rule_value = "all*all";
          return;
        }
        if (val.indexOf("空") >= 0) {
          rule.rule_value = "null*null";
          return;
        }
      }
      rule.rule_value = val.join(",");
    },
    setOptionsDisable(rule) {
      let isAllSelect = (rule.rule_values.indexOf("全部") >= 0);
      let isNullSelect = (rule.rule_values.indexOf("空") >= 0);
      rule.ruleValueOptions.forEach(opt => {
        if (!rule.rule_values.length) {
          opt.disabled = false;
          return
        }
        if (opt.name === "全部") {
          opt.disabled = !isAllSelect;
          return
        }
        if (opt.name === "空") {
          opt.disabled = !isNullSelect;
          return
        }
        opt.disabled = (isAllSelect || isNullSelect);
      })
    },
    // 根据value返回对应的name
    getNameByValue (arr, value) {
    getNameByValue(arr, value) {
      let s = arr.find(item => {
        return item.value === value;
      });
@@ -615,7 +732,7 @@
      return s.name;
    },
    // 清空重新新增
    reAdd () {
    reAdd() {
      this.taskEditData = {
        id: "",
        name: "",
@@ -640,11 +757,12 @@
          }
        ],
        radioValue: "1",
        eventTxt: ""
        eventTxt: "",
        push_set: this.pushFields
      };
      this.dataList = [];
    },
    onCancle () {
    onCancle() {
      this.$emit('onCancle')
    }
  }