echart检测尺寸变动重绘
This commit is contained in:
parent
26e7047359
commit
8566012575
@ -42,7 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, watch, reactive, computed } from "vue";
|
import { onMounted, onBeforeUnmount, watch, reactive, computed } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import * as echarts from "echarts";
|
import * as echarts from "echarts";
|
||||||
import { NDatePicker, NIcon } from "naive-ui";
|
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(() => {
|
onMounted(() => {
|
||||||
getHistoricalData();
|
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;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
flex-wrap: wrap;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
|
||||||
.echarts-search-byRange {
|
.echarts-search-byRange {
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, watch, reactive, computed } from "vue";
|
import { onMounted, onBeforeUnmount, watch, reactive, computed } from "vue";
|
||||||
import * as echarts from "echarts";
|
import * as echarts from "echarts";
|
||||||
import { NDatePicker, NIcon } from "naive-ui";
|
import { NDatePicker, NIcon } from "naive-ui";
|
||||||
import { ArrowForwardOutline } from "@vicons/ionicons5";
|
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(() => {
|
onMounted(() => {
|
||||||
getHistoricalData();
|
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;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
|
||||||
.echarts-search-byRange {
|
.echarts-search-byRange {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, watch, reactive, computed } from "vue";
|
import { onMounted, onBeforeUnmount, watch, reactive, computed } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import * as echarts from "echarts";
|
import * as echarts from "echarts";
|
||||||
import { NDatePicker, NIcon } from "naive-ui";
|
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(() => {
|
onMounted(() => {
|
||||||
getHistoricalData();
|
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;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 10 * 5.12px;
|
gap: 10 * 5.12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
|
||||||
.echarts-search-byRange {
|
.echarts-search-byRange {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, watch, reactive, computed } from "vue";
|
import { onMounted, onBeforeUnmount, watch, reactive, computed } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import * as echarts from "echarts";
|
import * as echarts from "echarts";
|
||||||
import { NDatePicker, NIcon } from "naive-ui";
|
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(() => {
|
onMounted(() => {
|
||||||
getHistoricalData();
|
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;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 10 * 2.5px;
|
gap: 10 * 2.5px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
|
||||||
.echarts-search-byRange {
|
.echarts-search-byRange {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -609,6 +646,7 @@ const handleDateRangeChange = (range) => {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
gap: 16 * 2.5px;
|
gap: 16 * 2.5px;
|
||||||
|
flex-wrap: wrap;
|
||||||
.search-range-list-each {
|
.search-range-list-each {
|
||||||
padding: 7 * 2.5px 22 * 2.5px;
|
padding: 7 * 2.5px 22 * 2.5px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
@ -588,6 +588,8 @@ const getPageData = async () => {
|
|||||||
padding: 0 16px;
|
padding: 0 16px;
|
||||||
margin-bottom: 32px;
|
margin-bottom: 32px;
|
||||||
margin-top: 32px;
|
margin-top: 32px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
|
||||||
.range-label {
|
.range-label {
|
||||||
font-family: "PingFang SC", sans-serif;
|
font-family: "PingFang SC", sans-serif;
|
||||||
|
@ -587,6 +587,8 @@ const getPageData = async () => {
|
|||||||
padding: 0 16px;
|
padding: 0 16px;
|
||||||
margin-bottom: 32px;
|
margin-bottom: 32px;
|
||||||
margin-top: 32px;
|
margin-top: 32px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
|
||||||
.range-label {
|
.range-label {
|
||||||
font-family: "PingFang SC", sans-serif;
|
font-family: "PingFang SC", sans-serif;
|
||||||
|
@ -560,6 +560,8 @@ const getPageData = async () => {
|
|||||||
gap: 8 * 5.12px;
|
gap: 8 * 5.12px;
|
||||||
padding: 0 16 * 5.12px;
|
padding: 0 16 * 5.12px;
|
||||||
margin-bottom: 32 * 5.12px;
|
margin-bottom: 32 * 5.12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10 * 5.12px;
|
||||||
|
|
||||||
.range-label {
|
.range-label {
|
||||||
font-family: "PingFang SC", sans-serif;
|
font-family: "PingFang SC", sans-serif;
|
||||||
|
@ -589,6 +589,8 @@ const getPageData = async () => {
|
|||||||
padding: 0 16 * 2.5px;
|
padding: 0 16 * 2.5px;
|
||||||
margin-bottom: 32 * 2.5px;
|
margin-bottom: 32 * 2.5px;
|
||||||
margin-top: 32 * 2.5px;
|
margin-top: 32 * 2.5px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10 * 2.5px;
|
||||||
|
|
||||||
.range-label {
|
.range-label {
|
||||||
font-family: "PingFang SC", sans-serif;
|
font-family: "PingFang SC", sans-serif;
|
||||||
|
Loading…
Reference in New Issue
Block a user