From be017c87f47a4272d0b9c9051f1cd47751673959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E8=A2=8B=E7=B1=B3=E8=A6=81=E6=89=9B=E5=B9=BE?= =?UTF-8?q?=E6=A8=93?= Date: Tue, 10 Mar 2026 17:14:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=89=8D=E7=AB=AF=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E5=88=87=E6=8F=9B=E5=88=B0=20chat=20=E5=88=87=E6=8F=9B?= =?UTF-8?q?=E5=BE=8C=E5=9B=9E=20welcome=20=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=9C=80=E7=B5=82=E5=88=87=E6=8F=9B=E9=A0=81?= =?UTF-8?q?=E9=9D=A2=20(#5792)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 前端修正切換到chat切換後回 welcome 的配置保存最終切換頁面 * 修復 SSR 不含localStorage 環境驗證 --- .../full/vertical-header/VerticalHeader.vue | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue b/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue index 613771860..b552670c3 100644 --- a/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue +++ b/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue @@ -27,6 +27,7 @@ const customizer = useCustomizerStore(); const theme = useTheme(); const { t } = useI18n(); const route = useRoute(); +const LAST_BOT_ROUTE_KEY = 'astrbot:last_bot_route'; let dialog = ref(false); let accountWarning = ref(false) let updateStatusDialog = ref(false); @@ -402,15 +403,32 @@ const viewMode = computed({ }); // 监听 viewMode 变化,切换到 bot 模式时跳转到首页 -watch(() => customizer.viewMode, (newMode, oldMode) => { - if (newMode === 'bot' && oldMode === 'chat') { - // 从 chat 模式切换到 bot 模式时,跳转到首页 - if (route.path !== '/') { - router.push('/'); +// 保存 bot 模式的最後路由 +// 監聽 route 變化,保存最後一次 bot 路由 +watch(() => route.fullPath, (newPath) => { + if (customizer.viewMode === 'bot' && typeof window !== 'undefined') { + try { + localStorage.setItem(LAST_BOT_ROUTE_KEY, newPath); + } catch (e) { + console.error('Failed to save last bot route to localStorage:', e); } } }); +// 監聽 viewMode 切換 +watch(() => customizer.viewMode, (newMode, oldMode) => { + if (newMode === 'bot' && oldMode === 'chat' && typeof window !== 'undefined') { + // 從 chat 切換回 bot,跳轉到最後一次的 bot 路由 + let lastBotRoute = '/'; + try { + lastBotRoute = localStorage.getItem(LAST_BOT_ROUTE_KEY) || '/'; + } catch (e) { + console.error('Failed to read last bot route from localStorage:', e); + } + router.push(lastBotRoute); + } +}); + // Merry Christmas! 🎄 const isChristmas = computed(() => { const today = new Date();