Commit 02731e6f authored by 张耀's avatar 张耀

feat:

优化预警规则设置展示逻辑
parent 0ed29fe1
...@@ -5,6 +5,8 @@ export const TIMEING_RULES = { ...@@ -5,6 +5,8 @@ export const TIMEING_RULES = {
3: '自定义时间' 3: '自定义时间'
} }
export const MAX_DAY = 7; export const MAX_DAY = 7;
export const WIELESS_SMALL = '-∞'
export const WIELESS_BIG = '+∞'
export const ONLY_INPUT_NUM = (value) => { export const ONLY_INPUT_NUM = (value) => {
return value.replace(/[^\d]/g, '') return value.replace(/[^\d]/g, '')
} }
......
...@@ -58,7 +58,7 @@ import gapTitle from "@/components/gap-title.vue"; ...@@ -58,7 +58,7 @@ import gapTitle from "@/components/gap-title.vue";
import bgBreadcrumb from "@/components/bg-breadcrumb.vue"; import bgBreadcrumb from "@/components/bg-breadcrumb.vue";
import Info from "@/components/warn-detail/info.vue"; import Info from "@/components/warn-detail/info.vue";
import { METHODS } from "@/components/manual-distribution/env.js"; import { METHODS } from "@/components/manual-distribution/env.js";
import { GetRuleTypeOptions, Empty } from "@/components/env.js"; import { GetRuleTypeOptions, Empty, WIELESS_SMALL, WIELESS_BIG } from "@/components/env.js";
const route = useRoute(); const route = useRoute();
const { id } = route.query; const { id } = route.query;
const STATUS_OBJ = ["禁用", "启用"]; const STATUS_OBJ = ["禁用", "启用"];
...@@ -227,10 +227,26 @@ const getInfoData = () => { ...@@ -227,10 +227,26 @@ const getInfoData = () => {
]; ];
} }
ruleRows.value = data.alert_condition.map((e) => { ruleRows.value = data.alert_condition.map((e) => {
let min = e.thresholds_min;
if (min === undefined) {
if (ruleTypeOptions.value[data.alert_rule_type].down !== "") {
min = ruleTypeOptions.value[data.alert_rule_type].down;
} else {
min = WIELESS_SMALL;
}
}
let max = e.thresholds_max;
if (max === undefined) {
if (ruleTypeOptions.value[data.alert_rule_type].up !== "") {
max = ruleTypeOptions.value[data.alert_rule_type].up;
} else {
max = WIELESS_SMALL;
}
}
return { return {
warning_threshold: `${e.thresholds_min}${ruleTypeOptions.value[data.alert_rule_type]?.unit || ""} - ${ warning_threshold: `${min}${ruleTypeOptions.value[data.alert_rule_type]?.unit || ""} - ${max}${
e.thresholds_max ruleTypeOptions.value[data.alert_rule_type]?.unit || ""
}${ruleTypeOptions.value[data.alert_rule_type]?.unit || ""}`, }`,
risk_level: riskLevelOptions[e.risk_level], risk_level: riskLevelOptions[e.risk_level],
}; };
}); });
......
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
:width="header.width"> :width="header.width">
<template #default="{ $index }"> <template #default="{ $index }">
<div class="warning-threshold" v-if="header.prop == 'warning_threshold'"> <div class="warning-threshold" v-if="header.prop == 'warning_threshold'">
<el-form-item :prop="`[${$index}].from`" :rules="state.tableRules.from" style="flex: 1"> <el-form-item :prop="`[${$index}].from`" :rules="state.tableRules.from($index)" style="flex: 1">
<el-input <el-input
style="flex: 1" style="flex: 1"
v-model="state.form.ruleRows[$index].from" v-model="state.form.ruleRows[$index].from"
...@@ -87,7 +87,11 @@ ...@@ -87,7 +87,11 @@
</el-input> </el-input>
</el-form-item> </el-form-item>
<span class="to">-</span> <span class="to">-</span>
<el-form-item label="" :prop="`${$index}.to`" :rules="state.tableRules.to" style="flex: 1"> <el-form-item
label=""
:prop="`${$index}.to`"
:rules="state.tableRules.to($index)"
style="flex: 1">
<el-input <el-input
style="flex: 1" style="flex: 1"
v-model="state.form.ruleRows[$index].to" v-model="state.form.ruleRows[$index].to"
...@@ -172,6 +176,30 @@ var validateWarnIndex = (rule, value, callback) => { ...@@ -172,6 +176,30 @@ var validateWarnIndex = (rule, value, callback) => {
callback(); callback();
} }
}; };
const validateFrom = (rule, value, callback, index) => {
let thisRow = state.form.ruleRows[index];
// 如果只有一条数据,并且上限下限都没有填写,则提示错误
if (state.form.ruleRows.length == 1 && thisRow.from === "" && thisRow.to == "") {
return callback(new Error("请输入"));
}
// 当前下限不是第一条数据,并且为空,提示错误
if (index > 0 && value === "") {
return callback(new Error("请输入"));
}
callback();
};
const validateTo = (rule, value, callback, index) => {
let thisRow = state.form.ruleRows[index];
// 如果只有一条数据,并且上限下限都没有填写,则提示错误
if (state.form.ruleRows.length == 1 && thisRow.from === "" && thisRow.to == "") {
return callback(new Error("请输入"));
}
// 当前上限不是最后一条数据,并且为空,提示错误
if (index < state.form.ruleRows.length - 1 && value === "") {
return callback(new Error("请输入"));
}
callback();
};
const ruleTypeOptions = ref({}); const ruleTypeOptions = ref({});
const state = reactive({ const state = reactive({
form: { form: {
...@@ -192,8 +220,12 @@ const state = reactive({ ...@@ -192,8 +220,12 @@ const state = reactive({
risk_level: [{ required: true, message: "请选择风险程度", trigger: "change" }], risk_level: [{ required: true, message: "请选择风险程度", trigger: "change" }],
}, },
tableRules: { tableRules: {
from: [{ required: true, message: "请输入", trigger: "blur" }], from: (index) => {
to: [{ required: true, message: "请输入", trigger: "blur" }], return [{ validator: (rule, value, callback) => validateFrom(rule, value, callback, index), trigger: "blur" }];
},
to: (index) => {
return [{ validator: (rule, value, callback) => validateTo(rule, value, callback, index), trigger: "blur" }];
},
risk_level: [{ required: true, message: "请选择风险程度", trigger: "change" }], risk_level: [{ required: true, message: "请选择风险程度", trigger: "change" }],
}, },
}); });
...@@ -215,8 +247,14 @@ const setLimits = (index) => { ...@@ -215,8 +247,14 @@ const setLimits = (index) => {
); );
}; };
const inputNum = (index, key) => { const inputNum = (index, key) => {
if (state.form.ruleRows[index][key] == "") return;
if (state.form.ruleRows[index][key] == "-") return; if (state.form.ruleRows[index][key] == "-") return;
state.form.ruleRows[index][key] = +`${state.form.ruleRows[index][key]}`.replace(/[^\-?\d.]/g, ""); state.form.ruleRows[index][key] = `${state.form.ruleRows[index][key]}`
.replace(/[^\-?\d.]/g, "") //只允许输入负号,数字,小数点
.replace(/(\-)+/, "$1") //过滤连续多个负号
.replace(/(\.)+/, "$1") //过滤连续多个小数点
.replace(/(\.\d+)\./g, "$1") //过滤出现多个小数点
.replace(/(\d)\-/g, "$1"); //过滤处于非开头的负号
}; };
const changeWarningThresholdFrom = (index) => { const changeWarningThresholdFrom = (index) => {
let { down, up } = limit.value; let { down, up } = limit.value;
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
:width="header.width"> :width="header.width">
<template #default="{ $index }"> <template #default="{ $index }">
<div class="warning-threshold" v-if="header.prop == 'warning_threshold'"> <div class="warning-threshold" v-if="header.prop == 'warning_threshold'">
<el-form-item :prop="`[${$index}].from`" :rules="state.tableRules.from" style="flex: 1"> <el-form-item :prop="`[${$index}].from`" :rules="state.tableRules.from($index)" style="flex: 1">
<el-input <el-input
style="flex: 1" style="flex: 1"
v-model.number="state.form.ruleRows[$index].from" v-model="state.form.ruleRows[$index].from"
placeholder="请输入" placeholder="请输入"
@input="inputNum($index, 'from')" @input="inputNum($index, 'from')"
@blur="changeWarningThresholdFrom($index)"> @blur="changeWarningThresholdFrom($index)">
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
</el-input> </el-input>
</el-form-item> </el-form-item>
<span class="to">-</span> <span class="to">-</span>
<el-form-item label="" :prop="`${$index}.to`" :rules="state.tableRules.to" style="flex: 1"> <el-form-item label="" :prop="`${$index}.to`" :rules="state.tableRules.to($index)" style="flex: 1">
<el-input <el-input
style="flex: 1" style="flex: 1"
v-model.number="state.form.ruleRows[$index].to" v-model="state.form.ruleRows[$index].to"
placeholder="请输入" placeholder="请输入"
clearable clearable
@input="inputNum($index, 'to')" @input="inputNum($index, 'to')"
...@@ -100,13 +100,41 @@ const getRuleTypeOptions = async (cb) => { ...@@ -100,13 +100,41 @@ const getRuleTypeOptions = async (cb) => {
ruleTypeOptions.value = await GetRuleTypeOptions(); ruleTypeOptions.value = await GetRuleTypeOptions();
cb && cb(); cb && cb();
}; };
const validateFrom = (rule, value, callback, index) => {
let thisRow = state.form.ruleRows[index];
// 如果只有一条数据,并且上限下限都没有填写,则提示错误
if (state.form.ruleRows.length == 1 && thisRow.from === "" && thisRow.to == "") {
return callback(new Error("请输入"));
}
// 当前下限不是第一条数据,并且为空,提示错误
if (index > 0 && value === "") {
return callback(new Error("请输入"));
}
callback();
};
const validateTo = (rule, value, callback, index) => {
let thisRow = state.form.ruleRows[index];
// 如果只有一条数据,并且上限下限都没有填写,则提示错误
if (state.form.ruleRows.length == 1 && thisRow.from === "" && thisRow.to == "") {
return callback(new Error("请输入"));
}
// 当前上限不是最后一条数据,并且为空,提示错误
if (index < state.form.ruleRows.length - 1 && value === "") {
return callback(new Error("请输入"));
}
callback();
};
const state = reactive({ const state = reactive({
form: { form: {
ruleRows: [], ruleRows: [],
}, },
tableRules: { tableRules: {
from: [{ required: true, message: "请输入", trigger: "blur" }], from: (index) => {
to: [{ required: true, message: "请输入", trigger: "blur" }], return [{ validator: (rule, value, callback) => validateFrom(rule, value, callback, index), trigger: "blur" }];
},
to: (index) => {
return [{ validator: (rule, value, callback) => validateTo(rule, value, callback, index), trigger: "blur" }];
},
risk_level: [{ required: true, message: "请选择", trigger: "change" }], risk_level: [{ required: true, message: "请选择", trigger: "change" }],
}, },
}); });
...@@ -217,8 +245,14 @@ const changeWarningThresholdFrom = (index) => { ...@@ -217,8 +245,14 @@ const changeWarningThresholdFrom = (index) => {
} }
}; };
const inputNum = (index, key) => { const inputNum = (index, key) => {
if (state.form.ruleRows[index][key] == "") return;
if (state.form.ruleRows[index][key] == "-") return; if (state.form.ruleRows[index][key] == "-") return;
state.form.ruleRows[index][key] = +`${state.form.ruleRows[index][key]}`.replace(/[^\-?\d.]/g, ""); state.form.ruleRows[index][key] = `${state.form.ruleRows[index][key]}`
.replace(/[^\-?\d.]/g, "") //只允许输入负号,数字,小数点
.replace(/(\-)+/, "$1") //过滤连续多个负号
.replace(/(\.)+/, "$1") //过滤连续多个小数点
.replace(/(\.\d+)\./g, "$1") //过滤出现多个小数点
.replace(/(\d)\-/g, "$1"); //过滤处于非开头的负号
}; };
const changeWarningThresholdTo = (index) => { const changeWarningThresholdTo = (index) => {
let { down, up } = limit.value; let { down, up } = limit.value;
......
...@@ -2,7 +2,6 @@ import { ElMessage } from "element-plus"; ...@@ -2,7 +2,6 @@ import { ElMessage } from "element-plus";
import axios from "@/request/http.js"; import axios from "@/request/http.js";
// max(container_fs_usage_bytes{pod!=\"\", namespace!=\"arms-prom\",namespace!=\"monitoring\"}) by (pod_name, namespace, device)/max(container_fs_limit_bytes{pod!=\"\"}) by (pod_name,namespace, device) * 100 // max(container_fs_usage_bytes{pod!=\"\", namespace!=\"arms-prom\",namespace!=\"monitoring\"}) by (pod_name, namespace, device)/max(container_fs_limit_bytes{pod!=\"\"}) by (pod_name,namespace, device) * 100
const setParams = (res, { id }) => { const setParams = (res, { id }) => {
console.log('res: ', res);
let isEmpty = res.type_com_ref.isEmpty let isEmpty = res.type_com_ref.isEmpty
let params = { let params = {
// 预警规则名称 // 预警规则名称
...@@ -85,11 +84,16 @@ const setParams = (res, { id }) => { ...@@ -85,11 +84,16 @@ const setParams = (res, { id }) => {
}] }]
} else { } else {
alert_condition = res.type_com_ref.ruleRows.map(e => { alert_condition = res.type_com_ref.ruleRows.map(e => {
return { let obj = {
thresholds_max: +e.to,
thresholds_min: +e.from,
risk_level: +e.risk_level risk_level: +e.risk_level
} }
if (e.to !== "") {
obj.thresholds_max = +e.to
}
if (e.from !== "") {
obj.thresholds_min = +e.to
}
return obj
}) })
} }
params = { params = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment