From 60095edab4a49db0bd26b2c0aa34a51a61f16b6b Mon Sep 17 00:00:00 2001 From: zhangyao Date: Thu, 6 Jul 2023 18:03:31 +0800 Subject: [PATCH] feat: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 接口对接及逻辑优化 --- src/components/env.js | 31 +++++++++++ .../indicator-config/detail/index.vue | 38 ++------------ .../indicator-config/modules/add-form.vue | 52 ++++--------------- .../main/forewarning/list/detail/index.vue | 50 ++++++------------ src/page/main/forewarning/list/index.vue | 42 ++------------- .../forewarning/rule-set/detail/index.vue | 5 +- .../main/forewarning/rule-set/edit/index.vue | 12 +++-- .../forewarning/rule-set/modules/custom.vue | 10 ++-- .../main/forewarning/rule-set/modules/env.js | 3 -- .../forewarning/rule-set/modules/gateway.vue | 21 ++++---- .../forewarning/rule-set/modules/interface.js | 37 ------------- .../forewarning/rule-set/modules/static.vue | 15 ++++-- 12 files changed, 103 insertions(+), 213 deletions(-) delete mode 100644 src/page/main/forewarning/rule-set/modules/env.js diff --git a/src/components/env.js b/src/components/env.js index a29f352..9208d17 100644 --- a/src/components/env.js +++ b/src/components/env.js @@ -1,3 +1,4 @@ +import axios from "@/request/http.js"; export const TIMEING_RULES = { 1: '手动下发', 2: '按周', @@ -6,4 +7,34 @@ export const TIMEING_RULES = { export const MAX_DAY = 7; export const ONLY_INPUT_NUM = (value) => { return value.replace(/[^\d]/g, '') +} +export const GetRuleTypeOptions = () => { + return new Promise((resolve, reject) => { + const params = { + page: 1, + page_size: 10000000000000, + class: 3, + }; + let obj = {} + axios.get(`/v1/api/dict`, { params }).then((res) => { + if (res.data.code == 200) { + if (res.data.data) { + res.data.data.forEach((e) => { + let isEmptyOption = e.name == "空"; + obj[e.id] = { + label: e.name, + unit: isEmptyOption ? "" : e.unit, + down: isEmptyOption ? '' : e.min_val, + up: isEmptyOption ? '' : e.max_val + }; + }); + } + resolve(obj) + } + }); + }) +} +export const Empty = (key, Obj) => { + let item = Obj[key] + return !item || item.label == '空' } \ No newline at end of file diff --git a/src/page/main/forewarning/indicator-config/detail/index.vue b/src/page/main/forewarning/indicator-config/detail/index.vue index 7e0acf8..11ec0f8 100644 --- a/src/page/main/forewarning/indicator-config/detail/index.vue +++ b/src/page/main/forewarning/indicator-config/detail/index.vue @@ -70,6 +70,7 @@ import gapTitle from "@/components/gap-title.vue"; import bgBreadcrumb from "@/components/bg-breadcrumb.vue"; import Info from "@/components/warn-detail/info.vue"; import { METHODS } from "@/components/manual-distribution/env.js"; +import { GetRuleTypeOptions, Empty } from "@/components/env.js"; const route = useRoute(); const { id, type_name, target_name } = route.query; const STATUS_OBJ = { @@ -130,41 +131,8 @@ const rule_label = [ ]; const rule_data = ref({}); const ruleTypeOptions = ref({}); -const getRuleTypeOptions = () => { - let arr = [ - { - id: "empty", - label: "空", - }, - { - id: "1", - label: "百分比范围", - unit: "%", - }, - { - id: "2", - label: "毫秒范围", - unit: "ms", - }, - { - id: "3", - label: "秒范围", - unit: "s", - }, - { - id: "4", - label: "个范围", - unit: "个", - }, - { - id: "5", - label: "温度范围", - unit: "℃", - }, - ]; - arr.forEach((e) => { - ruleTypeOptions.value[e.id] = e.label; - }); +const getRuleTypeOptions = async () => { + ruleTypeOptions.value = await GetRuleTypeOptions(); }; const advanced_label = [ [ diff --git a/src/page/main/forewarning/indicator-config/modules/add-form.vue b/src/page/main/forewarning/indicator-config/modules/add-form.vue index 4ad3376..e0d7759 100644 --- a/src/page/main/forewarning/indicator-config/modules/add-form.vue +++ b/src/page/main/forewarning/indicator-config/modules/add-form.vue @@ -18,7 +18,8 @@ - + +
@@ -61,50 +62,13 @@ import { MAX_DAY, ONLY_INPUT_NUM } from "@/components/env.js"; import { ElMessage } from "element-plus"; import axios from "@/request/http.js"; import warningScope from "./warning-scope.vue"; +import { GetRuleTypeOptions, Empty } from "@/components/env.js"; const props = defineProps({ row: { type: Object, default: null, }, }); -// 预警规则类型下拉 -const ruleTypeOptions = ref({}); -const getRuleTypeOptions = () => { - let arr = [ - { - id: "empty", - label: "空", - }, - { - id: "1", - label: "百分比范围", - unit: "%", - }, - { - id: "2", - label: "毫秒范围", - unit: "ms", - }, - { - id: "3", - label: "秒范围", - unit: "s", - }, - { - id: "4", - label: "个范围", - unit: "个", - }, - { - id: "5", - label: "温度范围", - unit: "℃", - }, - ]; - arr.forEach((e) => { - ruleTypeOptions.value[e.id] = e.label; - }); -}; // 当前是否是编辑 const isEdit = computed(() => !!props.row); // 获取旧数据 @@ -119,7 +83,7 @@ const state = reactive({ form: { name: "", indicator_expression: "", - rule_type: "empty", + rule_type: "", time: 10, unit: "s", inspection_cycle: 1, @@ -127,10 +91,16 @@ const state = reactive({ }, rules: { name: [{ required: true, message: "请输入指标名称", trigger: "blur" }], + rule_type: [{ required: true, message: "请选择预警规则类型", trigger: "change" }], indicator_expression: [{ required: true, message: "请输入指标表达式", trigger: "blur" }], time: [{ required: true, message: "请输入持续时间", trigger: "blur" }], }, }); +// 预警规则类型下拉 +const ruleTypeOptions = ref({}); +const getRuleTypeOptions = async () => { + ruleTypeOptions.value = await GetRuleTypeOptions(); +}; // 当预警持续输入限制 const inputNum = () => { state.form.time = state.form.time.replace(/[^\d]/g, ""); @@ -166,7 +136,7 @@ watch( async (n) => { if (!n) return; state.form.name = n.name; - state.form.rule_type = n.rule_type || "empty"; + state.form.rule_type = n.rule_type; state.form.inspection_cycle = n.inspection_cycle || 1; state.form.state = n.state || 1; state.form.time = n.time || 10; diff --git a/src/page/main/forewarning/list/detail/index.vue b/src/page/main/forewarning/list/detail/index.vue index 85a95b0..1d218d0 100644 --- a/src/page/main/forewarning/list/detail/index.vue +++ b/src/page/main/forewarning/list/detail/index.vue @@ -143,41 +143,23 @@ const getInfo = () => { }); }; const GetRuleTypeOptions = () => { - let arr = [ - { - id: "empty", - label: "空", - }, - { - id: "1", - label: "百分比范围", - unit: "%", - }, - { - id: "2", - label: "毫秒范围", - unit: "ms", - }, - { - id: "3", - label: "秒范围", - unit: "s", - }, - { - id: "4", - label: "个范围", - unit: "个", - }, - { - id: "5", - label: "温度范围", - unit: "℃", - }, - ]; - arr.forEach((e) => { - ruleTypeOptions.value[e.id] = e; + const params = { + page: 1, + page_size: 10000000000000, + class: 3, + }; + axios.get(`/v1/api/dict`, { params }).then((res) => { + if (res.data.code == 200) { + res.data.data?.forEach((e) => { + let isEmptyOption = e.name == "空"; + ruleTypeOptions.value[e.id] = { + label: e.name, + unit: isEmptyOption ? "" : e.unit, + }; + }); + getInfo(); + } }); - getInfo(); }; onBeforeMount(() => { GetRuleTypeOptions(); diff --git a/src/page/main/forewarning/list/index.vue b/src/page/main/forewarning/list/index.vue index 9b2ebb1..a9b687e 100644 --- a/src/page/main/forewarning/list/index.vue +++ b/src/page/main/forewarning/list/index.vue @@ -83,7 +83,7 @@