NEZ-1767 fix: 设置图表宽导致图表重叠的问题

This commit is contained in:
zhangyu
2022-04-01 10:48:43 +08:00
parent 2049a4e6f4
commit 9ab970d000
3 changed files with 90 additions and 5 deletions

View File

@@ -210,6 +210,8 @@ export default {
if (!this.isGroup) {
this.moveChart()
this.onScroll(this.scrollTop)
} else {
bus.$emit('groupChildMove')
}
},
containerResizedEvent (i, newH, newW, newHPx, newWPx) {
@@ -346,6 +348,65 @@ export default {
},
refreshPanel () {
bus.$emit('refreshPanel')
},
createChartSuccess (params) {
const arr = this.copyDataList.filter(item => !item.staic)
const charts = []
let weight = 0
arr.forEach(item => {
const chart = {
id: item.id,
x: item.x,
y: item.y,
span: item.span,
height: item.height,
groupId: item.groupId,
weight: weight
}
if (!params.groupId && chart.y >= params.y) {
chart.y = chart.y + 1
}
if (params.id == item.id) {
chart.y = params.y
chart.x = params.x
}
charts.push(chart)
weight++
if (item.type === 'group') {
item.children && item.children.forEach(children => {
const childrenChart = {
id: children.id,
x: children.x,
y: children.y,
span: children.span,
height: children.height,
groupId: children.groupId,
weight: weight
}
if (item.id === params.groupId && children.y >= params.y) {
childrenChart.y = childrenChart.y + 1
}
if (params.id == childrenChart.id) {
childrenChart.y = params.y
childrenChart.x = params.x
}
charts.push(childrenChart)
weight++
})
}
})
const chartParams = {
panelId: this.panelId,
charts: charts
}
if (charts && charts.length) {
this.$put('/visual/panel/chart/weights', chartParams).then(() => {
if (params.cb) {
params.cb()
}
})
}
}
},
created () {
@@ -355,6 +416,8 @@ export default {
this.init()
if (!this.isGroup) {
bus.$on('groupMove', this.changeGroupHeight)
bus.$on('creat-chart-success', this.createChartSuccess)
bus.$on('groupChildMove', this.moveChart)
this.$store.commit('setChartListId', `chartList${this.timestamp}`)
window.addEventListener('resize', this.resize)
}

View File

@@ -261,7 +261,6 @@ export default {
}
},
resize () {
console.log('reszie')
setTimeout(() => {
getChart(this.chartId) && getChart(this.chartId).resize()
}, 100)

View File

@@ -207,6 +207,8 @@ export default {
},
// 保存endpoint
save () {
const self = this
let resetFlag = false // 页面是否需要重排
const arr = [this.$refs.chartForm.validate()]
arr.push(this.$refs['childrenFrom' + this.editChart.datasource].$refs.chartForm.validate())
Promise.all(arr).then(res => {
@@ -245,6 +247,7 @@ export default {
if (params.x + params.span > 12) {
params.x = 0
params.y += 1
resetFlag = true
}
delete params.panel
if (params.type === 'table') {
@@ -257,8 +260,18 @@ export default {
this.$put('visual/panel/chart', params).then(response => {
if (response.code === 200) {
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
this.$emit('on-create-success', { id: this.panelId, name: this.panelName })
this.esc(true)
if (resetFlag) {
bus.$emit('creat-chart-success', {
...params,
cb: function () {
self.$emit('on-create-success', { id: this.panelId, name: this.panelName })
self.esc(true)
}
})
} else {
self.$emit('on-create-success', { id: this.panelId, name: this.panelName })
self.esc(true)
}
} else {
this.$message.error(response.msg)
}
@@ -267,8 +280,18 @@ export default {
this.$post('visual/panel/chart', params).then(response => {
if (response.code === 200) {
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
this.$emit('on-create-success', { id: this.panelId, name: this.panelName })
this.esc(true)
if (resetFlag) {
bus.$emit('creat-chart-success', {
...params,
cb: function () {
self.$emit('on-create-success', { id: this.panelId, name: this.panelName })
self.esc(true)
}
})
} else {
self.$emit('on-create-success', { id: this.panelId, name: this.panelName })
self.esc(true)
}
} else {
this.$message.error(response.msg)
}