| | |
| | | <el-form-item label="告警设备" class="inline" prop="deviceFlag"> |
| | | <el-select |
| | | v-model="params.deviceFlag" placeholder="请选择告警设备" |
| | | @change="fieldChange"> |
| | | @change="deviceFlagChange"> |
| | | <el-option |
| | | v-for="item in types" :key="item.value" |
| | | :label="item.label" :value="item.value"></el-option> |
| | |
| | | </el-col> |
| | | <el-col :span="layout.span"> |
| | | <el-form-item label="告警名称" class="inline" prop="field"> |
| | | <el-select v-model="params.field" placeholder="请选择告警名称"> |
| | | <el-select |
| | | v-model="params.field" placeholder="请选择告警名称" |
| | | @change="fieldChange"> |
| | | <el-option |
| | | v-for="item in warns" :key="item.value" |
| | | :label="item.label" :value="item.value"></el-option> |
| | |
| | | </el-col> |
| | | <el-col :span="layout.span"> |
| | | <el-form-item label="告警类型" class="inline" prop="thresholdFlag"> |
| | | <el-select v-model="params.thresholdFlag" placeholder="请选择告警类型"> |
| | | <el-select |
| | | v-model="params.thresholdFlag" placeholder="请选择告警类型" |
| | | @change="thresholdFlagChange"> |
| | | <el-option |
| | | v-for="item in ranges" :key="item.value" |
| | | :label="item.label" :value="item.value"></el-option> |
| | |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="layout.span"> |
| | | <el-form-item label="告警阈值" class="inline" prop="thresholdValue"> |
| | | <el-form-item label="告警级别" class="inline" prop="level"> |
| | | <el-select |
| | | v-model="params.level" placeholder="请选择级别" |
| | | @change="levelChange"> |
| | | <el-option |
| | | v-for="item in levels" :key="item.value" |
| | | :label="item.label" :value="item.value" :disabled="item.disabled"></el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="layout.span"> |
| | | <el-form-item :label="thresholdLabel" class="inline" prop="thresholdValue"> |
| | | <el-input v-model="params.thresholdValue" placeholder="请输入告警阈值"></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="layout.span"> |
| | | <el-form-item label="告警阈值时间(s)" class="inline" prop="thresholdDuration"> |
| | | <el-input v-model="params.thresholdDuration" placeholder="请输入告警阈值时间"></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="layout.span"> |
| | | <el-form-item label="告警级别" class="inline" prop="level"> |
| | | <el-select v-model="params.level" placeholder="请选择级别"> |
| | | <el-option |
| | | v-for="item in levels" :key="item.value" |
| | | :label="item.label" :value="item.value"></el-option> |
| | | </el-select> |
| | | <el-input v-model.number="params.thresholdDuration" placeholder="请输入告警阈值时间"></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | |
| | | import ThreeBtn from "@/components/ThreeBtn"; |
| | | import {warnRules} from "@/pages/warn/js/const"; |
| | | import {getItemByValue} from "@/assets/js/tools" |
| | | import {searchWarnRange} from "@/pages/warn/js/api"; |
| | | import {addWarnRule} from "@/pages/warn/js/api"; |
| | | import { |
| | | searchWarnRange, |
| | | searchLevelList, |
| | | addWarnRule, |
| | | thresholdValueRanges, |
| | | } from "@/pages/warn/js/api"; |
| | | |
| | | export default { |
| | | name: "addWarnRule", |
| | |
| | | }, |
| | | }, |
| | | data() { |
| | | let validateThresholdValue = (rule, value, callback) => { |
| | | let ranges = this.thresholdValueRanges; |
| | | let text = "" |
| | | // 大小均不为空 |
| | | if(ranges[0] != null && ranges[1] != null) { |
| | | if(value<=ranges[0] || value>=ranges[1]) { |
| | | text = this.regText; |
| | | } |
| | | }else if(ranges[0] != null) { |
| | | if(value<=ranges[0]) { |
| | | text = this.regText; |
| | | } |
| | | }else if(ranges[1] != null) { |
| | | if(value>=ranges[1]) { |
| | | text = this.regText; |
| | | } |
| | | } |
| | | |
| | | if(text) { |
| | | callback(new Error(text)); |
| | | }else { |
| | | callback(); |
| | | } |
| | | }; |
| | | return { |
| | | layout: { |
| | | span: 12, |
| | |
| | | name: "", |
| | | status: 1, |
| | | thresholdDuration: 0, |
| | | thresholdFlag: 1, |
| | | thresholdValue: 0 |
| | | thresholdFlag: "", |
| | | thresholdValue: 0, |
| | | unit: "" |
| | | }, |
| | | rules: { |
| | | deviceFlag:[ |
| | |
| | | ], |
| | | thresholdValue: [ |
| | | { required: true, message: '请输入告警阈值', trigger: 'blur' }, |
| | | {validator: validateThresholdValue, trigger: 'blur' } |
| | | ], |
| | | }, |
| | | warns: [], |
| | | thresholdValueRanges: [null,null], |
| | | } |
| | | }, |
| | | methods: { |
| | |
| | | this.types = item.types; |
| | | } |
| | | }, |
| | | fieldChange(field) { |
| | | deviceFlagChange(deviceFlag) { |
| | | let types = this.types; |
| | | let item = getItemByValue(field, types); |
| | | // 初始化名称 |
| | | let item = getItemByValue(deviceFlag, types); |
| | | // 初始化值 |
| | | this.params.field = ""; |
| | | this.params.thresholdFlag = ""; |
| | | this.params.level = ""; |
| | | searchWarnRange(item.url).then(res=>{ |
| | | let fieldNames = []; |
| | | let fieldValues = []; |
| | |
| | | }); |
| | | }).catch(error=>{ |
| | | console.log(error); |
| | | }); |
| | | }, |
| | | fieldChange() { |
| | | // 初始化值 |
| | | this.params.thresholdFlag = ""; |
| | | this.params.level = ""; |
| | | }, |
| | | thresholdFlagChange() { |
| | | let params = this.params; |
| | | // 初始化值 |
| | | this.params.level = ""; |
| | | searchLevelList({ |
| | | deviceFlag: params.deviceFlag, |
| | | field: params.field, |
| | | thresholdFlag: params.thresholdFlag, |
| | | }).then(res=>{ |
| | | let rs = res.data; |
| | | let data = []; |
| | | if(rs.code == 1) { |
| | | data = rs.data; |
| | | } |
| | | // 遍历等级级别对于已存在的等级设置不可选中 |
| | | this.levels = this.levels.map(item=>{ |
| | | let isIn = false; |
| | | for(let i=0; i<data.length; i++) { |
| | | if(item.value == data[i]) { |
| | | isIn = true; |
| | | break; |
| | | } |
| | | } |
| | | item.disabled = isIn; |
| | | return item; |
| | | }); |
| | | }).catch(error=>{ |
| | | console.log(error); |
| | | }); |
| | | }, |
| | | levelChange() { |
| | | let params = this.params; |
| | | thresholdValueRanges({ |
| | | deviceFlag: params.deviceFlag, |
| | | field: params.field, |
| | | thresholdFlag: params.thresholdFlag, |
| | | level: params.level, |
| | | }).then(res=>{ |
| | | let rs = res.data; |
| | | let data = [null, null]; |
| | | if(rs.code == 1) { |
| | | data = rs.data; |
| | | } |
| | | // 设置告警阈值的取值区间 |
| | | this.thresholdValueRanges = data; |
| | | }).catch(error=>{ |
| | | |
| | | }); |
| | | }, |
| | | submitForm() { |
| | |
| | | this.$emit("update:visible", false); |
| | | }, |
| | | }, |
| | | computed: { |
| | | thresholdLabel() { |
| | | let params = this.params; |
| | | if(this.regText || params.unit) { |
| | | return '告警阀值('+this.regText+params.unit+')'; |
| | | }else { |
| | | return '告警阀值'; |
| | | } |
| | | |
| | | }, |
| | | regText() { |
| | | let ranges = this.thresholdValueRanges; |
| | | // 大小均不为空 |
| | | if(ranges[0] != null && ranges[1] != null) { |
| | | return "取值范围"+ranges[0]+"~"+ranges[1]; |
| | | } |
| | | if(ranges[0] != null) { |
| | | return "取值范围大于"+ranges[0]; |
| | | } |
| | | if(ranges[1] != null) { |
| | | return "取值范围小于"+ranges[1]; |
| | | } |
| | | return ""; |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.init(); |
| | | } |