fix: 前端修正切換到 chat 切換後回 welcome 的配置保存最終切換頁面 (#5792)
* 前端修正切換到chat切換後回 welcome 的配置保存最終切換頁面 * 修復 SSR 不含localStorage 環境驗證
This commit is contained in:
@@ -27,6 +27,7 @@ const customizer = useCustomizerStore();
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const LAST_BOT_ROUTE_KEY = 'astrbot:last_bot_route';
|
||||||
let dialog = ref(false);
|
let dialog = ref(false);
|
||||||
let accountWarning = ref(false)
|
let accountWarning = ref(false)
|
||||||
let updateStatusDialog = ref(false);
|
let updateStatusDialog = ref(false);
|
||||||
@@ -402,15 +403,32 @@ const viewMode = computed({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 监听 viewMode 变化,切换到 bot 模式时跳转到首页
|
// 监听 viewMode 变化,切换到 bot 模式时跳转到首页
|
||||||
watch(() => customizer.viewMode, (newMode, oldMode) => {
|
// 保存 bot 模式的最後路由
|
||||||
if (newMode === 'bot' && oldMode === 'chat') {
|
// 監聽 route 變化,保存最後一次 bot 路由
|
||||||
// 从 chat 模式切换到 bot 模式时,跳转到首页
|
watch(() => route.fullPath, (newPath) => {
|
||||||
if (route.path !== '/') {
|
if (customizer.viewMode === 'bot' && typeof window !== 'undefined') {
|
||||||
router.push('/');
|
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! 🎄
|
// Merry Christmas! 🎄
|
||||||
const isChristmas = computed(() => {
|
const isChristmas = computed(() => {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
|
|||||||
Reference in New Issue
Block a user