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

@@ -1,5 +1,43 @@
:root {
/* 颜色系统 - 暗色主题 */
/* 亮色主题(默认) */
:root, [data-theme="light"] {
--bg-primary: #f8f9fb;
--bg-secondary: #ffffff;
--bg-tertiary: #f0f1f3;
--bg-card: rgba(0, 0, 0, 0.02);
--bg-card-hover: rgba(0, 0, 0, 0.04);
--bg-glass: rgba(0, 0, 0, 0.03);
--bg-glass-hover: rgba(0, 0, 0, 0.06);
--border-primary: rgba(0, 0, 0, 0.08);
--border-secondary: rgba(0, 0, 0, 0.04);
--border-focus: rgba(99, 102, 241, 0.5);
--text-primary: #18181b;
--text-secondary: #52525b;
--text-tertiary: #a1a1aa;
--text-inverse: #ffffff;
--accent: #6366f1;
--accent-hover: #4f46e5;
--accent-muted: rgba(99, 102, 241, 0.1);
--success: #16a34a;
--success-muted: rgba(22, 163, 74, 0.1);
--warning: #d97706;
--warning-muted: rgba(217, 119, 6, 0.1);
--error: #dc2626;
--error-muted: rgba(220, 38, 38, 0.1);
--info: #2563eb;
--info-muted: rgba(37, 99, 235, 0.1);
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
--shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
--shadow-glow: 0 0 20px rgba(99, 102, 241, 0.1);
}
/* 暗色主题 */
[data-theme="dark"] {
--bg-primary: #0a0a0f;
--bg-secondary: #12121a;
--bg-tertiary: #1a1a26;
@@ -10,19 +48,15 @@
--border-primary: rgba(255, 255, 255, 0.08);
--border-secondary: rgba(255, 255, 255, 0.04);
--border-focus: rgba(99, 102, 241, 0.5);
--text-primary: #e4e4e7;
--text-secondary: #a1a1aa;
--text-tertiary: #71717a;
--text-inverse: #0a0a0f;
/* 强调色 */
--accent: #6366f1;
--accent-hover: #818cf8;
--accent-muted: rgba(99, 102, 241, 0.15);
/* 状态色 */
--success: #22c55e;
--success-muted: rgba(34, 197, 94, 0.15);
--warning: #f59e0b;
@@ -32,7 +66,14 @@
--info: #3b82f6;
--info-muted: rgba(59, 130, 246, 0.15);
/* 间距 */
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
--shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
--shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}
/* 共享变量(不随主题变化) */
:root {
--space-xs: 4px;
--space-sm: 8px;
--space-md: 12px;
@@ -41,13 +82,11 @@
--space-2xl: 32px;
--space-3xl: 48px;
/* 圆角 */
--radius-sm: 6px;
--radius-md: 8px;
--radius-lg: 12px;
--radius-xl: 16px;
/* 字体 */
--font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Noto Sans SC', sans-serif;
--font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
--font-size-xs: 11px;
@@ -57,18 +96,10 @@
--font-size-xl: 20px;
--font-size-2xl: 24px;
/* 阴影 */
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
--shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
--shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
/* 动效 */
--transition-fast: 150ms ease;
--transition-normal: 250ms ease;
--transition-slow: 350ms ease;
/* 布局 */
--sidebar-width: 220px;
--sidebar-collapsed: 60px;
--header-height: 52px;