修复首页图表resize逻辑并添加组件卸载时的资源清理
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div class="assets-asset-page">
|
||||||
<div class="assets-asset-container">
|
<div class="assets-asset-container">
|
||||||
<el-card shadow="hover">
|
<el-card shadow="hover">
|
||||||
<div class="assets-asset-search mb15">
|
<div class="assets-asset-search mb15">
|
||||||
@@ -83,6 +84,7 @@
|
|||||||
</el-card>
|
</el-card>
|
||||||
</div>
|
</div>
|
||||||
<EditAsset ref="editAssetRef" @getAssetList="getAssetList" />
|
<EditAsset ref="editAssetRef" @getAssetList="getAssetList" />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { toRefs, reactive, defineComponent, onMounted, ref, watch, nextTick, onActivated } from 'vue';
|
import { toRefs, reactive, defineComponent, onMounted, ref, watch, nextTick, onActivated, onUnmounted } from 'vue';
|
||||||
import * as echarts from 'echarts';
|
import * as echarts from 'echarts';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||||
@@ -492,10 +492,17 @@ export default defineComponent({
|
|||||||
// 批量设置 echarts resize
|
// 批量设置 echarts resize
|
||||||
const initEchartsResizeFun = () => {
|
const initEchartsResizeFun = () => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
for (let i = 0; i < state.myCharts.length; i++) {
|
for (let i = state.myCharts.length - 1; i >= 0; i--) {
|
||||||
|
const chart = state.myCharts[i] as any;
|
||||||
|
if (!chart || (typeof chart.isDisposed === 'function' && chart.isDisposed())) {
|
||||||
|
state.myCharts.splice(i, 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
(<any>state.myCharts[i]).resize();
|
if (chart && typeof chart.resize === 'function' && !(chart.isDisposed && chart.isDisposed())) {
|
||||||
}, i * 1000);
|
chart.resize();
|
||||||
|
}
|
||||||
|
}, (state.myCharts.length - 1 - i) * 200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -507,6 +514,10 @@ export default defineComponent({
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
initEchartsResize();
|
initEchartsResize();
|
||||||
});
|
});
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener('resize', initEchartsResizeFun);
|
||||||
|
state.myCharts.length = 0;
|
||||||
|
});
|
||||||
// 由于页面缓存原因,keep-alive
|
// 由于页面缓存原因,keep-alive
|
||||||
onActivated(() => {
|
onActivated(() => {
|
||||||
initEchartsResizeFun();
|
initEchartsResizeFun();
|
||||||
|
|||||||
Reference in New Issue
Block a user