diff --git a/web/apps/web-ele/src/router/access.ts b/web/apps/web-ele/src/router/access.ts index 57c2fb1..d22a926 100644 --- a/web/apps/web-ele/src/router/access.ts +++ b/web/apps/web-ele/src/router/access.ts @@ -93,38 +93,35 @@ function withAdminRuntimePages(pageMap: ComponentRecordType) { } const PREFETCH_LIGHT_PAGE_KEYS = [ - '../views/_core/menu/index.vue', - '../views/_core/permission/index.vue', - '../views/_core/role/index.vue', '../views/_core/user/index.vue', + '../views/_core/menu/index.vue', + '../views/_core/role/index.vue', + '../views/_core/permission/index.vue', ]; let lightPagesPrefetched = false; -function scheduleIdleTask(callback: () => void) { +function scheduleLightPrefetch(callback: () => void, delay: number) { if (typeof window === 'undefined') return; - const requestIdle = (window as any).requestIdleCallback; - if (typeof requestIdle === 'function') { - requestIdle(callback, { timeout: 8000 }); - return; - } - window.setTimeout(callback, 8000); + window.setTimeout(callback, delay); } function prefetchLightPages(pageMap: ComponentRecordType) { if (lightPagesPrefetched) return; lightPagesPrefetched = true; - window.setTimeout(() => { - scheduleIdleTask(() => { - void ensureAdminRuntime().catch(() => undefined); - for (const key of PREFETCH_LIGHT_PAGE_KEYS) { - const loader = pageMap[key]; - if (typeof loader === 'function') { - void loader().catch(() => undefined); - } + + scheduleLightPrefetch(() => { + void ensureAdminRuntime().catch(() => undefined); + }, 250); + + for (const [index, key] of PREFETCH_LIGHT_PAGE_KEYS.entries()) { + scheduleLightPrefetch(() => { + const loader = pageMap[key]; + if (typeof loader === 'function') { + void loader().catch(() => undefined); } - }); - }, 3_000); + }, 450 + index * 160); + } } const LIGHT_AI_PLATFORM_MENU_ROUTES = [ diff --git a/web/apps/web-ele/src/router/guard.ts b/web/apps/web-ele/src/router/guard.ts index 6a8a368..aa9b525 100644 --- a/web/apps/web-ele/src/router/guard.ts +++ b/web/apps/web-ele/src/router/guard.ts @@ -25,21 +25,17 @@ function filterLightTabHistory(history: T) { }; } -function isMainHomeRoute(path: string) { - return /\/page-render\/main_home$/.test(path); -} +let adminRuntimeWarmupScheduled = false; function warmAdminRuntimeAfterPaint() { + if (adminRuntimeWarmupScheduled) return; + adminRuntimeWarmupScheduled = true; + const run = () => { - void ensureAdminRuntime(); + void ensureAdminRuntime().catch(() => undefined); }; - if ('requestIdleCallback' in window) { - window.requestIdleCallback(run, { timeout: 2000 }); - return; - } - - window.setTimeout(run, 800); + window.setTimeout(run, 350); } /** @@ -131,10 +127,8 @@ function setupCommonGuard(router: Router) { } if (useAccessStore().accessToken) { + warmAdminRuntimeAfterPaint(); prefetchAiPlatformPages(to.path); - if (isMainHomeRoute(to.path)) { - warmAdminRuntimeAfterPaint(); - } } }); } diff --git a/web/apps/web-ele/src/router/prefetch.ts b/web/apps/web-ele/src/router/prefetch.ts index 28458b1..f7a6e37 100644 --- a/web/apps/web-ele/src/router/prefetch.ts +++ b/web/apps/web-ele/src/router/prefetch.ts @@ -68,11 +68,11 @@ function scheduleIdle(callback: () => void) { const browserWindow = window as WindowWithIdleCallback; if (browserWindow.requestIdleCallback) { - browserWindow.requestIdleCallback(callback, { timeout: 8000 }); + browserWindow.requestIdleCallback(callback, { timeout: 2000 }); return; } - window.setTimeout(callback, 8000); + window.setTimeout(callback, 1200); } function canPrefetch() { @@ -160,7 +160,7 @@ function prefetchAiPlatformPages(currentPath = '') { } if (isSystemRoute(currentPath)) { - delayedPrefetch(`core:${currentPath}`, corePrefetchTasks, 18_000); + delayedPrefetch(`core:${currentPath}`, corePrefetchTasks, 4_000); return; } @@ -168,7 +168,7 @@ function prefetchAiPlatformPages(currentPath = '') { delayedPrefetch( `agent-chat:${currentPath}`, [aiPrefetchTasks.agentChat, aiPrefetchTasks.aiChatPanel], - 14_000, + 3_000, ); return; } @@ -177,12 +177,21 @@ function prefetchAiPlatformPages(currentPath = '') { delayedPrefetch( `ai:${currentPath}`, getAiRoutePrefetchTasks(currentPath), - 14_000, + 3_000, ); return; } - delayedPrefetch('core:home', corePrefetchTasks, 22_000); + delayedPrefetch('core:home', corePrefetchTasks, 4_500); + delayedPrefetch( + 'ai:home', + [ + aiPrefetchTasks.agentChat, + aiPrefetchTasks.model, + aiPrefetchTasks.workflowRuns, + ], + 7_000, + ); } export { prefetchAiPlatformPages }; diff --git a/web/apps/web-ele/src/views/ai-platform/workflow-runs/index.vue b/web/apps/web-ele/src/views/ai-platform/workflow-runs/index.vue index 70448a2..55c6a15 100644 --- a/web/apps/web-ele/src/views/ai-platform/workflow-runs/index.vue +++ b/web/apps/web-ele/src/views/ai-platform/workflow-runs/index.vue @@ -1,7 +1,7 @@