diff --git a/nezha-fronted/src/assets/css/components/common/panel/panelVariables.scss b/nezha-fronted/src/assets/css/components/common/panel/panelVariables.scss new file mode 100644 index 000000000..a7bec5001 --- /dev/null +++ b/nezha-fronted/src/assets/css/components/common/panel/panelVariables.scss @@ -0,0 +1,64 @@ +.panel-variables-box{ + display: flex; + position: relative; + z-index: 1; + background: #fff; + padding-left: 10px; + padding-bottom: 5px; + .panel-variables-content{ + display: flex; + margin-right: 15px; + } + .variable-key{ + margin-right: 5px; + border: 1px solid $--border-color-base; + color: #33a2e5; + padding: 3px 5px; + border-radius: 4px; + } + .choose-box { + overflow: hidden; + width: calc(100% - 7px); + white-space: nowrap; + max-width: 200px; + text-overflow: ellipsis; + height: 30px; + border: 1px solid $--border-color-light; + padding-left: 8px; + display: flex; + align-items: center; + .nz-icon-arrow-down6{ + font-size: 12px; + color: $--color-text-secondary; + } + } + .choose-box-content{ + flex: 1; + white-space: nowrap; + text-overflow: ellipsis; + width: calc(100% - 24px); + overflow: hidden; + min-width: 24px; + } +} + +.panel-variables{ + .el-dropdown-menu__item { + padding: 0 5px 0 20px; + position: relative; + height: 36px; + } + .el-dropdown-menu__item .el-dropdown-menu__item-label{ + display: inline-block; + white-space: nowrap; + text-overflow: ellipsis; + width: calc(100% - 20px); + overflow: hidden; + min-width: 24px; + } + .nz-icon-check{ + position: absolute; + right: 5px; + color: $--color-warning; + } +} diff --git a/nezha-fronted/src/assets/css/components/index.scss b/nezha-fronted/src/assets/css/components/index.scss index 63f21c1d0..03a3e7e76 100644 --- a/nezha-fronted/src/assets/css/components/index.scss +++ b/nezha-fronted/src/assets/css/components/index.scss @@ -75,6 +75,7 @@ @import './common/searchInput.scss'; @import './common/timePicker.scss'; @import './common/filterSearch/filterSearch.scss'; +@import './common/panel/panelVariables.scss'; @import './layout/container.scss'; @import './layout/header.scss'; diff --git a/nezha-fronted/src/components/chart/panelChart.vue b/nezha-fronted/src/components/chart/panelChart.vue index a08b68178..965b98347 100644 --- a/nezha-fronted/src/components/chart/panelChart.vue +++ b/nezha-fronted/src/components/chart/panelChart.vue @@ -109,7 +109,8 @@ export default { showAllData: false, // 是否显示所有legend allDataLength: 0, severityData: this.$store.getters.severityData, // 告警级别的数据 - severityDataWeight: this.$store.getters.severityDataWeight + severityDataWeight: this.$store.getters.severityDataWeight, + myVariables: [] // isExportData: false } }, @@ -119,6 +120,9 @@ export default { }, headerHPadding () { // 50px header + padding 主要用于展开的空group return this.$store.getters.getHeaderHPadding + }, + variablesArr () { + return this.$store.getters.getVariablesArr } }, methods: { @@ -144,6 +148,8 @@ export default { }, // 参数 isRefresh 标识是否是刷新操作 getChartData (isRefresh, params) { // 获取chart的数据前的准备 主要用于处理时间参数 + this.chartData = [] + this.myVariables = [] this.loading = true // TODO assetInfo、endpointInfo、echarts等进行不同的处理 let startTime = '' @@ -223,7 +229,8 @@ export default { // if (isChartPie(this.chartInfo.type)) { // query += `&statistics=${this.chartInfo.param.statistics || 'last'}` // } - query += `&query=${encodeURIComponent(element.expression)}` + this.myVariables.push(this.variablesReplace(element.expression)) + query += `&query=${encodeURIComponent(this.variablesReplace(element.expression))}` return this.$get(query) }) if (this.multipleTime) { @@ -519,6 +526,16 @@ export default { this.loading = false } }, + variablesReplace (expression) { + let str = expression + this.variablesArr.forEach(item => { + const reg = new RegExp('\\$' + item.name, 'g') // 后续需要考虑 item,name 使用特殊字符的问题 + if (reg.test(expression)) { + str = str.replace(reg, item.checked.map(label => label.replace(/\"/g, '\\"').replace(/\'/g, "\\'")).join('|')) + } + }) + return str + }, getHexagonFigureData () { return new Promise(resolve => { this.$get('stat/alertMessage/topN', { size: 48, dimension: 'module' }).then(response => { @@ -705,6 +722,23 @@ export default { handler (n) { // console.log(n) } + }, + variablesArr: { + handler (n) { + const elements = this.chartInfo.elements || [] + const variables = elements.map((element) => { + return this.variablesReplace(element.expression) + }) + let flag = false + this.myVariables.forEach((item, index) => { + if (item !== variables[index]) { + flag = true + } + }) + if (flag) { + this.chartInfo.loaded && this.getChartData(true) + } + } } }, mounted () { diff --git a/nezha-fronted/src/components/common/panel/panelVariables.vue b/nezha-fronted/src/components/common/panel/panelVariables.vue new file mode 100644 index 000000000..902aa7458 --- /dev/null +++ b/nezha-fronted/src/components/common/panel/panelVariables.vue @@ -0,0 +1,380 @@ + + + + {{item.name}} + + + + {checkAllChange(item)}">{{$t('overall.all')}} + + + {checkedChange(item,value)}" v-if="item.multi"> + + {{value.label}} + + + + + + {{value.label}} + + + + + + + + + {{item.checked.map(value=> labelValue[item.name].find(labelObj=>labelObj.value === value).label).join(' + ')}} + + + + + + + + + + + diff --git a/nezha-fronted/src/components/common/rightBox/panelBox.vue b/nezha-fronted/src/components/common/rightBox/panelBox.vue index e6a5e043c..2f7c14ccb 100644 --- a/nezha-fronted/src/components/common/rightBox/panelBox.vue +++ b/nezha-fronted/src/components/common/rightBox/panelBox.vue @@ -100,6 +100,7 @@ + {{$t('dashboard.panel.queryExpression')}} @@ -114,7 +115,6 @@ - {{$t('dashboard.panel.queryExpression')}} @@ -132,10 +132,10 @@ + {{$t('dashboard.panel.multi')}} {{$t('dashboard.panel.multiTip')}} - {{$t('dashboard.panel.multi')}} @@ -151,10 +151,10 @@ + {{$t('dashboard.panel.allOption')}} {{$t('dashboard.panel.allOptionTip')}} - {{$t('dashboard.panel.allOption')}} @@ -185,7 +185,7 @@ @@ -200,7 +200,7 @@ @@ -218,7 +218,7 @@ {{ $t("dashboard.panel.prevDay") }} {{ $t("dashboard.panel.prevWeek") }} - {{ $t("dashboard.panel.prevMonth") }} + {{ $t("config.menus.parent") }} this.editPanel.param.report.schedule.etime) { - this.editPanel.param.report.schedule.stime = '' + if (flag) { + if (this.editPanel.param.report.schedule.etime) { + if (this.editPanel.param.report.schedule.stime > this.editPanel.param.report.schedule.etime) { + this.editPanel.param.report.schedule.stime = '' this.$message.error(this.$t('alert.silence.timeError')) - } - } - } else { - if (this.editPanel.param.report.schedule.stime) { - if (this.editPanel.param.report.schedule.stime > this.editPanel.param.report.schedule.etime) { + } + } + } else { + if (this.editPanel.param.report.schedule.stime) { + if (this.editPanel.param.report.schedule.stime > this.editPanel.param.report.schedule.etime) { this.editPanel.param.report.schedule.etime = '' - this.$message.error(this.$t('alert.silence.timeError')) - } - } - } - } + this.$message.error(this.$t('alert.silence.timeError')) + } + } + } + } }, watch: { obj: { diff --git a/nezha-fronted/src/components/page/config/dc.vue b/nezha-fronted/src/components/page/config/dc.vue index 22d0ac458..bf517adf9 100644 --- a/nezha-fronted/src/components/page/config/dc.vue +++ b/nezha-fronted/src/components/page/config/dc.vue @@ -252,7 +252,6 @@ export default { return this.regNum.test(val) }, addCabinet (params) { - console.log('addCabinet') if (params) { this.cabinet.idcId = params.dcid } @@ -270,7 +269,6 @@ export default { }) }, closeRightBox (refresh) { - console.log('closeRightBox') this.rightBox.show = false this.cabinetBoxShow = false this.$store.dispatch('addCabinet', { dcid: '', cabinetBoxShow: false }) diff --git a/nezha-fronted/src/components/page/dashboard/panel.vue b/nezha-fronted/src/components/page/dashboard/panel.vue index 8be7c3722..0e36736cc 100644 --- a/nezha-fronted/src/components/page/dashboard/panel.vue +++ b/nezha-fronted/src/components/page/dashboard/panel.vue @@ -92,7 +92,7 @@ - + { if (res.code === 200) { this.panel = res.data.list[0] - if (!this.panel.param.report) { + if (!this.$loadsh.get(this.panel, 'param.report', '')) { this.panel = { ...this.panel, param: { @@ -783,8 +797,64 @@ export default { report: { enable: true, range: { type: 'previous', interval: 1, unit: 'day' }, schedule: { type: 2, repeat: 1, nums: [], stime: '2022-06-07 15:00:00', etime: '2022-06-19 15:00:00' }, receivers: [1] }, chartShare: 'none', - variables: [{ show: true, type: 'custom', multi: true, allOption: true, name: 'a', customOptions: 'z:1', expression: '', regex: '' }] + variables: [ + { show: true, type: 'custom', multi: true, allOption: true, name: 'mazy', customOptions: 'z:1, b:z:1, a,c:123', expression: '', regex: '' }, + { show: true, type: 'custom', multi: true, allOption: false, name: 'mzy', customOptions: 'z:1, b:z:1, a,c:123', expression: '', regex: '' }, + { show: true, type: 'custom', multi: false, allOption: false, name: 'zy', customOptions: 'z:1, b:z:1, a,c:123', expression: '', regex: '' }, + { show: true, type: 'custom', multi: false, allOption: true, name: 'azy', customOptions: 'z:1, b:z:1, a,c:123', expression: '', regex: '' } + ] } + this.variables = [ + { show: true, type: 'custom', multi: true, allOption: true, name: 'mazy', customOptions: 'z:1, b:z:1, a,c:123', expression: '', regex: '' }, + { show: true, type: 'custom', multi: true, allOption: false, name: 'mzy', customOptions: 'z:1, b:z:1, a,c:123', expression: '', regex: '' }, + { show: true, type: 'custom', multi: false, allOption: false, name: 'zy', customOptions: 'z:1, b:z:1, a,c:123', expression: '', regex: '' }, + { show: true, type: 'custom', multi: false, allOption: true, name: 'azy', customOptions: 'z:1, b:z:1, a,c:123', expression: '', regex: '' }, + { + name: 'bbb', + type: 'query', + multi: false, + allOption: true, + expression: 'label_names()', + regex: '/a\.*/', + show: true + }, + { + name: 'ccc', + type: 'query', + multi: false, + allOption: true, + expression: 'label_values(up, asset)', + regex: '', + show: true + }, + { + name: 'ddd', + type: 'query', + multi: true, + allOption: true, + expression: 'label_values(asset)', + regex: '', + show: true + }, + { + name: 'eeee', + type: 'query', + multi: false, + allOption: true, + expression: 'label_values(up, endpoint)', + regex: '/.*-(?.*)-(?.*)-.*/', + show: true + }, + { + name: 'fff', + type: 'query', + multi: false, + allOption: true, + expression: 'query_result(node_filefd_allocated{module="OLAP-Node-Exporter"})', + regex: '/asset="(?[^"]+)\.*\asset_id="(?[^"]+)/', + show: true + } + ] }).catch((error) => { // console.log('error................'+JSON.stringify(error)); if (error) { diff --git a/nezha-fronted/src/store/panel.js b/nezha-fronted/src/store/panel.js index b3c167f31..c0a7bd732 100644 --- a/nezha-fronted/src/store/panel.js +++ b/nezha-fronted/src/store/panel.js @@ -24,7 +24,8 @@ const panel = { // timeSeries类型图表联动 isConnect: 'none', // 当前鼠标所在的图表id - currentMousemove: 0 + currentMousemove: 0, + variablesArr: [] }, mutations: { setShowRightBox (state, flag) { @@ -89,6 +90,9 @@ const panel = { // 设置当前鼠标所在的图表id (timeSeries类型图表联动) setCurrentMousemove (state, value) { state.currentMousemove = value + }, + setVariablesArr (state, value) { + state.variablesArr = value } }, getters: { @@ -139,6 +143,9 @@ const panel = { }, getAddCabinetBoxParams (state) { return state.addCabinetBoxParams + }, + getVariablesArr (state) { + return state.variablesArr } }, actions: { @@ -177,6 +184,9 @@ const panel = { showTopology (store, chartInfo) { store.commit('setTopologyChartInfo', chartInfo) store.commit('setTopologyShow', true) + }, + dispatchVariablesArr (store, variablesArr) { + store.commit('setVariablesArr', variablesArr) } } }