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

feat:

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