修复首页能修改背景的BUG

This commit is contained in:
wzj 2025-07-09 10:31:02 +08:00
parent 4e59384b56
commit 4ab8653cdb
2 changed files with 49 additions and 23 deletions

View File

@ -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": "应用导航中心",

View File

@ -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() {