1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 14:08:06 +08:00

fix: 释放 echarts 资源 (#1611)

This commit is contained in:
ssongliu 2023-07-11 18:59:10 +08:00 committed by GitHub
parent 37d8244414
commit 5058a814aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 9 deletions

View File

@ -2,7 +2,7 @@
<div :id="id" class="v-charts" ref="chartRef" :style="{ height: height, width: width }" />
</template>
<script lang="ts" setup>
import { onMounted, onUnmounted, nextTick, watch } from 'vue';
import { onMounted, nextTick, watch, onBeforeUnmount } from 'vue';
import * as echarts from 'echarts';
import { GlobalStore } from '@/store';
import { computeSizeFromKBs, computeSizeFromMB } from '@/utils/util';
@ -176,8 +176,8 @@ onMounted(() => {
});
});
onUnmounted(() => {
echarts.dispose;
onBeforeUnmount(() => {
echarts.getInstanceByDom(document.getElementById(props.id) as HTMLElement).dispose();
});
</script>
<style lang="scss" scoped></style>

View File

@ -513,13 +513,16 @@ const loadSafeStatus = async () => {
isSafety.value = res.data.securityEntrance;
};
const onFocus = () => {
isActive.value = true;
};
const onBlur = () => {
isActive.value = false;
};
onMounted(() => {
window.addEventListener('focus', () => {
isActive.value = true;
});
window.addEventListener('blur', () => {
isActive.value = false;
});
window.addEventListener('focus', onFocus);
window.addEventListener('blur', onBlur);
loadSafeStatus();
loadUpgradeStatus();
onLoadNetworkOptions();
@ -528,6 +531,8 @@ onMounted(() => {
});
onBeforeUnmount(() => {
window.removeEventListener('focus', onFocus);
window.removeEventListener('blur', onBlur);
clearInterval(Number(timer));
timer = null;
});

View File

@ -356,11 +356,21 @@ function changeChartSize() {
}
}
function disposeChart() {
echarts.getInstanceByDom(document.getElementById('cpu') as HTMLElement)?.dispose();
echarts.getInstanceByDom(document.getElementById('memory') as HTMLElement)?.dispose();
echarts.getInstanceByDom(document.getElementById('load') as HTMLElement)?.dispose();
for (let i = 0; i < currentInfo.value.diskData.length; i++) {
echarts.getInstanceByDom(document.getElementById('disk' + i) as HTMLElement)?.dispose();
}
}
onMounted(() => {
window.addEventListener('resize', changeChartSize);
});
onBeforeUnmount(() => {
disposeChart();
window.removeEventListener('resize', changeChartSize);
});