From 266ba0c2983778a0bb026c7eb0580c33d6b1a37a Mon Sep 17 00:00:00 2001 From: zhangyao Date: Tue, 18 Jul 2023 10:41:01 +0800 Subject: [PATCH] fix: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复自测bug --- .../forewarning/rule-set/modules/custom.vue | 47 ++++++++++--------- .../forewarning/rule-set/modules/gateway.vue | 47 ++++++++++--------- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/src/page/main/forewarning/rule-set/modules/custom.vue b/src/page/main/forewarning/rule-set/modules/custom.vue index 5f97670..08f8d13 100644 --- a/src/page/main/forewarning/rule-set/modules/custom.vue +++ b/src/page/main/forewarning/rule-set/modules/custom.vue @@ -215,20 +215,22 @@ const setLimits = (index) => { ); }; const inputNum = (index, key) => { - state.form.ruleRows[index][key] = +`${state.form.ruleRows[index][key]}`.replace(/[^\d]/g, ""); + if (state.form.ruleRows[index][key] == "-") return; + state.form.ruleRows[index][key] = +`${state.form.ruleRows[index][key]}`.replace(/[^\-?\d.]/g, ""); }; const changeWarningThresholdFrom = (index) => { let { down, up } = limit.value; - if (down === "") return; let { from, to } = state.form.ruleRows[index]; - if (+from > +up || (index == 0 && +from < +down) || (to != "" && from > +to)) { - if (+from < +down) { - ElMessage.error(`下限不能小于${down}`); - } else if (+from > +up) { - ElMessage.error(`上限不能超过${up}`); - } else { - ElMessage.error(`下限不能大于上限`); - } + if (to != "" && from > +to) { + ElMessage.error(`下限不能大于上限`); + state.form.ruleRows[index].from = ""; + return; + } else if (down !== "" && +from < +down) { + ElMessage.error(`下限不能小于${down}`); + state.form.ruleRows[index].from = ""; + return; + } else if (up != "" && +from > +up) { + ElMessage.error(`上限不能超过${up}`); state.form.ruleRows[index].from = ""; return; } @@ -236,7 +238,7 @@ const changeWarningThresholdFrom = (index) => { if (rows.length == 0) return; try { rows.forEach((e) => { - if (e.up !== "" && e.down !== "" && +e.up >= +from > +e.down) { + if (e.up !== "" && e.down !== "" && +e.up >= +from && +from > +e.down) { throw ""; } }); @@ -247,16 +249,17 @@ const changeWarningThresholdFrom = (index) => { }; const changeWarningThresholdTo = (index) => { let { down, up } = limit.value; - if (up === "") return; let { from, to } = state.form.ruleRows[index]; - if ((index == 0 && +to > +up) || +to < +down || (from != "" && +from > +to)) { - if (+to > +up) { - ElMessage.error(`上限不能超过${up}`); - } else if (+to < +down) { - ElMessage.error(`下限不能小于${down}`); - } else { - ElMessage.error(`上限不能小于下限`); - } + if (from != "" && from > +to) { + ElMessage.error(`下限不能大于上限`); + state.form.ruleRows[index].to = ""; + return; + } else if (down !== "" && +to < +down) { + ElMessage.error(`下限不能小于${down}`); + state.form.ruleRows[index].to = ""; + return; + } else if (up != "" && +to > +up) { + ElMessage.error(`上限不能超过${up}`); state.form.ruleRows[index].to = ""; return; } @@ -264,7 +267,7 @@ const changeWarningThresholdTo = (index) => { if (rows.length == 0) return; try { rows.forEach((e) => { - if (e.up !== "" && e.down !== "" && +e.up > +to > +e.down) { + if (e.up !== "" && e.down !== "" && +e.up > +to && +to > +e.down) { throw ""; } }); @@ -352,7 +355,7 @@ const removeRule = (index) => { state.form.ruleRows.splice(index, 1); }; const info = () => { - if (!info) { + if (!props.form) { createRule(); return; } diff --git a/src/page/main/forewarning/rule-set/modules/gateway.vue b/src/page/main/forewarning/rule-set/modules/gateway.vue index 1890ce9..290962b 100644 --- a/src/page/main/forewarning/rule-set/modules/gateway.vue +++ b/src/page/main/forewarning/rule-set/modules/gateway.vue @@ -181,7 +181,7 @@ const isEmptyOption = computed(() => { }); const limit = computed(() => { return ( - ruleTypeOptions.value[rule_type.value] || { + ruleTypeOptions.value[props.rule_type] || { down: "", up: "", } @@ -189,16 +189,17 @@ const limit = computed(() => { }); const changeWarningThresholdFrom = (index) => { let { down, up } = limit.value; - if (down === "") return; let { from, to } = state.form.ruleRows[index]; - if ((up != "" && +from > +up) || (index == 0 && +from < +down) || (to != "" && from > +to)) { - if (+from < +down) { - ElMessage.error(`下限不能小于${down}`); - } else if (+from > +up) { - ElMessage.error(`上限不能超过${up}`); - } else { - ElMessage.error(`下限不能大于上限`); - } + if (to != "" && from > +to) { + ElMessage.error(`下限不能大于上限`); + state.form.ruleRows[index].from = ""; + return; + } else if (down !== "" && +from < +down) { + ElMessage.error(`下限不能小于${down}`); + state.form.ruleRows[index].from = ""; + return; + } else if (up != "" && +from > +up) { + ElMessage.error(`上限不能超过${up}`); state.form.ruleRows[index].from = ""; return; } @@ -206,7 +207,7 @@ const changeWarningThresholdFrom = (index) => { if (rows.length == 0) return; try { rows.forEach((e) => { - if (e.up !== "" && e.down !== "" && +e.up >= +from > +e.down) { + if (e.up !== "" && e.down !== "" && +e.up >= +from && +from > +e.down) { throw ""; } }); @@ -216,20 +217,22 @@ const changeWarningThresholdFrom = (index) => { } }; const inputNum = (index, key) => { - state.form.ruleRows[index][key] = +`${state.form.ruleRows[index][key]}`.replace(/[^\d]/g, ""); + if (state.form.ruleRows[index][key] == "-") return; + state.form.ruleRows[index][key] = +`${state.form.ruleRows[index][key]}`.replace(/[^\-?\d.]/g, ""); }; const changeWarningThresholdTo = (index) => { let { down, up } = limit.value; - if (up === "") return; let { from, to } = state.form.ruleRows[index]; - if ((index == 0 && +to > +up) || (down != "" && +to < +down) || (from != "" && +from > +to)) { - if (+to > +up) { - ElMessage.error(`上限不能超过${up}`); - } else if (+to < +down) { - ElMessage.error(`下限不能小于${down}`); - } else { - ElMessage.error(`上限不能小于下限`); - } + if (from != "" && from > +to) { + ElMessage.error(`下限不能大于上限`); + state.form.ruleRows[index].to = ""; + return; + } else if (down !== "" && +to < +down) { + ElMessage.error(`下限不能小于${down}`); + state.form.ruleRows[index].to = ""; + return; + } else if (up != "" && +to > +up) { + ElMessage.error(`上限不能超过${up}`); state.form.ruleRows[index].to = ""; return; } @@ -237,7 +240,7 @@ const changeWarningThresholdTo = (index) => { if (rows.length == 0) return; try { rows.forEach((e) => { - if (e.up !== "" && e.down !== "" && +e.up > +to > +e.down) { + if (e.up !== "" && e.down !== "" && +e.up > +to && +to > +e.down) { throw ""; } }); -- 2.26.0