| | |
| | | </template> |
| | | <script> |
| | | |
| | | import { eventPushsSave, findByEventTopic,getPushSet } from "@/api/event"; |
| | | import { eventPushsSave, findByEventTopic, getPushSet } from "@/api/event"; |
| | | import { findDictionaryByType, findDictionaryByID } from "@/api/dictionary"; |
| | | import { getTaskList } from "@/api/search"; |
| | | |
| | |
| | | } |
| | | }, |
| | | computed: { |
| | | urls () { |
| | | urls() { |
| | | return this.taskEditData.urls |
| | | } |
| | | }, |
| | | data () { |
| | | data() { |
| | | return { |
| | | taskEditData: {}, |
| | | dataList: [], |
| | |
| | | rule_values: [], |
| | | topic_arg: "", |
| | | topic_type: "", |
| | | |
| | | topicTypeOptions: {}, |
| | | topicArgOptions: {}, |
| | | operatorOptions: {}, |
| | |
| | | }, |
| | | watch: { |
| | | eventObject: { |
| | | handler (newVal, oldVal) { |
| | | handler(newVal, oldVal) { |
| | | this.taskEditData.enable = this.eventObject.enable; |
| | | if (newVal !== oldVal) { |
| | | if (this.taskEditData.id !== newVal.id) { |
| | |
| | | this.$set(this.taskEditData, "urls", []) |
| | | } |
| | | //this.taskEditData.push_set = this.eventObject.push_set; |
| | | if(!this.eventObject.push_set.length){ |
| | | if (!this.eventObject.push_set.length) { |
| | | this.$set(this.taskEditData, "push_set", this.pushFields) |
| | | }else{ |
| | | } else { |
| | | this.$set(this.taskEditData, "push_set", this.eventObject.push_set) |
| | | } |
| | | if (newVal.rules) { |
| | |
| | | deep: true |
| | | }, |
| | | tempPushSet: { |
| | | handler (n, o) { |
| | | handler(n, o) { |
| | | let _this = this; |
| | | let flag = false; |
| | | n.forEach(configObj => { |
| | |
| | | deep: true |
| | | } |
| | | }, |
| | | created () { |
| | | created() { |
| | | this.reAdd(); |
| | | }, |
| | | mounted () { |
| | | mounted() { |
| | | // 加载字典 |
| | | this.findByType(); |
| | | this.getCameras(); |
| | |
| | | this.getPushFields(); |
| | | }, |
| | | methods: { |
| | | openPushSetDialog(){ |
| | | this.pushFieldDialog=true; |
| | | openPushSetDialog() { |
| | | this.pushFieldDialog = true; |
| | | this.tempPushSet = JSON.parse(JSON.stringify(this.taskEditData.push_set)); |
| | | }, |
| | | varifyField (param) { |
| | | varifyField(param) { |
| | | var reg = /^[A-Za-z]+[0-9-_]?$/; |
| | | if (!reg.test(param.alias)) { |
| | | this.$message('请输入合法字段名'); |
| | |
| | | // }) |
| | | |
| | | }, |
| | | canclePushFieldSet(){ |
| | | canclePushFieldSet() { |
| | | this.pushFieldDialog = false; |
| | | }, |
| | | submitPushFieldSet () { |
| | | submitPushFieldSet() { |
| | | let flag = false; |
| | | //this.pushFields.forEach(configObj => { |
| | | this.tempPushSet.forEach(configObj => { |
| | |
| | | flag = true |
| | | } |
| | | }); |
| | | if(flag){ |
| | | if (flag) { |
| | | //NO SUBMIT |
| | | return |
| | | } |
| | |
| | | console.log(this.taskEditData.push_set); |
| | | this.pushFieldDialog = false; |
| | | }, |
| | | toggleConfigCheck (configObj) { |
| | | toggleConfigCheck(configObj) { |
| | | configObj.children.forEach(child => { |
| | | child.checked = configObj.checked |
| | | }) |
| | | }, |
| | | getPushFields () { |
| | | getPushFields() { |
| | | let _this = this; |
| | | getPushSet().then(res=>{ |
| | | getPushSet().then(res => { |
| | | _this.pushFields = res.data; |
| | | }) |
| | | // this.pushFields = [ |
| | |
| | | // ]; |
| | | |
| | | }, |
| | | addUrl () { |
| | | addUrl() { |
| | | this.taskEditData.urls.push({ |
| | | checked: true, |
| | | hash: Math.random().toString(36).substr(2), |
| | | url: "", |
| | | }); |
| | | }, |
| | | delUrl (index) { |
| | | 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({ |
| | |
| | | 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) |
| | |
| | | } |
| | | }, |
| | | // 查找字典 |
| | | async findByType () { |
| | | async findByType() { |
| | | let res = await findDictionaryByType(); |
| | | if (res && res.success) { |
| | | this.dictionary = Object.assign(this.dictionary, res.data) |
| | |
| | | }) |
| | | } |
| | | }, |
| | | async getCameras () { |
| | | async getCameras() { |
| | | let rsp = await findByEventTopic({ topic: 'camera', type: 'name' }); |
| | | if (rsp && rsp.success) { |
| | | this.dictionary['camera'] = rsp.data |
| | |
| | | }) |
| | | } |
| | | }, |
| | | async getTasks () { |
| | | async getTasks() { |
| | | this.dictionary['task'] = [] |
| | | let rsp = await getTaskList(); |
| | | if (rsp && rsp.success) { |
| | |
| | | } |
| | | }, |
| | | // 新建配置 |
| | | 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; |
| | |
| | | } |
| | | }); |
| | | }, |
| | | selectArg (rule, resetNext = false) { |
| | | selectArg(rule, resetNext = false) { |
| | | let argInfo = rule.topicArgOptions.filter(arg => { |
| | | return arg.value === rule.topic_arg |
| | | }) |
| | |
| | | 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(",") |
| | | |
| | | // 处理 全部/空 |
| | | 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) { |
| | |
| | | rule.rule_values = []; |
| | | } |
| | | }, |
| | | selectValue (rule, val) { |
| | | 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; |
| | | }); |
| | |
| | | return s.name; |
| | | }, |
| | | // 清空重新新增 |
| | | reAdd () { |
| | | reAdd() { |
| | | this.taskEditData = { |
| | | id: "", |
| | | name: "", |
| | |
| | | }; |
| | | this.dataList = []; |
| | | }, |
| | | onCancle () { |
| | | onCancle() { |
| | | this.$emit('onCancle') |
| | | } |
| | | } |