diff --git a/.beagle.yml b/.beagle.yml index 851c5d9e23e045b90237955e29a45a2e7b68184b..efc73532c15a03b3baa6d7a1d933e4d51420b1ab 100644 --- a/.beagle.yml +++ b/.beagle.yml @@ -33,7 +33,8 @@ steps: # 定义流水线执行步骤,这些步骤将顺序执行 commands: # - npm install -g cnpm --registry=https://registry.npm.taobao.org # - cnpm install - - yarn + - npm install -g cnpm --registry=https://registry.npm.taobao.org + - cnpm install - export NODE_ENV=production - yarn build diff --git a/.vscode/settings.json b/.vscode/settings.json index 2c0882957ae57ac55273edbd87c616145a49b0f2..7616a04b50693f438126c14456288020a34e29dd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,18 +1,16 @@ { - "editor.defaultFormatter": "esbenp.prettier-vscode", - "GitCommitPlugin.ShowEmoji": false, - "editor.formatOnSave": false, - "editor.codeActionsOnSave": { - "source.fixAll.eslint": true - }, - "volar.inlayHints.eventArgumentInInlineHandlers": false, - // "path-intellisense.mappings": { - // "@": "${workspaceFolder}/src" - // }, - // 文件保存自动格式化 - "editor.formatOnSave": true, - "[vue]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "vue.codeActions.enabled": false -} + "editor.defaultFormatter": "esbenp.prettier-vscode", + "GitCommitPlugin.ShowEmoji": false, + "volar.inlayHints.eventArgumentInInlineHandlers": false, + "path-intellisense.mappings": { + "@": "${workspaceFolder}/src" + }, + // 文件保存自动格式化 + "editor.formatOnSave": true, + "[vue]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + } +} \ No newline at end of file diff --git a/package.json b/package.json index af9316dcb9102f2f4437665592a02f0d21de4db2..6cdd8f98b9c61b722b63fc3af23036993c324a2c 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,14 @@ "serve": "vite preview" }, "dependencies": { + "@codemirror/theme-one-dark": "^6.1.2", "@element-plus/icons-vue": "^2.0.6", "@wangeditor/editor": "^5.1.14", "@wangeditor/editor-for-vue": "^5.1.12", "ace-builds": "^1.9.6", "axios": "^0.21.1", "clipboard": "^2.0.11", + "codemirror": "^6.0.1", "crypto-js": "^4.1.1", "echarts": "^5.3.3", "element-plus": "^2.2.19", @@ -26,8 +28,9 @@ "string-format": "^2.0.0", "uuid": "^8.3.2", "vue": "^3.2.31", + "vue-codemirror": "^6.1.1", "vue-demi": "^0.14.5", - "vue-i18n": "^9.1.7", + "vue-i18n": "^9.5.0", "vue-router": "^4.0.10", "vue3-ace-editor": "^2.2.2", "vuex": "^4.0.2" diff --git a/src/bg-ui/bg-codemirror.vue b/src/bg-ui/bg-codemirror.vue new file mode 100644 index 0000000000000000000000000000000000000000..928b0ad6587f876f947d5a51d781a38ef2179df5 --- /dev/null +++ b/src/bg-ui/bg-codemirror.vue @@ -0,0 +1,79 @@ + + + + + + diff --git a/src/bg-ui/index.js b/src/bg-ui/index.js index 1374c3573eacf8a4e885219b22011ca3ee9c8723..d0d4c2d1367da35e18f2e687071274df29dfcb58 100644 --- a/src/bg-ui/index.js +++ b/src/bg-ui/index.js @@ -21,6 +21,7 @@ import BgTags from "./bg-tags.vue"; import BgSwitch from "./bg-switch.vue"; import BgRichText from "./bg-rich-text.vue"; import BgCodeEditor from "./bg-code-editor.vue"; +import BgCodemirror from "./bg-codemirror.vue"; import BgFilter from "./bg-filter.vue"; import BgSort from "./bg-sort.vue"; import BgFilterDate from "./bg-filter-date.vue"; @@ -58,6 +59,7 @@ const components = { BgSwitch, // 开关 BgRichText, // 富文本 BgCodeEditor, //代码输入 + BgCodemirror, //代码输入 BgFilter, // 首页筛选 BgSort, // 首页排序 BgFilterDate, diff --git a/src/components/manual-distribution/index.vue b/src/components/manual-distribution/index.vue index 37231f6cd04388d079ecf285344ff3745628b04c..c56e87a8af8bb366f1fc1e521a88424117f12ea6 100644 --- a/src/components/manual-distribution/index.vue +++ b/src/components/manual-distribution/index.vue @@ -4,12 +4,7 @@
-
+
- + -
是否确定删除 {{ activeTree.own.label }} 这个预警分类
+
+ 是否确定删除 {{ activeTree.own.label }} 这个预警{{ activeTree.node.level == 1 ? "分类" : "对象" }} +
-
+
@@ -23,6 +23,7 @@
+
@@ -125,6 +126,9 @@ const labelData = [ const info = ref({}); const warning_scope_label = ref([]); const watning_scope_data = ref({}); +const watning_scope_data_key = computed(() => { + return Object.keys(watning_scope_data.value); +}); const advanced_label = [ [ { @@ -210,11 +214,12 @@ const getInfoData = () => { data.alert_range.forEach((e) => { warning_scope_label.value.push([ { - prop: e.name, + prop: e.chinese_name || e.name, label: e.chinese_name || e.name, }, ]); - watning_scope_data.value[e.name] = e.value == ".*" ? "全部" : `${selectRule[e.compare]} ${e.value}`; + watning_scope_data.value[e.chinese_name || e.name] = + e.value == ".*" ? "全部" : `${selectRule[e.compare]} ${e.value}`; }); let isEmpty = Empty(data.alert_rule_type, ruleTypeOptions.value); if (!isEmpty) { @@ -230,7 +235,11 @@ const getInfoData = () => { ruleRows.value = data.alert_condition.map((e) => { let min = e.thresholds_min + unit; if (e.thresholds_min === undefined) { - if (ruleTypeOptions.value[data.alert_rule_type].down !== "") { + if ( + data.alert_rule_type && + ruleTypeOptions.value[data.alert_rule_type] && + ruleTypeOptions.value[data.alert_rule_type]?.down !== "" + ) { min = ruleTypeOptions.value[data.alert_rule_type].down + unit; } else { min = WIELESS_SMALL; @@ -238,10 +247,14 @@ const getInfoData = () => { } let max = e.thresholds_max + unit; if (e.thresholds_max === undefined) { - if (ruleTypeOptions.value[data.alert_rule_type].up !== "") { + if ( + data.alert_rule_type && + ruleTypeOptions.value[data.alert_rule_type] && + ruleTypeOptions.value[data.alert_rule_type].up !== "" + ) { max = ruleTypeOptions.value[data.alert_rule_type].up + unit; } else { - max = WIELESS_SMALL; + max = WIELESS_BIG; } } return { diff --git a/src/page/main/forewarning/rule-set/edit/index.vue b/src/page/main/forewarning/rule-set/edit/index.vue index 0f134bf0c1b325d3e4c968e1128643a67451aecd..856efadaa011aaac58c8c98e1cb71d94a789e71c 100644 --- a/src/page/main/forewarning/rule-set/edit/index.vue +++ b/src/page/main/forewarning/rule-set/edit/index.vue @@ -32,9 +32,8 @@ const Cancle = () => { }; const add_form = ref(null); const SaveSubmit = async () => { - let res = await add_form.value.Submit(); + let { res, cb } = await add_form.value.Submit(); if (!res) return; - console.log("res: ", res); Save(res, { id }, () => { Cancle(); }); @@ -65,20 +64,20 @@ const getInfoData = () => { warn_indicator: data.metric_config_id, warn_target: findTypeBySecond(data.class_id)?.class_id || "", rule_type: data.alert_rule_type, + warning_scpoe_form: + data.alert_range?.map((e) => { + return { + ...e, + value: e.value == ".*" ? "" : e.value, + select: e.value == ".*" ? "all" : e.compare, + options: [], + }; + }) || [], }, }; 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, - value: e.value == ".*" ? "" : e.value, - select: e.value == ".*" ? "all" : e.compare, - options: [], - }; - }) || []; obj.type_com_ref.ruleRows = data.alert_condition?.map((e) => { return { diff --git a/src/page/main/forewarning/rule-set/modules/add-form.vue b/src/page/main/forewarning/rule-set/modules/add-form.vue index a46377cf61e92894444c7956501e2117f5b59c66..adb9d459537915c1924b54920b5a6435f2cbcb54 100644 --- a/src/page/main/forewarning/rule-set/modules/add-form.vue +++ b/src/page/main/forewarning/rule-set/modules/add-form.vue @@ -23,7 +23,8 @@ ref="type_com_ref" :is="typeCom[state.form.type_key]" :isEdit="isEdit" - :form="typrFormData"> + :form="typrFormData" + @update-duration="updateDuration">
@@ -108,6 +109,7 @@ import ManualDistributionForm from "@/components/manual-distribution/form.vue"; import Static from "./static.vue"; import Custom from "./custom.vue"; import { MAX_DAY } from "@/components/env.js"; +import { ElMessage } from "element-plus"; const props = defineProps({ row: { type: Object, @@ -151,6 +153,14 @@ const inputNum = () => { state.form.time = max; } }; + +const updateDuration = (data) => { + const { duration, duration_unit, check_period } = data; + state.form.time = duration; + state.form.unit = duration_unit; + state.form.inspection_cycle = check_period; +}; + const types = { static: "静态阈值", custom: "自定义", @@ -159,16 +169,6 @@ const changeType = async (key) => { state.form.type_key = key; form_ref.value.clearValidate(); }; -const durationOptions = [ - { - id: 1, - name: "直接产生预警", - }, - { - id: 2, - name: "当预警持续", - }, -]; const timeOptions = [10, 20, 60, 120, 180, 300]; const inspectionCycleOptions = ref([1, 3, 5, 10, 20]); const form_ref = ref(null); @@ -180,14 +180,26 @@ const Submit = async () => { let type_com_ref_valid = await type_com_ref.value.Submit(); let manual_distribution_form_valid = await manual_distribution_form.value.Submit(); if (form_valid && type_com_ref_valid && manual_distribution_form_valid) { - return { + let obj = { ...state.form, type_com_ref: type_com_ref.value?.form || {}, manual_distribution_form: manual_distribution_form.value?.form || {}, }; + return { + res: obj, + cb: () => { + if (!isEdit.value) { + setTimeout(() => { + type_com_ref.value.form_ref.resetFields(); + manual_distribution_form.value.form_ref.resetFields(); + form_ref.value.resetFields(); + }, 100); + } + }, + }; } ElMessage.error("有必填项没有填写"); - return; + return {}; }; watch( () => props.row, diff --git a/src/page/main/forewarning/rule-set/modules/custom.vue b/src/page/main/forewarning/rule-set/modules/custom.vue index 2bdd30265c6c5dfb9566a8a026efc64979550086..84a3527ac7785044ffee8f6e8592a09b66b6d70c 100644 --- a/src/page/main/forewarning/rule-set/modules/custom.vue +++ b/src/page/main/forewarning/rule-set/modules/custom.vue @@ -38,6 +38,7 @@
+
@@ -250,11 +251,10 @@ const inputNum = (index, key) => { if (state.form.ruleRows[index][key] == "") return; if (state.form.ruleRows[index][key] == "-") return; state.form.ruleRows[index][key] = `${state.form.ruleRows[index][key]}` - .replace(/[^\-?\d.]/g, "") //只允许输入负号,数字,小数点 - .replace(/(\-)+/, "$1") //过滤连续多个负号 - .replace(/(\.)+/, "$1") //过滤连续多个小数点 - .replace(/(\.\d+)\./g, "$1") //过滤出现多个小数点 - .replace(/(\d)\-/g, "$1"); //过滤处于非开头的负号 + .replace(/[^\-?\d.]/g, "") + .replace(/(\.)+/, "$1") + .replace(/(\.\d+)\.+/g, "$1") + .replace(/(\..*)\./g, "$1"); }; const changeWarningThresholdFrom = (index) => { let { down, up } = limit.value; @@ -274,18 +274,13 @@ const changeWarningThresholdFrom = (index) => { } let rows = setLimits(index); if (rows.length == 0) return; - try { - rows.forEach((e) => { - 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) { + let items = rows.filter((e, i) => { + let isPassDown = e.down !== "" ? +e.down <= +from : false; + let isLessUp = e.up !== "" ? +e.up >= +from : false; + let isLessDownAndPassUp = e.down !== "" && e.up !== "" && to !== "" ? +from < +e.down && +to > +e.up : false; + return (isPassDown && isLessUp) || isLessDownAndPassUp; + }); + if (items.length > 0) { ElMessage.error(`该范围已被设置`); state.form.ruleRows[index].from = ""; } @@ -308,18 +303,13 @@ const changeWarningThresholdTo = (index) => { } let rows = setLimits(index); if (rows.length == 0) return; - try { - rows.forEach((e) => { - 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) { + let items = rows.filter((e, i) => { + let isPassDown = e.down !== "" ? +e.down <= +to : false; + let isLessUp = e.up !== "" ? +e.up >= +to : false; + let isLessDownAndPassUp = e.down !== "" && e.up !== "" && from !== "" ? +from < +e.down && +to > +e.up : false; + return (isPassDown && isLessUp) || isLessDownAndPassUp; + }); + if (items.length > 0) { ElMessage.error(`该范围已被设置`); state.form.ruleRows[index].to = ""; } diff --git a/src/page/main/forewarning/rule-set/modules/gateway.vue b/src/page/main/forewarning/rule-set/modules/gateway.vue index 4de2d2629d55447f4db48c472b945a625299f1c0..ceb9298494842043301b66d24a0be33106bd6297 100644 --- a/src/page/main/forewarning/rule-set/modules/gateway.vue +++ b/src/page/main/forewarning/rule-set/modules/gateway.vue @@ -130,10 +130,20 @@ const state = reactive({ }, tableRules: { from: (index) => { - return [{ validator: (rule, value, callback) => validateFrom(rule, value, callback, index), trigger: "blur" }]; + return [ + { + validator: (rule, value, callback) => validateFrom(rule, value, callback, index), + trigger: "blur", + }, + ]; }, to: (index) => { - return [{ validator: (rule, value, callback) => validateTo(rule, value, callback, index), trigger: "blur" }]; + return [ + { + validator: (rule, value, callback) => validateTo(rule, value, callback, index), + trigger: "blur", + }, + ]; }, risk_level: [{ required: true, message: "请选择", trigger: "change" }], }, @@ -218,7 +228,7 @@ const limit = computed(() => { const changeWarningThresholdFrom = (index) => { let { down, up } = limit.value; let { from, to } = state.form.ruleRows[index]; - if (to !== "" && from !== "" && from > +to) { + if (to !== "" && from !== "" && from >= +to) { ElMessage.error(`下限不能大于上限`); state.form.ruleRows[index].from = ""; return; @@ -233,18 +243,13 @@ const changeWarningThresholdFrom = (index) => { } let rows = setLimits(index); if (rows.length == 0) return; - try { - 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) { + let items = rows.filter((e, i) => { + let isPassDown = e.down !== "" ? +e.down <= +from : false; + let isLessUp = e.up !== "" ? +e.up >= +from : false; + let isLessDownAndPassUp = e.down !== "" && e.up !== "" && to !== "" ? +from < +e.down && +to > +e.up : false; + return (isPassDown && isLessUp) || isLessDownAndPassUp; + }); + if (items.length > 0) { ElMessage.error(`该范围已被设置`); state.form.ruleRows[index].from = ""; } @@ -262,7 +267,7 @@ const inputNum = (index, key) => { const changeWarningThresholdTo = (index) => { let { down, up } = limit.value; let { from, to } = state.form.ruleRows[index]; - if (to !== "" && from !== "" && from > +to) { + if (to !== "" && from !== "" && from >= +to) { ElMessage.error(`下限不能大于上限`); state.form.ruleRows[index].to = ""; return; @@ -277,18 +282,13 @@ const changeWarningThresholdTo = (index) => { } let rows = setLimits(index); if (rows.length == 0) return; - try { - 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) { + let items = rows.filter((e, i) => { + let isPassDown = e.down !== "" ? +e.down <= +to : false; + let isLessUp = e.up !== "" ? +e.up >= +to : false; + let isLessDownAndPassUp = e.down !== "" && e.up !== "" && from !== "" ? +from < +e.down && +to > +e.up : false; + return (isPassDown && isLessUp) || isLessDownAndPassUp; + }); + if (items.length > 0) { ElMessage.error(`该范围已被设置`); state.form.ruleRows[index].to = ""; } diff --git a/src/page/main/forewarning/rule-set/modules/interface.js b/src/page/main/forewarning/rule-set/modules/interface.js index 585073cf424b38a333c9aa7832c32311d0897010..306e5c6deece87730a7fa26307b33adbef2ad954 100644 --- a/src/page/main/forewarning/rule-set/modules/interface.js +++ b/src/page/main/forewarning/rule-set/modules/interface.js @@ -1,6 +1,5 @@ import { ElMessage } from "element-plus"; import axios from "@/request/http.js"; -// max(container_fs_usage_bytes{pod!=\"\", namespace!=\"arms-prom\",namespace!=\"monitoring\"}) by (pod_name, namespace, device)/max(container_fs_limit_bytes{pod!=\"\"}) by (pod_name,namespace, device) * 100 const setParams = (res, { id }) => { let isEmpty = res.type_com_ref.isEmpty let params = { @@ -69,13 +68,12 @@ const setParams = (res, { id }) => { compare: e.select == 'all' ? '=~' : e.select } }), - // // 预警规则(下拉) + // 预警规则(下拉) alert_rule_type: res.type_com_ref.alert_rule_type, } } } let alert_condition = [] - // debugger; if (isEmpty) { alert_condition = [{ thresholds_max: 0, diff --git a/src/page/main/forewarning/rule-set/modules/static.vue b/src/page/main/forewarning/rule-set/modules/static.vue index b7b4306dab8b916460a1ba0d6cf8b663c1594090..38881c2bb151d1201e1e1a533e6562ba5742b7ab 100644 --- a/src/page/main/forewarning/rule-set/modules/static.vue +++ b/src/page/main/forewarning/rule-set/modules/static.vue @@ -89,7 +89,7 @@