From 4ab8653cdb519a7c70fb197838e201abffdb88c6 Mon Sep 17 00:00:00 2001 From: wzj <244142824@qq.com> Date: Wed, 9 Jul 2025 10:31:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A6=96=E9=A1=B5=E8=83=BD?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=83=8C=E6=99=AF=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/settings.json | 4 +-- templates/index.html | 68 ++++++++++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/data/settings.json b/data/settings.json index 401e53a..8d74aca 100644 --- a/data/settings.json +++ b/data/settings.json @@ -1,7 +1,7 @@ { - "card_style": "compact", + "card_style": "normal", "search_history": [], - "theme": "dark", + "theme": "light", "bg_image": "/upload/background/5dd4f5d3cd7b.png", "dark_bg_image": "/upload/background/d078c01de3be.png", "site_title": "应用导航中心", diff --git a/templates/index.html b/templates/index.html index e2afee9..7663b67 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1655,31 +1655,57 @@ body.dark-theme .secondary-filters-container::after { } // 主题切换功能 - function setupThemeSwitcher() { - const themeToggle = document.getElementById('themeToggle'); +// 主题切换功能 +function setupThemeSwitcher() { + const themeToggle = document.getElementById('themeToggle'); - themeToggle.addEventListener('click', () => { - // 只在明亮和暗黑之间切换 - if (document.body.classList.contains('dark-theme')) { - settings.theme = 'light'; - document.body.classList.remove('dark-theme'); + themeToggle.addEventListener('click', () => { + // 确定新主题 + const newTheme = document.body.classList.contains('dark-theme') ? 'light' : 'dark'; - // 更新视频背景显示状态 - document.querySelectorAll('.video-bg-container.bg-light').forEach(el => el.style.display = 'block'); - document.querySelectorAll('.video-bg-container.bg-dark').forEach(el => el.style.display = 'none'); - } else { - settings.theme = 'dark'; - document.body.classList.add('dark-theme'); + // 更新界面主题 + document.body.classList.remove('dark-theme', 'light-theme'); + if (newTheme === 'dark') { + document.body.classList.add('dark-theme'); + // 更新视频背景显示状态 + document.querySelectorAll('.video-bg-container.bg-light').forEach(el => el.style.display = 'none'); + document.querySelectorAll('.video-bg-container.bg-dark').forEach(el => el.style.display = 'block'); + } else { + document.body.classList.add('light-theme'); + // 更新视频背景显示状态 + document.querySelectorAll('.video-bg-container.bg-light').forEach(el => el.style.display = 'block'); + document.querySelectorAll('.video-bg-container.bg-dark').forEach(el => el.style.display = 'none'); + } - // 更新视频背景显示状态 - document.querySelectorAll('.video-bg-container.bg-light').forEach(el => el.style.display = 'none'); - document.querySelectorAll('.video-bg-container.bg-dark').forEach(el => el.style.display = 'block'); - } + // 更新主题按钮图标 + updateThemeButtonIcon(); - updateThemeButtonIcon(); - saveSettings(); - }); - } + // 更新本地设置(仅主题) + settings.theme = newTheme; + + // 保存设置(不会影响后台的背景设置) + if (isLoggedIn) { + // 已登录用户只更新主题设置 + fetch('/api/settings', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ theme: newTheme }) + }).catch(error => { + console.error('保存主题设置失败:', error); + }); + } else { + // 游客保存到本地(仅保存主题、卡片样式和搜索历史) + const settingsToSave = { + theme: newTheme, + card_style: settings.card_style, + search_history: settings.search_history + }; + localStorage.setItem('navSettings', JSON.stringify(settingsToSave)); + } + }); +} // 简洁模式切换 function setupCompactToggle() {