From 5bf5098349160055bf8354e2fc0c71e126df8b85 Mon Sep 17 00:00:00 2001 From: luojiayi <1712054227@qq.com> Date: Tue, 6 May 2025 14:19:39 +0800 Subject: [PATCH] =?UTF-8?q?2025=E5=B9=B405=E6=9C=8806=E6=97=A514:19:38?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/hooks.ts | 12 + src/views/incidentDispose/index.vue | 9 +- src/views/monitoringCenter/deviceHistory.vue | 14 +- src/views/statisticalCenter/deviceHistory.vue | 86 ++++++- src/views/statisticalCenter/emergencyList.vue | 66 ++--- src/views/statisticalCenter/index.vue | 229 +----------------- src/views/statisticalCenter/monitoringTop.vue | 32 ++- .../statisticalCenter/onLineStatistics.vue | 48 +++- .../statisticalCenter/statisticsWarning.vue | 53 +++- 9 files changed, 262 insertions(+), 287 deletions(-) diff --git a/src/utils/hooks.ts b/src/utils/hooks.ts index a3769cf..45ce335 100644 --- a/src/utils/hooks.ts +++ b/src/utils/hooks.ts @@ -1,4 +1,5 @@ import { computed, onBeforeMount, onMounted, onUnmounted, ref } from "vue"; +import { debounce } from "@/utils/index"; export function useVModel(props, propsName, emit) { return computed({ @@ -98,4 +99,15 @@ export function useFullScreen() { window.removeEventListener('resize', fullChange) }); return { isFullScreen, toggleFullScreen }; +} + +// 监听窗口大小 +export function useResize(fn = () => { }) { + const handleResize = debounce(fn, 200); + onMounted(() => { + window.addEventListener("resize", handleResize); + }); + onUnmounted(() => { + window.removeEventListener("resize", handleResize); + }); } \ No newline at end of file diff --git a/src/views/incidentDispose/index.vue b/src/views/incidentDispose/index.vue index 01653bc..c8991a4 100644 --- a/src/views/incidentDispose/index.vue +++ b/src/views/incidentDispose/index.vue @@ -94,6 +94,7 @@ import { TWarningConfirm, TWarningDetail } from "@/api/index.d"; import { useRoute } from "vue-router"; import { ElMessage, FormInstance, FormRules } from "element-plus"; import { debounce, format } from "@/utils"; +import { useResize } from "@/utils/hooks"; // 定义一个响应式变量 enum unitEnum { @@ -307,9 +308,9 @@ const submitForm = async (formEl: FormInstance | undefined) => { }); }; -const handleResize = debounce(() => { +useResize(() => { myChart.resize(); -}, 200); +}); onMounted(() => { getData(); try { @@ -318,12 +319,8 @@ onMounted(() => { if (chartRef.value) { myChart = echarts.init(chartRef.value); myChart.setOption(options); - window.addEventListener("resize", handleResize); } }); -onUnmounted(() => { - window.removeEventListener("resize", handleResize); -});