echart检测尺寸变动重绘

This commit is contained in:
yuanshan 2025-10-16 15:59:52 +08:00
parent 26e7047359
commit 8566012575
8 changed files with 162 additions and 4 deletions

View File

@ -42,7 +42,7 @@
</div>
</template>
<script setup>
import { onMounted, watch, reactive, computed } from "vue";
import { onMounted, onBeforeUnmount, watch, reactive, computed } from "vue";
import { useI18n } from "vue-i18n";
import * as echarts from "echarts";
import { NDatePicker, NIcon } from "naive-ui";
@ -310,8 +310,44 @@ const initEcharts = (data) => {
});
};
//
const debounce = (func, wait) => {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
};
//
const handleResize = () => {
if (myCharts) {
myCharts.resize();
}
};
// resize
const debouncedResize = debounce(handleResize, 300);
onMounted(() => {
getHistoricalData();
// resize
window.addEventListener("resize", debouncedResize);
});
//
onBeforeUnmount(() => {
// resize
window.removeEventListener("resize", debouncedResize);
// echarts
if (myCharts) {
myCharts.dispose();
myCharts = null;
}
});
//
@ -593,6 +629,7 @@ const handleDateRangeChange = (range) => {
flex-direction: row;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 10px;
.echarts-search-byRange {

View File

@ -42,7 +42,7 @@
</div>
</template>
<script setup>
import { onMounted, watch, reactive, computed } from "vue";
import { onMounted, onBeforeUnmount, watch, reactive, computed } from "vue";
import * as echarts from "echarts";
import { NDatePicker, NIcon } from "naive-ui";
import { ArrowForwardOutline } from "@vicons/ionicons5";
@ -309,8 +309,44 @@ const initEcharts = (data) => {
});
};
//
const debounce = (func, wait) => {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
};
//
const handleResize = () => {
if (myCharts) {
myCharts.resize();
}
};
// resize
const debouncedResize = debounce(handleResize, 300);
onMounted(() => {
getHistoricalData();
// resize
window.addEventListener("resize", debouncedResize);
});
//
onBeforeUnmount(() => {
// resize
window.removeEventListener("resize", debouncedResize);
// echarts
if (myCharts) {
myCharts.dispose();
myCharts = null;
}
});
//
@ -592,6 +628,8 @@ const handleDateRangeChange = (range) => {
flex-direction: row;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 10px;
.echarts-search-byRange {
display: flex;

View File

@ -98,7 +98,7 @@
</div>
</template>
<script setup>
import { onMounted, watch, reactive, computed } from "vue";
import { onMounted, onBeforeUnmount, watch, reactive, computed } from "vue";
import { useI18n } from "vue-i18n";
import * as echarts from "echarts";
import { NDatePicker, NIcon } from "naive-ui";
@ -374,8 +374,44 @@ const initEcharts = (data) => {
});
};
//
const debounce = (func, wait) => {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
};
//
const handleResize = () => {
if (myCharts) {
myCharts.resize();
}
};
// resize
const debouncedResize = debounce(handleResize, 300);
onMounted(() => {
getHistoricalData();
// resize
window.addEventListener("resize", debouncedResize);
});
//
onBeforeUnmount(() => {
// resize
window.removeEventListener("resize", debouncedResize);
// echarts
if (myCharts) {
myCharts.dispose();
myCharts = null;
}
});
//
@ -729,6 +765,7 @@ watch(
flex-direction: column;
justify-content: center;
gap: 10 * 5.12px;
flex-wrap: wrap;
.echarts-search-byRange {
width: 100%;

View File

@ -42,7 +42,7 @@
</div>
</template>
<script setup>
import { onMounted, watch, reactive, computed } from "vue";
import { onMounted, onBeforeUnmount, watch, reactive, computed } from "vue";
import { useI18n } from "vue-i18n";
import * as echarts from "echarts";
import { NDatePicker, NIcon } from "naive-ui";
@ -310,8 +310,44 @@ const initEcharts = (data) => {
});
};
//
const debounce = (func, wait) => {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
};
//
const handleResize = () => {
if (myCharts) {
myCharts.resize();
}
};
// resize
const debouncedResize = debounce(handleResize, 300);
onMounted(() => {
getHistoricalData();
// resize
window.addEventListener("resize", debouncedResize);
});
//
onBeforeUnmount(() => {
// resize
window.removeEventListener("resize", debouncedResize);
// echarts
if (myCharts) {
myCharts.dispose();
myCharts = null;
}
});
//
@ -595,6 +631,7 @@ const handleDateRangeChange = (range) => {
flex-direction: column;
justify-content: center;
gap: 10 * 2.5px;
flex-wrap: wrap;
.echarts-search-byRange {
width: 100%;
@ -609,6 +646,7 @@ const handleDateRangeChange = (range) => {
align-items: center;
justify-content: flex-start;
gap: 16 * 2.5px;
flex-wrap: wrap;
.search-range-list-each {
padding: 7 * 2.5px 22 * 2.5px;
border-radius: 5px;

View File

@ -588,6 +588,8 @@ const getPageData = async () => {
padding: 0 16px;
margin-bottom: 32px;
margin-top: 32px;
flex-wrap: wrap;
gap: 10px;
.range-label {
font-family: "PingFang SC", sans-serif;

View File

@ -587,6 +587,8 @@ const getPageData = async () => {
padding: 0 16px;
margin-bottom: 32px;
margin-top: 32px;
flex-wrap: wrap;
gap: 10px;
.range-label {
font-family: "PingFang SC", sans-serif;

View File

@ -560,6 +560,8 @@ const getPageData = async () => {
gap: 8 * 5.12px;
padding: 0 16 * 5.12px;
margin-bottom: 32 * 5.12px;
flex-wrap: wrap;
gap: 10 * 5.12px;
.range-label {
font-family: "PingFang SC", sans-serif;

View File

@ -589,6 +589,8 @@ const getPageData = async () => {
padding: 0 16 * 2.5px;
margin-bottom: 32 * 2.5px;
margin-top: 32 * 2.5px;
flex-wrap: wrap;
gap: 10 * 2.5px;
.range-label {
font-family: "PingFang SC", sans-serif;