1818
1919import {
2020 BankFilled ,
21- BgColorsOutlined ,
2221 ExportOutlined ,
2322 FormOutlined ,
2423 FunctionOutlined ,
@@ -27,11 +26,10 @@ import {
2726 SafetyCertificateFilled ,
2827 SettingFilled ,
2928 SettingOutlined ,
29+ SkinOutlined ,
3030 UserOutlined ,
3131} from '@ant-design/icons' ;
3232import { List , Menu , Tooltip } from 'antd' ;
33- import lightTheme from 'antd/dist/default-theme' ;
34- import { darkThemeSingle } from 'antd/dist/theme' ;
3533import logo from 'app/assets/images/logo.svg' ;
3634import { Avatar , MenuListItem , Popup } from 'app/components' ;
3735import useI18NPrefix from 'app/hooks/useI18NPrefix' ;
@@ -53,6 +51,7 @@ import { useDispatch, useSelector } from 'react-redux';
5351import { NavLink , useHistory , useRouteMatch } from 'react-router-dom' ;
5452import styled from 'styled-components/macro' ;
5553import {
54+ BLACK ,
5655 BORDER_RADIUS ,
5756 FONT_SIZE_ICON_SM ,
5857 FONT_WEIGHT_MEDIUM ,
@@ -61,9 +60,11 @@ import {
6160 SPACE_MD ,
6261 SPACE_TIMES ,
6362 SPACE_XS ,
63+ WHITE ,
6464} from 'styles/StyleConstants' ;
6565import themeSlice from 'styles/theme/slice' ;
6666import { ThemeKeyType } from 'styles/theme/slice/types' ;
67+ import { changeAntdTheme , saveTheme } from 'styles/theme/utils' ;
6768import { Access } from '../Access' ;
6869import {
6970 PermissionLevels ,
@@ -198,14 +199,8 @@ export function Navbar() {
198199 const handleChangeThemeFn = useCallback (
199200 ( theme : ThemeKeyType ) => {
200201 dispatch ( themeSlice . actions . changeTheme ( theme ) ) ;
201- ( window as any ) . less
202- . modifyVars ( theme === 'dark' ? darkThemeSingle : lightTheme )
203- . then ( ( res : any ) => {
204- console . log ( '切换主题成功' ) ;
205- } )
206- . catch ( ( res : any ) => {
207- console . log ( '切换主题错误' ) ;
208- } ) ;
202+ changeAntdTheme ( theme ) ;
203+ saveTheme ( theme ) ;
209204 } ,
210205 [ dispatch ] ,
211206 ) ;
@@ -325,14 +320,17 @@ export function Navbar() {
325320 </ MenuListItem >
326321 < MenuListItem
327322 key = "theme"
328- prefix = { < BgColorsOutlined className = "icon" /> }
323+ prefix = { < SkinOutlined className = "icon" /> }
329324 title = { < p > { t ( 'nav.account.switchTheme.title' ) } </ p > }
330325 sub
331326 >
332- < MenuListItem key = "light" >
327+ < MenuListItem key = "light" prefix = { < ThemeBadge /> } >
333328 { t ( 'nav.account.switchTheme.light' ) }
334329 </ MenuListItem >
335- < MenuListItem key = "dark" >
330+ < MenuListItem
331+ key = "dark"
332+ prefix = { < ThemeBadge background = { BLACK } /> }
333+ >
336334 { t ( 'nav.account.switchTheme.dark' ) }
337335 </ MenuListItem >
338336 </ MenuListItem >
@@ -511,3 +509,11 @@ const SubNavTitle = styled(NavLink)`
511509 }
512510 }
513511` ;
512+
513+ const ThemeBadge = styled . span < { background ?: string } > `
514+ width: ${ SPACE_TIMES ( 4 ) } ;
515+ height: ${ SPACE_TIMES ( 4 ) } ;
516+ background-color: ${ p => p . background || WHITE } ;
517+ border-radius: 50%;
518+ box-shadow: 0 0 2px 1px rgba(0, 0, 0, 0.2);
519+ ` ;
0 commit comments