From f1284142ac3ee7c2091b79b7dbe9fcdefc796469 Mon Sep 17 00:00:00 2001 From: lzh Date: Thu, 26 Feb 2026 13:24:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(ops):=20=E4=BF=AE=E5=A4=8D=20setInterval=20?= =?UTF-8?q?=E5=9C=A8=20keepAlive=20=E4=B8=8B=E6=9C=AA=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 页面使用 keepAlive 缓存后 onUnmounted 不触发,setInterval 持续运行, 长时间放置导致 OOM 崩溃。统一使用 onActivated/onDeactivated 管理轮询生命周期。 涉及页面:工单统计栏、工单看板、工单详情、客流统计、工作台、全局布局通知轮询 Co-Authored-By: Claude Opus 4.6 --- apps/web-antd/src/layouts/basic.vue | 13 +- .../src/views/dashboard/workspace/index.vue | 26 +- .../cleaning/work-order/dashboard/index.vue | 27 +- .../ops/cleaning/work-order/detail/index.vue | 38 +- .../cleaning/work-order/modules/stats-bar.vue | 30 +- apps/web-antd/src/views/ops/traffic/index.vue | 973 ++++++++++++++++++ 6 files changed, 1080 insertions(+), 27 deletions(-) create mode 100644 apps/web-antd/src/views/ops/traffic/index.vue diff --git a/apps/web-antd/src/layouts/basic.vue b/apps/web-antd/src/layouts/basic.vue index 525c2fe3d..d6a52c63e 100644 --- a/apps/web-antd/src/layouts/basic.vue +++ b/apps/web-antd/src/layouts/basic.vue @@ -3,7 +3,7 @@ import type { NotificationItem } from '@vben/layouts'; import type { SystemTenantApi } from '#/api/system/tenant'; -import { computed, onMounted, ref, watch } from 'vue'; +import { computed, onMounted, onUnmounted, ref, watch } from 'vue'; import { useAccess } from '@vben/access'; import { AuthenticationLoginExpiredModal, useVbenModal } from '@vben/common-ui'; @@ -185,13 +185,15 @@ async function handleTenantChange(tenant: SystemTenantApi.Tenant) { } // ========== 初始化 ========== +let notifyTimer: null | ReturnType = null; + onMounted(() => { // 首次加载未读数量 handleNotificationGetUnreadCount(); // 获取租户列表 handleGetTenantList(); // 轮询刷新未读数量 - setInterval( + notifyTimer = setInterval( () => { if (userStore.userInfo) { handleNotificationGetUnreadCount(); @@ -201,6 +203,13 @@ onMounted(() => { ); }); +onUnmounted(() => { + if (notifyTimer) { + clearInterval(notifyTimer); + notifyTimer = null; + } +}); + watch( () => ({ enable: preferences.app.watermark, diff --git a/apps/web-antd/src/views/dashboard/workspace/index.vue b/apps/web-antd/src/views/dashboard/workspace/index.vue index 280058bf1..08dbe79ee 100644 --- a/apps/web-antd/src/views/dashboard/workspace/index.vue +++ b/apps/web-antd/src/views/dashboard/workspace/index.vue @@ -1,5 +1,12 @@