feat: init ai-platform - 源码 + 配置

This commit is contained in:
2026-08-25 16:27:43 +08:00
commit 83210a606a
122 changed files with 27401 additions and 0 deletions
+234
View File
@@ -0,0 +1,234 @@
import { createContext, useContext, useState, useEffect } from 'react';
export type Theme = 'dark' | 'light';
// ── Token 定义 ─────────────────────────────────────────────────────────────
export interface ThemeTokens {
// 背景
bodyBg: string;
panelBg: string;
panelBgAlt: string;
centerBg: string;
// 边框
border: string;
borderSub: string;
borderAccent: string;
// 文字
text: string;
textSub: string;
textMuted: string;
textInverse: string;
// 强调色
accent: string;
accentGlow: string;
accentBg: string;
// 功能色
success: string;
successBg: string;
warning: string;
warningBg: string;
danger: string;
dangerBg: string;
// 特殊组件
headerScanLine: string;
kpiCardBg: string;
kpiCardBorder: string;
tableHeaderBg: string;
tableRowHover: string;
tableRowAlt: string;
scrollThumb: string;
// SVG面板渐变色
svgPanelFrom: string;
svgPanelTo: string;
svgStroke: string;
svgDot: string;
// 底部弧形
bottomArcFill: string;
bottomBg: string;
// 标题装饰
titleBarColor: string;
titleGlow: string;
}
export const darkTokens: ThemeTokens = {
bodyBg: '#000a1e',
panelBg: 'rgba(0,20,50,0.35)',
panelBgAlt: 'rgba(0,20,60,0.2)',
centerBg: 'rgba(0,15,45,0.55)',
border: 'rgba(0,212,255,0.12)',
borderSub: 'rgba(0,212,255,0.08)',
borderAccent: 'rgba(0,212,255,0.28)',
text: '#e8f4ff',
textSub: '#a8d8ff',
textMuted: 'rgba(255,255,255,0.5)',
textInverse: '#e8f4ff',
accent: '#00d4ff',
accentGlow: 'rgba(0,212,255,0.7)',
accentBg: 'rgba(0,212,255,0.06)',
success: '#00e599',
successBg: 'rgba(0,229,153,0.08)',
warning: '#ffb340',
warningBg: 'rgba(255,179,64,0.12)',
danger: '#ff6b6b',
dangerBg: 'rgba(255,107,107,0.08)',
headerScanLine: 'linear-gradient(90deg, transparent 0%, rgba(0,212,255,0.3) 20%, rgba(0,212,255,0.9) 50%, rgba(0,212,255,0.3) 80%, transparent 100%)',
kpiCardBg: 'rgba(0,212,255,0.05)',
kpiCardBorder: 'rgba(0,212,255,0.1)',
tableHeaderBg: 'rgba(0,40,100,0.7)',
tableRowHover: 'rgba(0,50,100,0.2)',
tableRowAlt: 'rgba(0,20,60,0.2)',
scrollThumb: 'rgba(0,212,255,0.25)',
svgPanelFrom: 'rgba(4,28,75,0.42)',
svgPanelTo: 'rgba(2,14,48,0.32)',
svgStroke: 'rgba(0,212,255,0.45)',
svgDot: 'rgba(0,212,255,0.9)',
bottomArcFill: 'rgba(0,15,50,0.42)',
bottomBg: 'linear-gradient(to bottom, rgba(0,15,50,0.42), rgba(0,8,28,0.52))',
titleBarColor: '#a8d8ff',
titleGlow: '0 0 24px rgba(0,212,255,0.7), 0 0 48px rgba(0,212,255,0.3)',
};
export const lightTokens: ThemeTokens = {
bodyBg: '#eef1f7',
panelBg: 'rgba(255,255,255,0.97)',
panelBgAlt: 'rgba(248,250,255,0.98)',
centerBg: 'linear-gradient(160deg, rgba(255,255,255,0.78) 0%, rgba(240,246,255,0.72) 50%, rgba(232,241,255,0.75) 100%)',
border: 'rgba(30,58,110,0.14)',
borderSub: 'rgba(30,58,110,0.08)',
borderAccent: 'rgba(26,86,219,0.28)',
text: '#111827',
textSub: '#1e3a6e',
textMuted: '#6b7280',
textInverse: '#ffffff',
accent: '#1a56db',
accentGlow: 'rgba(26,86,219,0.35)',
accentBg: 'rgba(26,86,219,0.06)',
success: '#047857',
successBg: 'rgba(4,120,87,0.07)',
warning: '#b45309',
warningBg: 'rgba(180,83,9,0.07)',
danger: '#b91c1c',
dangerBg: 'rgba(185,28,28,0.06)',
headerScanLine: 'linear-gradient(90deg, transparent 0%, rgba(26,86,219,0.15) 20%, rgba(26,86,219,0.5) 50%, rgba(26,86,219,0.15) 80%, transparent 100%)',
kpiCardBg: 'rgba(26,86,219,0.04)',
kpiCardBorder: 'rgba(26,86,219,0.12)',
tableHeaderBg: 'rgba(226,232,248,0.9)',
tableRowHover: 'rgba(210,222,255,0.4)',
tableRowAlt: 'rgba(241,245,255,0.75)',
scrollThumb: 'rgba(26,86,219,0.2)',
svgPanelFrom: 'rgba(238,243,255,0.97)',
svgPanelTo: 'rgba(225,235,255,0.95)',
svgStroke: 'rgba(26,86,219,0.35)',
svgDot: 'rgba(26,86,219,0.75)',
bottomArcFill: 'rgba(238,243,255,0.97)',
bottomBg: 'linear-gradient(to bottom, rgba(238,243,255,0.97), rgba(225,235,252,0.99))',
titleBarColor: '#111827',
titleGlow: 'none',
};
// ── Light theme CSS variables (shadcn/ui HSL) ──────────────────────────────
const lightCssVars: Record<string, string> = {
'--background': '240 6% 97%',
'--foreground': '240 10% 10%',
'--card': '0 0% 100%',
'--card-foreground': '240 10% 10%',
'--popover': '0 0% 100%',
'--popover-foreground': '240 10% 10%',
'--primary': '211 100% 50%',
'--primary-foreground': '0 0% 100%',
'--secondary': '240 5% 93%',
'--secondary-foreground': '240 10% 25%',
'--muted': '240 5% 95%',
'--muted-foreground': '240 5% 52%',
'--accent': '211 100% 50%',
'--accent-foreground': '0 0% 100%',
'--border': '240 5% 88%',
'--input': '240 5% 93%',
'--ring': '211 100% 50%',
};
// ── Dark theme CSS variables (shadcn/ui HSL) ──────────────────────────────
const darkCssVars: Record<string, string> = {
'--background': '222 47% 5%',
'--foreground': '210 40% 98%',
'--card': '222 47% 8%',
'--card-foreground': '210 40% 98%',
'--popover': '222 47% 8%',
'--popover-foreground': '210 40% 98%',
'--primary': '210 40% 98%',
'--primary-foreground': '222 47% 5%',
'--secondary': '217 33% 17%',
'--secondary-foreground': '210 40% 98%',
'--muted': '217 33% 17%',
'--muted-foreground': '215 20% 65%',
'--accent': '217 33% 17%',
'--accent-foreground': '210 40% 98%',
'--border': '217 33% 17%',
'--input': '217 33% 17%',
'--ring': '212 68% 58%',
};
// ── Context ────────────────────────────────────────────────────────────────
interface ThemeContextValue {
theme: Theme;
tokens: ThemeTokens;
toggleTheme: () => void;
setTheme: (theme: Theme) => void;
}
const ThemeContext = createContext<ThemeContextValue>({
theme: 'dark',
tokens: darkTokens,
toggleTheme: () => {},
setTheme: () => {},
});
const STORAGE_KEY = 'eios-theme';
export function ThemeProvider({ children }: { children: React.ReactNode }) {
const [theme, setThemeState] = useState<Theme>(() => {
try {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored === 'light' || stored === 'dark') return stored;
} catch {}
return 'dark';
});
const tokens = theme === 'dark' ? darkTokens : lightTokens;
const setTheme = (t: Theme) => {
setThemeState(t);
try { localStorage.setItem(STORAGE_KEY, t); } catch {}
};
const toggleTheme = () => setTheme(theme === 'dark' ? 'light' : 'dark');
// Sync body background and CSS variables
useEffect(() => {
document.body.style.backgroundColor = tokens.bodyBg;
document.body.style.color = theme === 'dark' ? '#a8d8ff' : '#1e3a6e';
const cssVars = theme === 'dark' ? darkCssVars : lightCssVars;
const root = document.documentElement;
Object.entries(cssVars).forEach(([key, value]) => {
root.style.setProperty(key, value);
});
// Toggle dark class for Tailwind darkMode
if (theme === 'dark') {
root.classList.add('dark');
} else {
root.classList.remove('dark');
}
}, [theme, tokens]);
return (
<ThemeContext.Provider value={{ theme, tokens, toggleTheme, setTheme }}>
{children}
</ThemeContext.Provider>
);
}
export function useTheme() {
return useContext(ThemeContext);
}