From c1404046b04ae79603e3dd71bc26174e58c164b2 Mon Sep 17 00:00:00 2001 From: zhangyao Date: Fri, 21 Jul 2023 15:21:58 +0800 Subject: [PATCH] feat: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化逻辑 --- .../forewarning/rule-set/detail/index.vue | 17 +++++----- .../forewarning/rule-set/modules/custom.vue | 22 +++++++++---- .../forewarning/rule-set/modules/gateway.vue | 31 +++++++++++++------ 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/page/main/forewarning/rule-set/detail/index.vue b/src/page/main/forewarning/rule-set/detail/index.vue index 9e3f327..e15872d 100644 --- a/src/page/main/forewarning/rule-set/detail/index.vue +++ b/src/page/main/forewarning/rule-set/detail/index.vue @@ -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], }; }); diff --git a/src/page/main/forewarning/rule-set/modules/custom.vue b/src/page/main/forewarning/rule-set/modules/custom.vue index 15973bf..e848241 100644 --- a/src/page/main/forewarning/rule-set/modules/custom.vue +++ b/src/page/main/forewarning/rule-set/modules/custom.vue @@ -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,8 +276,13 @@ const changeWarningThresholdFrom = (index) => { if (rows.length == 0) return; try { rows.forEach((e) => { - if (e.up !== "" && e.down !== "" && +e.up >= +from && +from > +e.down) { - throw ""; + 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) { @@ -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,8 +310,13 @@ const changeWarningThresholdTo = (index) => { if (rows.length == 0) return; try { rows.forEach((e) => { - if (e.up !== "" && e.down !== "" && +e.up > +to && +to > +e.down) { - throw ""; + 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) { diff --git a/src/page/main/forewarning/rule-set/modules/gateway.vue b/src/page/main/forewarning/rule-set/modules/gateway.vue index 418a5a6..75f21c6 100644 --- a/src/page/main/forewarning/rule-set/modules/gateway.vue +++ b/src/page/main/forewarning/rule-set/modules/gateway.vue @@ -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,9 +234,14 @@ const changeWarningThresholdFrom = (index) => { let rows = setLimits(index); if (rows.length == 0) return; try { - rows.forEach((e) => { - if (e.up !== "" && e.down !== "" && +e.up >= +from && +from > +e.down) { - throw ""; + 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) { @@ -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,9 +279,14 @@ const changeWarningThresholdTo = (index) => { let rows = setLimits(index); if (rows.length == 0) return; try { - rows.forEach((e) => { - if (e.up !== "" && e.down !== "" && +e.up > +to && +to > +e.down) { - throw ""; + 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) { -- 2.26.0