Commit 9de794c5 authored by 张耀's avatar 张耀

feat:

优化逻辑
parent c4b5f9f0
...@@ -78,8 +78,10 @@ ...@@ -78,8 +78,10 @@
</template> </template>
<script setup> <script setup>
import { ElMessage } from "element-plus";
import { reactive, watch, ref, computed } from "vue"; import { reactive, watch, ref, computed } from "vue";
import { METHODS, ADD_NUM } from "./env"; import { METHODS, ADD_NUM } from "./env";
import axios from "@/request/http.js";
const props = defineProps({ const props = defineProps({
disabled: { disabled: {
type: Boolean, type: Boolean,
...@@ -160,43 +162,20 @@ const addTrue = ref(0); ...@@ -160,43 +162,20 @@ const addTrue = ref(0);
// 获取远程用户列表 // 获取远程用户列表
const userLists = ref([]); const userLists = ref([]);
const getUserLists = () => { const getUserLists = () => {
userLists.value = [ axios.get("/v1/api/user/devOps").then((res) => {
{ if (res.data.code == 200) {
user_id: 1, userLists.value =
user_name: 11, res.data.data?.map((e) => {
phone: 13000000001, return {
}, user_id: e.system_account,
{ user_name: e.name,
user_id: 2, phone: e.phone,
user_name: 22, };
phone: 13000000002, }) || [];
}, } else {
{ ElMessage.error(res.data.msg);
user_id: 3, }
user_name: 33, });
phone: 13000000003,
},
{
user_id: 4,
user_name: 44,
phone: 13000000004,
},
{
user_id: 5,
user_name: 55,
phone: 13000000005,
},
{
user_id: 6,
user_name: 66,
phone: 13000000006,
},
{
user_id: 7,
user_name: 77,
phone: 13000000007,
},
];
}; };
// 格式化处理用户下拉列表,去除已经选择的用户,并将当前选中的也显示到列表中 // 格式化处理用户下拉列表,去除已经选择的用户,并将当前选中的也显示到列表中
const userOptions = computed(() => { const userOptions = computed(() => {
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
style="width: 400px" style="width: 400px"
v-model="filter.time" v-model="filter.time"
type="datetimerange" type="datetimerange"
value-format="yyyy-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
range-separator="至" range-separator="至"
start-placeholder="开始时间" start-placeholder="开始时间"
end-placeholder="结束时间" /> end-placeholder="结束时间" />
...@@ -210,7 +210,9 @@ const selectable = (row, index) => { ...@@ -210,7 +210,9 @@ const selectable = (row, index) => {
return row.is_enabled === 2; return row.is_enabled === 2;
}; };
const getTableRows = () => { const getTableRows = () => {
let params = { ...state.filter, class_id: node.value.data.class_id }; const [start_time = "", end_time = ""] = state.filter.time;
let params = { ...state.filter, class_id: node.value.data.class_id, start_time, end_time };
Reflect.deleteProperty(params, "time");
axios.get("/v1/api/metric_config/list", { params }).then((res) => { axios.get("/v1/api/metric_config/list", { params }).then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
state.tableRows = state.tableRows =
......
...@@ -58,6 +58,8 @@ import gapTitle from "@/components/gap-title.vue"; ...@@ -58,6 +58,8 @@ 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 { Empty } from "../modules/env.js";
import { GetRuleTypeOptions } from "../modules/interface.js";
const route = useRoute(); const route = useRoute();
const { id } = route.query; const { id } = route.query;
const STATUS_OBJ = ["禁用", "启用"]; const STATUS_OBJ = ["禁用", "启用"];
...@@ -215,7 +217,7 @@ const getInfoData = () => { ...@@ -215,7 +217,7 @@ const getInfoData = () => {
]); ]);
watning_scope_data.value[e.name] = e.value == ".*" ? "全部" : `${selectRule[e.compare]} ${e.value}`; watning_scope_data.value[e.name] = e.value == ".*" ? "全部" : `${selectRule[e.compare]} ${e.value}`;
}); });
let isEmpty = !data.alert_rule_type || data.alert_rule_type == "empty"; let isEmpty = Empty(data.alert_rule_type);
if (!isEmpty) { if (!isEmpty) {
ruleHeaders.value = [ ruleHeaders.value = [
{ {
...@@ -227,9 +229,9 @@ const getInfoData = () => { ...@@ -227,9 +229,9 @@ const getInfoData = () => {
} }
ruleRows.value = data.alert_condition.map((e) => { ruleRows.value = data.alert_condition.map((e) => {
return { return {
warning_threshold: `${e.thresholds_min}${ruleTypeOptions.value[data.alert_rule_type].unit} - ${ warning_threshold: `${e.thresholds_min}${ruleTypeOptions.value[data.alert_rule_type]?.unit || ""} - ${
e.thresholds_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],
}; };
}); });
...@@ -248,41 +250,8 @@ const getInfoData = () => { ...@@ -248,41 +250,8 @@ const getInfoData = () => {
} }
}); });
}; };
const getRuleTypeOptions = () => { const getRuleTypeOptions = async () => {
let arr = [ ruleTypeOptions.value = await GetRuleTypeOptions();
{
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;
});
getInfoData(); getInfoData();
}; };
onBeforeMount(() => { onBeforeMount(() => {
......
...@@ -21,6 +21,7 @@ import addForm from "../modules/add-form.vue"; ...@@ -21,6 +21,7 @@ import addForm from "../modules/add-form.vue";
import axios from "@/request/http.js"; import axios from "@/request/http.js";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { Save } from "../modules/interface.js"; import { Save } from "../modules/interface.js";
import { Empty } from "../modules/env.js";
const infoData = ref({}); const infoData = ref({});
const router = useRouter(); const router = useRouter();
...@@ -54,8 +55,7 @@ const getInfoData = () => { ...@@ -54,8 +55,7 @@ const getInfoData = () => {
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
const { data } = res.data; const { data } = res.data;
console.log("data: ", data); const isEmpty = Empty(data.alert_rule_type);
const isEmpty = !data.alert_rule_type || data.alert_rule_type == "empty";
let type_json = { let type_json = {
1: () => { 1: () => {
let obj = { let obj = {
...@@ -67,26 +67,27 @@ const getInfoData = () => { ...@@ -67,26 +67,27 @@ const getInfoData = () => {
rule_type: data.alert_rule_type, rule_type: data.alert_rule_type,
}, },
}; };
// if (isEmpty) { if (isEmpty) {
// obj.type_com_ref.risk_level = data.alert_condition[0].risk_level; obj.type_com_ref.risk_level = data.alert_condition[0].risk_level;
// } else { } else {
obj.type_com_ref.warning_scpoe_form = obj.type_com_ref.warning_scpoe_form =
data.alert_range?.map((e) => { data.alert_range?.map((e) => {
return { return {
...e, ...e,
select: e.compare, value: e.value == ".*" ? "" : e.value,
options: [], select: e.value == ".*" ? "all" : e.compare,
}; options: [],
}) || []; };
obj.type_com_ref.ruleRows = }) || [];
data.alert_condition?.map((e) => { obj.type_com_ref.ruleRows =
return { data.alert_condition?.map((e) => {
from: e.thresholds_min, return {
to: e.thresholds_max, from: e.thresholds_min,
risk_level: e.risk_level, to: e.thresholds_max,
}; risk_level: e.risk_level,
}) || []; };
// } }) || [];
}
return obj; return obj;
}, },
2: () => { 2: () => {
......
...@@ -150,6 +150,8 @@ ...@@ -150,6 +150,8 @@
import { computed, onBeforeMount, reactive, ref } from "vue"; import { computed, onBeforeMount, reactive, ref } from "vue";
import gapTitle from "@/components/gap-title.vue"; import gapTitle from "@/components/gap-title.vue";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { Empty } from "../modules/env.js";
import { GetRuleTypeOptions } from "./interface.js";
const props = defineProps({ const props = defineProps({
form: { form: {
type: Object, type: Object,
...@@ -194,7 +196,9 @@ const state = reactive({ ...@@ -194,7 +196,9 @@ const state = reactive({
risk_level: [{ required: true, message: "请选择风险程度", trigger: "change" }], risk_level: [{ required: true, message: "请选择风险程度", trigger: "change" }],
}, },
}); });
const isEmpty = computed(() => state.form.rule_type == "empty"); const isEmpty = computed(() => {
return Empty(state.form.rule_type);
});
const changeWarnCustomTarget = () => {}; const changeWarnCustomTarget = () => {};
const changeWarnCustomType = () => {}; const changeWarnCustomType = () => {};
const setLimits = (index) => { const setLimits = (index) => {
...@@ -323,61 +327,8 @@ const limit = computed(() => { ...@@ -323,61 +327,8 @@ const limit = computed(() => {
} }
); );
}); });
const getRuleTypeOptions = () => { const getRuleTypeOptions = async () => {
let arr = [ ruleTypeOptions.value = await GetRuleTypeOptions();
{
id: "empty",
label: "",
},
{
id: "1",
label: "百分比范围",
unit: "%",
limit: {
down: 0,
up: 100,
},
},
{
id: "2",
label: "毫秒范围",
unit: "ms",
limit: {
down: 0,
up: "",
},
},
{
id: "3",
label: "秒范围",
unit: "s",
limit: {
down: 0,
up: "",
},
},
{
id: "4",
label: "个范围",
unit: "",
limit: {
down: 0,
up: "",
},
},
{
id: "5",
label: "温度范围",
unit: "",
limit: {
down: "",
up: "",
},
},
];
arr.forEach((e) => {
ruleTypeOptions.value[e.id] = e;
});
}; };
const ruleHeaders = [ const ruleHeaders = [
{ {
......
export const Empty = (key) => {
return !key || key == "empty"
}
\ No newline at end of file
...@@ -84,6 +84,7 @@ ...@@ -84,6 +84,7 @@
import { computed, nextTick, onBeforeMount, reactive, ref } from "vue"; import { computed, nextTick, onBeforeMount, reactive, ref } from "vue";
import gapTitle from "@/components/gap-title.vue"; import gapTitle from "@/components/gap-title.vue";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { GetRuleTypeOptions } from "./interface.js";
const props = defineProps({ const props = defineProps({
form: { form: {
type: Object, type: Object,
...@@ -96,61 +97,7 @@ const props = defineProps({ ...@@ -96,61 +97,7 @@ const props = defineProps({
}); });
const ruleTypeOptions = ref({}); const ruleTypeOptions = ref({});
const getRuleTypeOptions = async (cb) => { const getRuleTypeOptions = async (cb) => {
let arr = [ ruleTypeOptions.value = await GetRuleTypeOptions();
{
id: "empty",
label: "",
},
{
id: "1",
label: "百分比范围",
unit: "%",
limit: {
down: 0,
up: 100,
},
},
{
id: "2",
label: "毫秒范围",
unit: "ms",
limit: {
down: 0,
up: "",
},
},
{
id: "3",
label: "秒范围",
unit: "s",
limit: {
down: 0,
up: "",
},
},
{
id: "4",
label: "个范围",
unit: "",
limit: {
down: 0,
up: "",
},
},
{
id: "5",
label: "温度范围",
unit: "",
limit: {
down: "",
up: "",
},
},
];
arr.forEach((e) => {
ruleTypeOptions.value[e.id] = e;
});
await nextTick();
cb && cb(); cb && cb();
}; };
const state = reactive({ const state = reactive({
......
...@@ -113,4 +113,41 @@ export const Save = (res, p, cb) => { ...@@ -113,4 +113,41 @@ export const Save = (res, p, cb) => {
ElMessage.error(res.data.data) ElMessage.error(res.data.data)
} }
}) })
}
export 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: "",
},
];
let obj = {}
arr.forEach((e) => {
obj[e.id] = e;
});
return obj
} }
\ No newline at end of file
...@@ -94,6 +94,8 @@ import gapTitle from "@/components/gap-title.vue"; ...@@ -94,6 +94,8 @@ import gapTitle from "@/components/gap-title.vue";
import Gateway from "./gateway.vue"; import Gateway from "./gateway.vue";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import axios from "@/request/http.js"; import axios from "@/request/http.js";
import { Empty } from "../modules/env.js";
const showSelect = ["=~", "!~"]; const showSelect = ["=~", "!~"];
const selectRule = ref({ const selectRule = ref({
all: "全部", all: "全部",
...@@ -161,7 +163,7 @@ const state = reactive({ ...@@ -161,7 +163,7 @@ const state = reactive({
const module_data = ref({}); const module_data = ref({});
const alert_rule_type = ref(""); const alert_rule_type = ref("");
const isEmpty = computed(() => { const isEmpty = computed(() => {
return !alert_rule_type.value || alert_rule_type.value == "empty"; return Empty(alert_rule_type.value);
}); });
const chooseWarnIndicator = () => { const chooseWarnIndicator = () => {
axios axios
...@@ -226,7 +228,7 @@ const formFormat = computed(() => { ...@@ -226,7 +228,7 @@ const formFormat = computed(() => {
warn_target, warn_target,
warn_type, warn_type,
isEmpty: isEmpty.value, isEmpty: isEmpty.value,
alert_rule_type: module_data.value, alert_rule_type: module_data.value.alert_rule_type,
}; };
if (!isEmpty.value) { if (!isEmpty.value) {
obj = { obj = {
...@@ -285,7 +287,6 @@ const ruleHeaders = [ ...@@ -285,7 +287,6 @@ const ruleHeaders = [
]; ];
const rule_rows = computed(() => props.form?.ruleRows || []); const rule_rows = computed(() => props.form?.ruleRows || []);
const info = () => { const info = () => {
console.log(1);
state.form.warn_type = state.form.warn_type =
props.form.warn_target && props.form.warn_type ? [props.form.warn_target, props.form.warn_type] : []; props.form.warn_target && props.form.warn_type ? [props.form.warn_target, props.form.warn_type] : [];
state.form.warn_indicator = props.form.warn_indicator; state.form.warn_indicator = props.form.warn_indicator;
......
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