NEZ-2494 feat: 处理chart rules 优化未生效的问题

This commit is contained in:
zhangyu
2023-01-05 17:53:42 +08:00
parent 3661eb6584
commit b527f54500
8 changed files with 75 additions and 21 deletions

View File

@@ -16,7 +16,7 @@
<!-- asset --> <!-- asset -->
<div v-if="from === fromRoute.asset" style="display: flex"> <div v-if="from === fromRoute.asset" style="display: flex">
<pick-time ref="pickTime" v-model="searchTime" :refresh-data-func="dateChange" :use-chart-unit="false" :sign="'panel' + obj.id"></pick-time> <pick-time ref="pickTime" v-model="searchTime" :refresh-data-func="dateChange" :use-chart-unit="false" :sign="'panel' + obj.id"></pick-time>
<button id="panel-add-chart" v-has="'main_add'" :title="$t('overall.createChart')" class="top-tool-btn margin-r-10" type="button" @click="addChart"> <button id="panel-add-chart" v-has="'main_add'" :title="$t('overall.createChart')" class="top-tool-btn margin-r-10" type="button" @click="addChartBefore">
<i class="nz-icon-create-square nz-icon"></i> <i class="nz-icon-create-square nz-icon"></i>
</button> </button>
<top-tool-more-options <top-tool-more-options
@@ -244,16 +244,25 @@ export default {
enable: { enable: {
legend: true, legend: true,
valueMapping: false, valueMapping: false,
thresholds: false thresholds: false,
visibility: false
}, },
thresholdShow: true, thresholdShow: true,
thresholds: [{ value: undefined, color: randomcolor() }] thresholds: [{ value: undefined, color: randomcolor() }],
showHeader: 1,
visibility: {
varName: '',
operator: 'equal',
varValue: '',
result: 'show'
}
}, },
elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1 }], elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1, orderNum: 0 }],
panel: '', panel: '',
sync: 0, sync: 0,
remark: '', remark: '',
groupId: '' groupId: '',
varType: ''
}, },
pageObj: { pageObj: {
pageNo: 1, pageNo: 1,
@@ -347,9 +356,11 @@ export default {
/* 图表相关操作--start */ /* 图表相关操作--start */
addChart () { addChart () {
this.chart = this.newChart() this.chart = this.newChart()
this.$store.dispatch('dispatchEditChart', { this.chart.param.thresholds = [{ value: undefined, color: randomcolor() }]
chart: '', this.chart.panelId = this.showPanel.id
type: 'add' this.chart.panelName = this.showPanel.name
this.$nextTick(() => {
this.$refs.addChartModal.isStable = 'stable'
}) })
}, },
addChartByTemp () { addChartByTemp () {
@@ -441,6 +452,9 @@ export default {
} }
}) })
} }
this.$nextTick(() => {
this.$refs.addChartModal.isStable = 'stable'
})
} else { } else {
this.$message.error(res.msg) this.$message.error(res.msg)
} }
@@ -774,6 +788,12 @@ export default {
} }
}) })
}, },
addChartBefore () {
this.$store.dispatch('dispatchEditChart', {
chart: '',
type: 'add'
})
},
disposeChart () { disposeChart () {
const chartInfo = this.$store.getters.getChart const chartInfo = this.$store.getters.getChart
const groupId = this.$store.getters.getGroupId const groupId = this.$store.getters.getGroupId
@@ -882,6 +902,8 @@ export default {
handler (n) { handler (n) {
if (n) { if (n) {
this.disposeChart() this.disposeChart()
} else {
this.$refs.addChartModal.isStable = 'instability'
} }
} }
}, },

View File

@@ -13,8 +13,8 @@ export const clickoutside = {
const unsavedChange = localStorage.getItem('nz-unsaved-change') const unsavedChange = localStorage.getItem('nz-unsaved-change')
let oldValue let oldValue
try { try {
oldValue = JSON.parse(JSON.stringify(binding.value.obj)) el.__oldValue__ = JSON.parse(JSON.stringify(binding.value.obj))
el.__newValue__ = oldValue el.__newValue__ = el.__oldValue__
} catch (e) { } catch (e) {
} }
@@ -37,10 +37,9 @@ export const clickoutside = {
if (!flag) { if (!flag) {
return false return false
} }
if (oldValue) { if ( el.__oldValue__) {
console.log(oldValue, el.__newValue__)
// const newValue = JSON.parse(JSON.stringify(binding.value.obj)) // const newValue = JSON.parse(JSON.stringify(binding.value.obj))
if (unsavedChange == 'on' && !isEqual(oldValue, el.__newValue__) && !el.isShow) { if (unsavedChange == 'on' && !isEqual( el.__oldValue__, el.__newValue__) && !el.isShow) {
el.isShow = true el.isShow = true
MessageBox.confirm(i18n.t('tip.confirmCancel'), { MessageBox.confirm(i18n.t('tip.confirmCancel'), {
confirmButtonText: i18n.t('tip.yes'), confirmButtonText: i18n.t('tip.yes'),
@@ -75,6 +74,9 @@ export const clickoutside = {
}, 100) }, 100)
}, },
update (el, binding, vnode) { update (el, binding, vnode) {
if (binding.arg && binding.arg != 'stable') {
el.__oldValue__ = JSON.parse(JSON.stringify(binding.value.obj))
}
el.__newValue__ = binding.value.obj el.__newValue__ = binding.value.obj
}, },
unbind (el, binding) { unbind (el, binding) {

View File

@@ -9,7 +9,9 @@ export default {
emit: '' emit: ''
}, },
closeMessage: null, closeMessage: null,
uuid: getUUID() uuid: getUUID(),
isStable: 'instability',
stableTime: null
} }
}, },
mounted () { mounted () {

View File

@@ -1,5 +1,5 @@
<template> <template>
<div v-clickoutside="{obj: editAlertRule, func: clickOutside}" class="right-box right-box-alert-rule"> <div v-clickoutside="{obj: editAlertRule, func: clickOutside}" class="right-box right-box-alert-rule" ref="rightBox">
<div class="right-box__header"> <div class="right-box__header">
<!-- begin--标题--> <!-- begin--标题-->
<div class="header__title">{{alertRule.id ? $t("alert.config.editAlertConfig") : $t("overall.createAlertRule")}}</div> <div class="header__title">{{alertRule.id ? $t("alert.config.editAlertConfig") : $t("overall.createAlertRule")}}</div>
@@ -406,7 +406,7 @@ export default {
} }
], ],
showMetrics: true, showMetrics: true,
showSnmpTrap: true, showSnmpTrap: false,
showTypeSelect: false, showTypeSelect: false,
editAlertRule: {}, editAlertRule: {},
rules: { rules: {
@@ -664,7 +664,13 @@ export default {
this.showTypeSelect = !!this.editAlertRule.id // 当 edit 时禁用 type下拉框 this.showTypeSelect = !!this.editAlertRule.id // 当 edit 时禁用 type下拉框
if (n.type === 1) { if (n.type === 1) {
this.editAlertRule.type = 1 this.editAlertRule.type = 1
setTimeout(() => {
this.showSnmpTrap = true
}, 150)
} else if (n.type === 2) { } else if (n.type === 2) {
setTimeout(() => {
this.showSnmpTrap = true
}, 150)
this.showMetrics = false // showMetrics 为 false 时,展示 Logs label this.showMetrics = false // showMetrics 为 false 时,展示 Logs label
this.editAlertRule.type = 2 this.editAlertRule.type = 2
} else if (n.type === 3) { } else if (n.type === 3) {
@@ -680,6 +686,10 @@ export default {
} }
}) })
}) })
} else {
setTimeout(() => {
this.showSnmpTrap = true
}, 150)
} }
} }
} }

View File

@@ -1,5 +1,5 @@
<template> <template>
<div v-clickoutside="{obj: editChart, func:clickOutside}" :class="boxClass" class="right-box right-box-chart"> <div v-clickoutside:[isStable]="{obj: editChart, func:clickOutside}" :class="boxClass" class="right-box right-box-chart">
<transition v-if="from !== 'chartTemp'" name="right-box"> <transition v-if="from !== 'chartTemp'" name="right-box">
<!-- <panel-box v-if="!showPanel.type" ref="panelBox2" :panel="panel" @reload="panelReload"></panel-box>--> <!-- <panel-box v-if="!showPanel.type" ref="panelBox2" :panel="panel" @reload="panelReload"></panel-box>-->
</transition> </transition>
@@ -607,6 +607,10 @@ export default {
} }
} }
this.editChart = obj this.editChart = obj
if (this.stableTime) {
clearTimeout(this.stableTime)
this.stableTime = null
}
} }
}, },
'editChart.type': { 'editChart.type': {

View File

@@ -194,12 +194,13 @@ export default {
alertName: '', alertName: '',
linkObject: { id: '', name: '' }, linkObject: { id: '', name: '' },
expr: '', expr: '',
inr: 15,
state: 1, state: 1,
type: 1, type: 1,
unit: 2, unit: 2,
operator: '>', operator: '>',
last: 60, last: 60,
severityId: '', severityId: 1,
summary: '', summary: '',
description: '', description: '',
method: [], method: [],
@@ -359,6 +360,7 @@ export default {
if (response.code === 200) { if (response.code === 200) {
this.object = { this.object = {
...response.data, ...response.data,
expr: response.data.expression,
method: response.data.method ? response.data.method.split(',').map(item => Number(item)) : [], method: response.data.method ? response.data.method.split(',').map(item => Number(item)) : [],
schedDays: response.data.schedDays ? response.data.schedDays.split(',').map(item => Number(item)) : [], schedDays: response.data.schedDays ? response.data.schedDays.split(',').map(item => Number(item)) : [],
receiverShow: response.data.receiver ? response.data.receiver.split(',').map(item => Number(item)) : [] receiverShow: response.data.receiver ? response.data.receiver.split(',').map(item => Number(item)) : []

View File

@@ -260,11 +260,12 @@ export default {
result: 'show' result: 'show'
} }
}, },
elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1 }], elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1, orderNum: 0 }],
panel: '', panel: '',
sync: 0, sync: 0,
remark: '', remark: '',
groupId: '' groupId: '',
varType: ''
}, },
pageObj: { pageObj: {
pageNo: 1, pageNo: 1,
@@ -532,6 +533,9 @@ export default {
this.chart.param.thresholds = [{ value: undefined, color: randomcolor() }] this.chart.param.thresholds = [{ value: undefined, color: randomcolor() }]
this.chart.panelId = this.showPanel.id this.chart.panelId = this.showPanel.id
this.chart.panelName = this.showPanel.name this.chart.panelName = this.showPanel.name
this.$nextTick(() => {
this.$refs.addChartModal.isStable = 'stable'
})
}, },
addChartByTemp () { addChartByTemp () {
this.chart = JSON.parse(JSON.stringify(this.blankChartTemp)) this.chart = JSON.parse(JSON.stringify(this.blankChartTemp))
@@ -556,6 +560,9 @@ export default {
this.chart.panelId = this.showPanel.id this.chart.panelId = this.showPanel.id
this.chart.panelName = this.showPanel.name this.chart.panelName = this.showPanel.name
this.chart.isGroup = true this.chart.isGroup = true
this.$nextTick(() => {
this.$refs.addChartModal.isStable = 'stable'
})
}, },
newChart () { newChart () {
return JSON.parse(JSON.stringify(this.blankChart)) return JSON.parse(JSON.stringify(this.blankChart))
@@ -607,6 +614,9 @@ export default {
} }
}) })
} }
this.$nextTick(() => {
this.$refs.addChartModal.isStable = 'stable'
})
} else { } else {
this.$message.error(res.msg) this.$message.error(res.msg)
} }
@@ -1184,6 +1194,8 @@ export default {
handler (n) { handler (n) {
if (n) { if (n) {
this.disposeChart() this.disposeChart()
} else {
this.$refs.addChartModal.isStable = 'instability'
} }
} }
}, },

View File

@@ -179,9 +179,9 @@ const panel = {
store.commit('setPanelNowTimeType', playload.nowTimeType) store.commit('setPanelNowTimeType', playload.nowTimeType)
}, },
dispatchEditChart (store, playload) { dispatchEditChart (store, playload) {
store.commit('setShowRightBox', true)
store.commit('setChart', playload.chart) store.commit('setChart', playload.chart)
store.commit('setType', playload.type) store.commit('setType', playload.type)
store.commit('setShowRightBox', true)
}, },
dispatchHeaderH (store, playload) { dispatchHeaderH (store, playload) {
store.commit('setHeaderH', playload.headerH) store.commit('setHeaderH', playload.headerH)