fix(ops): 修复 setInterval 在 keepAlive 下未清除导致内存泄漏
页面使用 keepAlive 缓存后 onUnmounted 不触发,setInterval 持续运行, 长时间放置导致 OOM 崩溃。统一使用 onActivated/onDeactivated 管理轮询生命周期。 涉及页面:工单统计栏、工单看板、工单详情、客流统计、工作台、全局布局通知轮询 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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<typeof setInterval> = 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,
|
||||
|
||||
Reference in New Issue
Block a user