NEZ-1820 fix:修复dashboard内存泄漏

This commit is contained in:
zyh
2022-04-19 15:40:40 +08:00
parent 4d799ed86a
commit 3bab521a95
3 changed files with 40 additions and 23 deletions

View File

@@ -172,6 +172,15 @@
:is-fullscreen="isFullscreen" :is-fullscreen="isFullscreen"
@chartIsNoData="chartIsNoData" @chartIsNoData="chartIsNoData"
></chart-clock> ></chart-clock>
<chart-topology
:ref="'chart' + chartInfo.id"
v-if="isTopology(chartInfo.type)"
:chart-data="chartData"
:chart-info="chartInfo"
:chart-option="chartOption"
:is-fullscreen="isFullscreen"
@chartIsNoData="chartIsNoData"
></chart-topology>
</template> </template>
</div> </div>
</template> </template>
@@ -198,7 +207,8 @@ import chartUrl from './chart/chartUrl'
import chartValue from './chart/chartValue' import chartValue from './chart/chartValue'
import chartHexagonD3 from './chart/chartHexagonD3' import chartHexagonD3 from './chart/chartHexagonD3'
import chartMap from './chart/chartMap' import chartMap from './chart/chartMap'
import { getOption, isTimeSeries, isHexagon, isUrl, isText, isChartPie, isChartBar, isTreemap, isLog, isStat, isDiagram, isGroup, isAutotopology, isMap, isAssetInfo, isEndpointInfo, isTable, isGauge, isClock } from './chart/tools' import chartTopology from './chart/chartTopology'
import { getOption, isTimeSeries, isHexagon, isUrl, isText, isChartPie, isChartBar, isTreemap, isLog, isStat, isDiagram, isGroup, isAutotopology, isMap, isAssetInfo, isEndpointInfo, isTable, isGauge, isClock, isTopology } from './chart/tools'
import lodash from 'lodash' import lodash from 'lodash'
export default { export default {
@@ -224,7 +234,8 @@ export default {
chartUrl, chartUrl,
chartValue, chartValue,
chartHexagonD3, chartHexagonD3,
chartMap chartMap,
chartTopology
}, },
props: { props: {
chartInfo: Object, chartInfo: Object,
@@ -293,6 +304,7 @@ export default {
isTable, isTable,
isGauge, isGauge,
isClock, isClock,
isTopology,
chartIsNoData (flag) { chartIsNoData (flag) {
this.chartChildrenData = flag this.chartChildrenData = flag
}, },

View File

@@ -1,5 +1,5 @@
<template> <template>
<div v-loading="topologyLoading" class="overview"> <div v-my-loading="topologyLoading" class="overview">
<transition name = "el-zoom-in-center"> <transition name = "el-zoom-in-center">
<div v-if="allProject&&allProject.length>0" style="width: 100%;height: 100%;position: relative"> <div v-if="allProject&&allProject.length>0" style="width: 100%;height: 100%;position: relative">
<el-carousel :interval="5000" :trigger="'click'" arrow="hover"> <el-carousel :interval="5000" :trigger="'click'" arrow="hover">
@@ -46,7 +46,7 @@ export default {
this.$get('monitor/project', { pageSize: -1 }).then(res => { this.$get('monitor/project', { pageSize: -1 }).then(res => {
this.topologyLoading = true this.topologyLoading = true
const axiosAll = [] const axiosAll = []
const temp = [] let temp = []
if (res.data.list.length === 0) { if (res.data.list.length === 0) {
this.topologyLoading = false this.topologyLoading = false
} }
@@ -64,7 +64,8 @@ export default {
res2.forEach(item => { res2.forEach(item => {
temp.push(item) temp.push(item)
}) })
this.allProject = temp this.allProject = JSON.parse(JSON.stringify(temp))
temp = []
this.topologyLoading = false this.topologyLoading = false
}) })
}) })

View File

@@ -3,7 +3,7 @@
@import "./L5/css/props.css"; @import "./L5/css/props.css";
</style> </style>
<template> <template>
<div class="project-box list-page" v-loading="topologyLoading"> <div class="project-box list-page" v-my-loading="topologyLoading">
<div class="main-list" :style="{height: fromOverView ?'100%' : 'calc(100% - 30px)'}"> <div class="main-list" :style="{height: fromOverView ?'100%' : 'calc(100% - 30px)'}">
<div class="main-container" :class="fromOverView?'from-overview':'from-project'"> <div class="main-container" :class="fromOverView?'from-overview':'from-project'">
<div v-if="(editTopologyFlag || isPreview)&&!fromChart" class="edit-topologyLine top-tools" style="padding-left: 20px;width: calc(100% - 40px);display: inline-block"> <div v-if="(editTopologyFlag || isPreview)&&!fromChart" class="edit-topologyLine top-tools" style="padding-left: 20px;width: calc(100% - 40px);display: inline-block">
@@ -13,7 +13,7 @@
<span class="el-dropdown-title"><i class="iconfont icon-cube"></i> <i <span class="el-dropdown-title"><i class="iconfont icon-cube"></i> <i
class="nz-icon nz-icon-arrow-down"></i></span> class="nz-icon nz-icon-arrow-down"></i></span>
<el-dropdown-menu slot="dropdown" @click="dropdownClick" class="right-box-select-top right-public-box-dropdown-top"> <el-dropdown-menu slot="dropdown" @click="dropdownClick" class="right-box-select-top right-public-box-dropdown-top">
<div style="height: 450px" v-loading="imgageLoading"> <div style="height: 450px" v-my-loading="imgageLoading">
<el-card shadow="hover" style="height:420px;width:284px;overflow-y: auto" <el-card shadow="hover" style="height:420px;width:284px;overflow-y: auto"
class="project-topology-add-node"> class="project-topology-add-node">
<!--<div class="drag-header"></div>--> <!--<div class="drag-header"></div>-->
@@ -660,12 +660,11 @@ export default {
this.chartGetData = [] this.chartGetData = []
const axiosArr = [] const axiosArr = []
const promiseArr = [] const promiseArr = []
const self = this
const pensPromise = (pen, arr, index) => { const pensPromise = (pen, arr, index) => {
return new Promise(function (resolve, reject) { return new Promise((resolve, reject) => {
Promise.all(arr).then((res) => { Promise.all(arr).then((res) => {
self.chartGetData[index].res = self.computeData(res, pen.data.aggregation, pen) this.chartGetData[index].res = this.computeData(res, pen.data.aggregation, pen)
self.setAnimation(pen, self.chartGetData[index].res) this.setAnimation(pen, this.chartGetData[index].res)
resolve() resolve()
}) })
}) })
@@ -774,9 +773,10 @@ export default {
return return
} }
if (!getTopology(this.topologyIndex)) { if (!getTopology(this.topologyIndex)) {
const canvas = new Topology('topology-canvas' + this.topologyIndexF, canvasOptions) let canvas = new Topology('topology-canvas' + this.topologyIndexF, canvasOptions)
canvas.open(data) canvas.open(data)
setTopology(this.topologyIndex, canvas) setTopology(this.topologyIndex, canvas)
canvas = null
} else { } else {
getTopology(this.topologyIndex).open(data) getTopology(this.topologyIndex).open(data)
} }
@@ -801,7 +801,7 @@ export default {
if (!res.data) { if (!res.data) {
return return
} }
let data = res.data.topo let data = JSON.parse(JSON.stringify(res.data.topo))
if (!res.data.topo || !res.data.topo.pens.length) { if (!res.data.topo || !res.data.topo.pens.length) {
this.showNoData = true this.showNoData = true
} else { } else {
@@ -846,12 +846,11 @@ export default {
const arr = data.pens.filter(item => !item.type) const arr = data.pens.filter(item => !item.type)
this.addNodeInit(arr) this.addNodeInit(arr)
} }
const timer = setInterval(() => { let timer = setInterval(() => {
if (!this.imgInit) { if (!this.imgInit) {
return return
} }
const promiseArr = [] const promiseArr = []
const self = this
for (let i = 0; i < data.pens.length; i++) { for (let i = 0; i < data.pens.length; i++) {
const line = data.pens[i] const line = data.pens[i]
if (line.type === 1) { if (line.type === 1) {
@@ -914,13 +913,15 @@ export default {
} }
} }
}) })
self.saveData = { ...data } this.saveData = { ...data }
resolve(data) resolve(data)
clearInterval(timer) clearInterval(timer)
timer = null
}).catch(res => { }).catch(res => {
self.saveData = { ...data } this.saveData = { ...data }
resolve(data) resolve(data)
clearInterval(timer) clearInterval(timer)
timer = null
}) })
}, 100) }, 100)
} }
@@ -1062,7 +1063,6 @@ export default {
}, },
getNodesArr () { getNodesArr () {
const arr = []
if (!getTopology(this.topologyIndex)) return if (!getTopology(this.topologyIndex)) return
this.offsetX = getTopology(this.topologyIndex).data.x this.offsetX = getTopology(this.topologyIndex).data.x
this.offsetY = getTopology(this.topologyIndex).data.y this.offsetY = getTopology(this.topologyIndex).data.y
@@ -1556,7 +1556,7 @@ export default {
fileList = fileList.splice(fileList.length - 1, 1) fileList = fileList.splice(fileList.length - 1, 1)
return false return false
} }
const isSize = new Promise(function (resolve, reject) { new Promise(function (resolve, reject) {
const width = 0 const width = 0
const height = 0 const height = 0
const _URL = window.URL || window.webkitURL const _URL = window.URL || window.webkitURL
@@ -1839,8 +1839,7 @@ export default {
// resolve(img) // resolve(img)
// }) // })
}) })
.catch(err => { .catch()
})
}) })
} }
}, },
@@ -2250,8 +2249,13 @@ export default {
} }
} }
}, },
destroyed () { beforeDestroy () {
if (this.timer) {
clearInterval(this.timer)
this.timer = null
}
if (getTopology(this.topologyIndex)) { if (getTopology(this.topologyIndex)) {
getTopology(this.topologyIndex).off('contextmenu', this.onContextMenu)
getTopology(this.topologyIndex).destroy() getTopology(this.topologyIndex).destroy()
setTopology(this.topologyIndex, null) setTopology(this.topologyIndex, null)
} }
@@ -2259,7 +2263,7 @@ export default {
document.getElementById('topology-canvas' + this.topologyIndexF).removeEventListener('mousemove', this.canvasMove) document.getElementById('topology-canvas' + this.topologyIndexF).removeEventListener('mousemove', this.canvasMove)
} }
window.removeEventListener('resize', this.winResize) window.removeEventListener('resize', this.winResize)
window.removeEventListener('resize', this.contextmenuNone) window.removeEventListener('click', this.contextmenuNone)
} }
} }
</script> </script>