Skip to content

Commit

Permalink
🐛 Layout-Header 中英文切换和主题色切换混了 #3 (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: jackhoo_98 <jackhoo_98@foxmail.com>
  • Loading branch information
13982720426 and jackhoo_98 authored May 26, 2024
1 parent c0c1567 commit 1331acd
Showing 1 changed file with 14 additions and 3 deletions.
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

0 comments on commit 1331acd

Please sign in to comment.