feat: 添加日间/夜间主题切换系统

- 新增 theme.js 主题管理模块(localStorage 持久化)
- variables.css 重构为亮色默认 + 暗色 data-theme 切换
- sidebar 底部添加主题切换按钮(sun/moon SVG 图标)
- 修复 scrollbar 硬编码颜色为 CSS 变量
- 修复 agents.js fallbacks 未定义时的空指针错误
This commit is contained in:
晴天
2026-02-26 23:08:21 +08:00
parent d32ce81547
commit 8bf2caf788
7 changed files with 110 additions and 22 deletions

View File

@@ -2,6 +2,7 @@
* 侧边导航栏
*/
import { navigate, getCurrentRoute } from '../router.js'
import { toggleTheme, getTheme } from '../lib/theme.js'
const NAV_ITEMS = [
{
@@ -68,10 +69,31 @@ export function renderSidebar(el) {
}
html += '</nav>'
// 主题切换按钮
const isDark = getTheme() === 'dark'
const sunIcon = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>'
const moonIcon = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"/></svg>'
html += `
<div class="sidebar-footer">
<div class="nav-item" id="btn-theme-toggle">
${isDark ? sunIcon : moonIcon}
<span>${isDark ? '日间模式' : '夜间模式'}</span>
</div>
</div>
`
el.innerHTML = html
// 绑定点击事件
el.querySelectorAll('.nav-item').forEach(item => {
// 绑定导航点击事件
el.querySelectorAll('.nav-item[data-route]').forEach(item => {
item.onclick = () => navigate(item.dataset.route)
})
// 主题切换
el.querySelector('#btn-theme-toggle')?.addEventListener('click', () => {
toggleTheme()
renderSidebar(el)
})
}