Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 修复 Layout-Header 中英文切换和主题色切换混 #3 #4

Merged
merged 1 commit into from
May 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { Layout, Menu, theme, Avatar, Dropdown, ConfigProvider, Badge, Popover, type MenuProps } from 'antd';
import getNavList from './menu';
import { useRouter } from 'next/navigation';
Expand All @@ -22,6 +22,10 @@ interface IProps {
defaultOpen?: string[]
}

const onLogout = () => {
localStorage.removeItem("isDarkTheme")
}

const items: MenuProps['items'] = [
{
key: '1',
Expand All @@ -42,7 +46,7 @@ const items: MenuProps['items'] = [
{
key: '3',
label: (
<a target="_blank" rel="noopener noreferrer" href="/user/login">
<a target="_blank" onClick={onLogout} rel="noopener noreferrer" href="/user/login">
退出登录
</a>
),
Expand All @@ -65,13 +69,20 @@ const CommonLayout: React.FC<IProps> = ({ children, curActive, defaultOpen = ['/

const [curTheme, setCurTheme] = useState<boolean>(false);
const toggleTheme = () => {
setCurTheme(prev => !prev);
const _curTheme = !curTheme;
setCurTheme(_curTheme);
localStorage.setItem('isDarkTheme', _curTheme ? 'true' : '');
}

const handleSelect = (row: {key: string}) => {
router.push(row.key)
}

useEffect(() => {
const isDark = !!localStorage.getItem("isDarkTheme");
setCurTheme(isDark);
}, []);

return (
<ConfigProvider
theme={{
Expand Down