Commit c1404046 authored by 张耀's avatar 张耀

feat:

优化逻辑
parent 02731e6f
......@@ -226,27 +226,26 @@ const getInfoData = () => {
...ruleHeaders.value,
];
}
let unit = ruleTypeOptions.value[data.alert_rule_type]?.unit || "";
ruleRows.value = data.alert_condition.map((e) => {
let min = e.thresholds_min;
if (min === undefined) {
let min = e.thresholds_min + unit;
if (e.thresholds_min === undefined) {
if (ruleTypeOptions.value[data.alert_rule_type].down !== "") {
min = ruleTypeOptions.value[data.alert_rule_type].down;
min = ruleTypeOptions.value[data.alert_rule_type].down + unit;
} else {
min = WIELESS_SMALL;
}
}
let max = e.thresholds_max;
if (max === undefined) {
let max = e.thresholds_max + unit;
if (e.thresholds_max === undefined) {
if (ruleTypeOptions.value[data.alert_rule_type].up !== "") {
max = ruleTypeOptions.value[data.alert_rule_type].up;
max = ruleTypeOptions.value[data.alert_rule_type].up + unit;
} else {
max = WIELESS_SMALL;
}
}
return {
warning_threshold: `${min}${ruleTypeOptions.value[data.alert_rule_type]?.unit || ""} - ${max}${
ruleTypeOptions.value[data.alert_rule_type]?.unit || ""
}`,
warning_threshold: `${min} - ${max}`,
risk_level: riskLevelOptions[e.risk_level],
};
});
......
......@@ -259,7 +259,7 @@ const inputNum = (index, key) => {
const changeWarningThresholdFrom = (index) => {
let { down, up } = limit.value;
let { from, to } = state.form.ruleRows[index];
if (to != "" && from > +to) {
if (to != "" && from !== "" && from > +to) {
ElMessage.error(`下限不能大于上限`);
state.form.ruleRows[index].from = "";
return;
......@@ -276,9 +276,14 @@ const changeWarningThresholdFrom = (index) => {
if (rows.length == 0) return;
try {
rows.forEach((e) => {
if (from !== "") {
if (i == 0 && e.down === "" && +from <= +e.up) {
throw "";
}
if (e.up !== "" && e.down !== "" && +e.up >= +from && +from > +e.down) {
throw "";
}
}
});
} catch (e) {
ElMessage.error(`该范围已被设置`);
......@@ -288,7 +293,7 @@ const changeWarningThresholdFrom = (index) => {
const changeWarningThresholdTo = (index) => {
let { down, up } = limit.value;
let { from, to } = state.form.ruleRows[index];
if (from != "" && from > +to) {
if (from != "" && from !== "" && from > +to) {
ElMessage.error(`下限不能大于上限`);
state.form.ruleRows[index].to = "";
return;
......@@ -305,9 +310,14 @@ const changeWarningThresholdTo = (index) => {
if (rows.length == 0) return;
try {
rows.forEach((e) => {
if (to !== "") {
if (i == rows.length - 1 && e.up === "" && +to > +e.down) {
throw "";
}
if (e.up !== "" && e.down !== "" && +e.up > +to && +to > +e.down) {
throw "";
}
}
});
} catch (e) {
state.form.ruleRows[index].to = "";
......
......@@ -198,8 +198,8 @@ const setLimits = (index) => {
return (
rows.map((e) => {
return {
down: +e.from,
up: +e.to,
down: e.from,
up: e.to,
};
}) || []
);
......@@ -218,7 +218,7 @@ const limit = computed(() => {
const changeWarningThresholdFrom = (index) => {
let { down, up } = limit.value;
let { from, to } = state.form.ruleRows[index];
if (to != "" && from > +to) {
if (to !== "" && from !== "" && from > +to) {
ElMessage.error(`下限不能大于上限`);
state.form.ruleRows[index].from = "";
return;
......@@ -234,10 +234,15 @@ const changeWarningThresholdFrom = (index) => {
let rows = setLimits(index);
if (rows.length == 0) return;
try {
rows.forEach((e) => {
rows.forEach((e, i) => {
if (from !== "") {
if (i == 0 && e.down === "" && +from <= +e.up) {
throw "";
}
if (e.up !== "" && e.down !== "" && +e.up >= +from && +from > +e.down) {
throw "";
}
}
});
} catch (e) {
ElMessage.error(`该范围已被设置`);
......@@ -255,9 +260,10 @@ const inputNum = (index, key) => {
.replace(/(\d)\-/g, "$1"); //过滤处于非开头的负号
};
const changeWarningThresholdTo = (index) => {
console.log(1);
let { down, up } = limit.value;
let { from, to } = state.form.ruleRows[index];
if (from != "" && from > +to) {
if (to !== "" && from !== "" && from > +to) {
ElMessage.error(`下限不能大于上限`);
state.form.ruleRows[index].to = "";
return;
......@@ -273,10 +279,15 @@ const changeWarningThresholdTo = (index) => {
let rows = setLimits(index);
if (rows.length == 0) return;
try {
rows.forEach((e) => {
rows.forEach((e, i) => {
if (to !== "") {
if (i == rows.length - 1 && e.up === "" && +to > +e.down) {
throw "";
}
if (e.up !== "" && e.down !== "" && +e.up > +to && +to > +e.down) {
throw "";
}
}
});
} catch (e) {
ElMessage.error(`该范围已被设置`);
......
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