feat:notebook chart新增编辑功能

This commit is contained in:
18317449825
2023-09-19 22:07:39 +08:00
parent 730cae9f67
commit 65e528f966
4 changed files with 56 additions and 48 deletions

View File

@@ -92,7 +92,6 @@ export default {
delete chartOption.yAxis[1].max delete chartOption.yAxis[1].max
} }
} }
console.log(chartOption)
return chartOption return chartOption
}, },
getMinMaxFromData (originalDatas, chartUnit = 2, params) { getMinMaxFromData (originalDatas, chartUnit = 2, params) {

View File

@@ -166,12 +166,6 @@ export default {
notebookList notebookList
}, },
methods: { methods: {
getId (arr) { // 获取当前列表最大的id
const maxIdElement = arr.reduce(function (prev, current) {
return (prev.id > current.id) ? prev : current
})
return maxIdElement.id + 1
},
done () { done () {
let charts = this.$lodash.cloneDeep(this.$refs.notebookList.copyDataList) let charts = this.$lodash.cloneDeep(this.$refs.notebookList.copyDataList)
charts = charts.filter(item => item.name !== 'groupTemp') charts = charts.filter(item => item.name !== 'groupTemp')
@@ -205,8 +199,17 @@ export default {
// 图表创建成功回调panel页面进行图表的刷新 // 图表创建成功回调panel页面进行图表的刷新
createSuccess (chart) { createSuccess (chart) {
delete chart.panelName delete chart.panelName
// this.$refs.notebookList.copyDataList.push(chart) chart.loaded = false
this.dataList.push(chart) if (chart.id) {
const index = this.$refs.notebookList.copyDataList.findIndex(item => item.id == chart.id)
this.$refs.notebookList.copyDataList.splice(index, 1, chart)
} else {
const id = this.getMaxId(this.$refs.notebookList.copyDataList) + 1
chart.id = id
chart.i = id
this.$refs.notebookList.copyDataList.push(chart)
}
this.$refs.notebookList.onScroll(this.scrollbarWrap.scrollTop)
this.$store.dispatch('clearPanel') this.$store.dispatch('clearPanel')
}, },
addNotebook (position) { addNotebook (position) {
@@ -216,6 +219,7 @@ export default {
editChart (data, copy) { editChart (data, copy) {
if (copy) { if (copy) {
this.chart = JSON.parse(JSON.stringify(data)) this.chart = JSON.parse(JSON.stringify(data))
this.chart.y = this.chart.y + 0.01
this.chart.panelName = this.showPanel.name this.chart.panelName = this.showPanel.name
this.chart.id = '' this.chart.id = ''
this.chart.elements.forEach((item) => { this.chart.elements.forEach((item) => {
@@ -226,47 +230,24 @@ export default {
if (this.chart.datasource !== 'metrics' && this.chart.datasource !== 'log') { if (this.chart.datasource !== 'metrics' && this.chart.datasource !== 'log') {
delete this.chart.elements delete this.chart.elements
} }
if (!this.chart.groupId || this.chart.groupId == -1) {
this.chart.groupId = ''
}
if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) {
this.chart.param.collapse = false
}
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.addChartModal.isStable = 'stable' this.$refs.addChartModal.isStable = 'stable'
}) })
} else { } else {
this.rightBox.loading = true this.chart = JSON.parse(JSON.stringify(data))
this.$get('visual/dashboard/chart/' + data.id).then(res => { this.chart.panelName = this.showPanel.name
this.rightBox.loading = false this.$nextTick(() => {
if (res.code === 200) { this.$refs.addChartModal.isStable = 'stable'
const chartData = res.data
this.chart = JSON.parse(JSON.stringify(chartData))
this.chart.panelName = this.showPanel.name
if (this.chart.param) {
this.chart.param = JSON.parse(this.chart.param)
} else {
this.chart.param = {}
}
if (!this.chart.groupId || this.chart.groupId == -1) {
this.chart.groupId = ''
}
if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) {
this.chart.param.collapse = false
}
this.$nextTick(() => {
this.$refs.addChartModal.isStable = 'stable'
})
} else {
this.$message.error(res.msg)
}
}) })
} }
}, },
delChart (chart) {
const index = this.$refs.notebookList.copyDataList.findIndex(item => item.id == chart.id)
this.$refs.notebookList.copyDataList.splice(index, 1)
this.$refs.notebookList.onScroll(this.scrollbarWrap.scrollTop)
},
/* 图表相关操作--start */ /* 图表相关操作--start */
addChart (chart) { addChart (chart) {
const id = this.getId(this.$refs.notebookList.copyDataList)
console.log(chart)
this.chart = { this.chart = {
name: '', name: '',
type: chart.type, type: chart.type,
@@ -277,18 +258,44 @@ export default {
w: 12, w: 12,
h: 4, h: 4,
x: 0, x: 0,
id: id, y: 0,
i: id,
param: this.newChart(chart.type) param: this.newChart(chart.type)
} }
if (chart.position) {
if (chart.position.position === 'before') {
this.chart.y = chart.position.y - 0.01
} else {
this.chart.y = chart.position.y + 0.01
}
} else {
this.chart.y = this.getMaxY(this.$refs.notebookList.copyDataList)
}
if (this.chart.datasource === 'metrics') { if (this.chart.datasource === 'metrics') {
this.chart.elements = [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1, step: undefined }] this.chart.elements = [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1, step: undefined }]
} }
this.chart.panelName = this.obj.name this.chart.panelName = this.showPanel.name
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.addChartModal.isStable = 'stable' this.$refs.addChartModal.isStable = 'stable'
}) })
}, },
getMaxId (arr) { // 获取当前列表最大的id
if (!arr.length) {
return 1
}
const maxElement = arr.reduce(function (prev, current) {
return (prev.id > current.id) ? prev : current
})
return Math.max(maxElement.id, 1)
},
getMaxY (arr) { // 获取当前列表最大的y
if (!arr.length) {
return 0
}
const maxElement = arr.reduce(function (prev, current) {
return (prev.y > current.y) ? prev : current
})
return maxElement.y
},
newChart (type) { newChart (type) {
let param = {} let param = {}
switch (type) { switch (type) {
@@ -566,6 +573,10 @@ export default {
immediate: true, immediate: true,
handler (n) { handler (n) {
this.notebookName = n.name this.notebookName = n.name
this.showPanel = {
id: n.id,
name: n.name
}
this.getData() this.getData()
if (!n.id) { if (!n.id) {
this.$store.commit('setNotebookEdit', true) this.$store.commit('setNotebookEdit', true)

View File

@@ -295,6 +295,7 @@ export default {
params.param.datasource[0].filter = params.param.datasource[0].filter.filter(item => item.value) params.param.datasource[0].filter = params.param.datasource[0].filter.filter(item => item.value)
} }
if (this.from === 'notebook') { if (this.from === 'notebook') {
delete params.oldElements
self.$emit('on-create-success', params) self.$emit('on-create-success', params)
return return
} }

View File

@@ -176,11 +176,9 @@ export default {
const cloneDataList = this.$lodash.cloneDeep(n) const cloneDataList = this.$lodash.cloneDeep(n)
const tempList = cloneDataList.map((item, index) => { const tempList = cloneDataList.map((item, index) => {
const height = item.height || '' const height = item.height || ''
const id = item.id || index
return { return {
...item, ...item,
id, i: item.id,
i: id,
w: 12, w: 12,
h: height || 4, h: height || 4,
x: item.x || 0, x: item.x || 0,
@@ -198,7 +196,6 @@ export default {
static: true static: true
}) })
this.$nextTick(() => { this.$nextTick(() => {
console.log(tempList)
this.copyDataList = this.$lodash.cloneDeep(tempList) this.copyDataList = this.$lodash.cloneDeep(tempList)
this.gridLayoutShow = true this.gridLayoutShow = true
if (!this.isExportHtml) { if (!this.isExportHtml) {