diff --git a/nezha-fronted/src/components/chart/chartHeader.vue b/nezha-fronted/src/components/chart/chartHeader.vue index 014538929..14b5dd365 100644 --- a/nezha-fronted/src/components/chart/chartHeader.vue +++ b/nezha-fronted/src/components/chart/chartHeader.vue @@ -65,7 +65,7 @@ export default { this.$emit('refresh') }, editChart () { - + this.$emit('edit-chart', this.chartInfo) }, removeChart () { diff --git a/nezha-fronted/src/components/chart/chartList.vue b/nezha-fronted/src/components/chart/chartList.vue index 3f37fe297..10bbc42ca 100644 --- a/nezha-fronted/src/components/chart/chartList.vue +++ b/nezha-fronted/src/components/chart/chartList.vue @@ -26,6 +26,7 @@ > - + diff --git a/nezha-fronted/src/components/common/rightBox/chart/chartRightBox.vue b/nezha-fronted/src/components/common/rightBox/chart/chartRightBox.vue index e051fb13a..8e349d61b 100644 --- a/nezha-fronted/src/components/common/rightBox/chart/chartRightBox.vue +++ b/nezha-fronted/src/components/common/rightBox/chart/chartRightBox.vue @@ -163,15 +163,16 @@ export default { Promise.all(arr).then(res => { this.editChart.panelId = this.panelId const params = JSON.parse(JSON.stringify(this.editChart)) - delete params.panel if (!params.groupId) { - params.groupId = -1 + params.groupId = 0 } + delete params.panel if (params.id) { // 修改 this.$put('visual/panel/chart', params).then(response => { if (response.code === 200) { this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') }) this.esc(true) + this.$emit('on-create-success') } else { this.$message.error(response.msg) } @@ -181,6 +182,7 @@ export default { if (response.code === 200) { this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') }) this.esc(true) + this.$emit('on-create-success') } else { this.$message.error(response.msg) } diff --git a/nezha-fronted/src/components/common/rightBox/chart/systemChartConfig.vue b/nezha-fronted/src/components/common/rightBox/chart/systemChartConfig.vue index 39f8f888c..b3fae2f5e 100644 --- a/nezha-fronted/src/components/common/rightBox/chart/systemChartConfig.vue +++ b/nezha-fronted/src/components/common/rightBox/chart/systemChartConfig.vue @@ -428,7 +428,7 @@ export default { }, watch: { selectList (n) { - if (n.length === 1) { + if (n.length === 1 && !this.chartConfig.param.systemSelect) { this.chartConfig.param.systemSelect = this.selectList[0].name } } @@ -439,14 +439,21 @@ export default { }, getSystemData () { this.loading = true - this.$get('/mock/getSystemData').then(res => { + this.$get('/sys/config/key/stat_query_json').then(res => { this.loading = false if (res.code === 200) { - this.systemData = res.data.list - if (res.data.list.length) { - this.chartConfig.param.system = res.data.list[0].name - this.groupList = res.data.list[0].group - this.selectList = res.data.list[0].select + this.systemData = JSON.parse(res.data.paramValue) + if (this.systemData.length) { + if (!this.chartConfig.param.system) { + this.chartConfig.param.system = this.systemData[0].name + this.groupList = this.systemData[0].group + this.selectList = this.systemData[0].select + } else { + const system = this.systemData.find(item => item.name === this.chartConfig.param.system) + this.chartConfig.param.system = system.name + this.groupList = system.group + this.selectList = system.select + } this.$refs.chartForm.clearValidate() } } else { diff --git a/nezha-fronted/src/components/page/dashboard/panel.vue b/nezha-fronted/src/components/page/dashboard/panel.vue index b5d0a9f77..6c4f9516f 100644 --- a/nezha-fronted/src/components/page/dashboard/panel.vue +++ b/nezha-fronted/src/components/page/dashboard/panel.vue @@ -90,7 +90,7 @@ :from="fromRoute.panel" :panel-lock="panelLock" :time-range="searchTime" - @on-edit-chart="editChart" + @edit-chart="editChart" @on-refresh-time="refreshTime" @on-remove-chart="delChart" @on-add-group-item-chart="addGroupItem" @@ -191,7 +191,7 @@ export default { name: '', type: 'line', span: 4, - datasource: '1', + datasource: 'metrics', height: 4, unit: 2, param: { @@ -205,7 +205,7 @@ export default { panel: '', sync: 0, remark: '', - groupId: -1 + groupId: '' }, pageObj: { pageNo: 1, @@ -385,6 +385,7 @@ export default { }, // 编辑图表信息,打开编辑弹窗 editChart (data, copy) { + console.log(456) if (copy) { this.chart = JSON.parse(JSON.stringify(data)) this.chart.panelId = this.showPanel.id @@ -394,19 +395,14 @@ export default { this.$get('visual/panel/chart/' + data.id).then(res => { if (res.code === 200) { const chartData = res.data.data - if (typeof chartData.param === 'string') { - chartData.param = chartData.param ? JSON.parse(chartData.param) : {} - } - if (!chartData.param) { - chartData.param = { url: '', threshold: '' } - } else if (!chartData.param.threshold) { - chartData.param.threshold = '' - } else if (!chartData.param.url) { - chartData.param.url = '' - } this.chart = JSON.parse(JSON.stringify(chartData)) this.chart.panelId = this.showPanel.id this.chart.panelName = this.showPanel.name + this.chart.param = JSON.parse(this.chart.param) + this.chart.datasource = 'metrics' + if (!this.chart.groupId || this.chart.groupId == -1) { + this.chart.groupId = '' + } this.rightBox.chart.show = true } else { this.$message.error(res.msg)