feat: 侧边栏默认亮色主题,暗黑主题下跟随切换
This commit is contained in:
@@ -72,4 +72,36 @@ describe('AppLayout', () => {
|
||||
const header = container.querySelector('.ant-layout-header') as HTMLElement;
|
||||
expect(header.style.background).toBe('#141414');
|
||||
});
|
||||
|
||||
it('uses light menu theme in default mode', async () => {
|
||||
const { useTheme } = await import('@/contexts/ThemeContext');
|
||||
vi.mocked(useTheme).mockReturnValue({
|
||||
effectiveThemeId: 'default',
|
||||
themeId: 'default',
|
||||
followSystem: false,
|
||||
systemIsDark: false,
|
||||
setThemeId: vi.fn(),
|
||||
setFollowSystem: vi.fn(),
|
||||
});
|
||||
|
||||
const { container } = renderWithRouter(<AppLayout />);
|
||||
expect(container.querySelector('.ant-menu-light')).toBeInTheDocument();
|
||||
expect(container.querySelector('.ant-menu-dark')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('uses dark menu theme in dark mode', async () => {
|
||||
const { useTheme } = await import('@/contexts/ThemeContext');
|
||||
vi.mocked(useTheme).mockReturnValue({
|
||||
effectiveThemeId: 'dark',
|
||||
themeId: 'dark',
|
||||
followSystem: false,
|
||||
systemIsDark: false,
|
||||
setThemeId: vi.fn(),
|
||||
setFollowSystem: vi.fn(),
|
||||
});
|
||||
|
||||
const { container } = renderWithRouter(<AppLayout />);
|
||||
expect(container.querySelector('.ant-menu-dark')).toBeInTheDocument();
|
||||
expect(container.querySelector('.ant-menu-light')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,6 +15,7 @@ export function AppLayout() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const { effectiveThemeId } = useTheme();
|
||||
const isDark = effectiveThemeId === 'dark';
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
|
||||
const getPageTitle = () => {
|
||||
@@ -31,6 +32,7 @@ export function AppLayout() {
|
||||
collapsed={collapsed}
|
||||
onCollapse={setCollapsed}
|
||||
breakpoint="lg"
|
||||
theme={isDark ? 'dark' : 'light'}
|
||||
style={{
|
||||
overflow: 'hidden',
|
||||
height: '100vh',
|
||||
@@ -47,7 +49,7 @@ export function AppLayout() {
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
color: '#fff',
|
||||
color: isDark ? '#fff' : 'rgba(0, 0, 0, 0.88)',
|
||||
fontSize: collapsed ? '1rem' : '1.25rem',
|
||||
fontWeight: 600,
|
||||
transition: 'all 0.2s',
|
||||
@@ -57,7 +59,7 @@ export function AppLayout() {
|
||||
{collapsed ? 'AI' : 'AI Gateway'}
|
||||
</div>
|
||||
<Menu
|
||||
theme="dark"
|
||||
theme={isDark ? 'dark' : 'light'}
|
||||
mode="inline"
|
||||
selectedKeys={[location.pathname]}
|
||||
items={menuItems}
|
||||
|
||||
Reference in New Issue
Block a user