Skip to content

Commit 387f8bf

Browse files
committed
refactor: 更新 Header、LogoSection 和 Logo 组件以支持迷你模式,优化样式和布局
1 parent e48a5ed commit 387f8bf

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

web/src/layout/MainLayout/Header/index.jsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import PropTypes from 'prop-types';
22
import { Icon } from '@iconify/react';
33
import { useLocation } from 'react-router-dom';
4+
import { useSelector } from 'react-redux';
45

56
// material-ui
67
import { useTheme } from '@mui/material/styles';
@@ -12,6 +13,7 @@ import Profile from './Profile';
1213
import ThemeButton from 'ui-component/ThemeButton';
1314
import I18nButton from 'ui-component/i18nButton';
1415
import { NoticeButton } from 'ui-component/notice';
16+
import { drawerWidth, miniDrawerWidth } from 'store/constant';
1517

1618
// ==============================|| MAIN NAVBAR / HEADER ||============================== //
1719

@@ -20,20 +22,36 @@ const Header = ({ handleLeftDrawerToggle, toggleProfileDrawer }) => {
2022
const matchUpMd = useMediaQuery(theme.breakpoints.up('md'));
2123
const location = useLocation();
2224
const isConsoleRoute = location.pathname.startsWith('/panel');
25+
const leftDrawerOpened = useSelector((state) => state.customization.opened);
2326

2427
return (
2528
<>
2629
<Box
2730
sx={{
2831
display: 'flex',
2932
alignItems: 'center',
33+
...(matchUpMd && {
34+
width: `${leftDrawerOpened ? drawerWidth : miniDrawerWidth}px`,
35+
ml: leftDrawerOpened ? 0 : -3,
36+
transition: 'width 200ms cubic-bezier(0.4, 0, 0.2, 1), margin 200ms cubic-bezier(0.4, 0, 0.2, 1)'
37+
}),
3038
[theme.breakpoints.down('md')]: {
3139
width: 'auto'
3240
}
3341
}}
3442
>
35-
<Box component="span" sx={{ display: { xs: 'none', md: 'block' }, mr: 1 }}>
36-
<LogoSection />
43+
<Box
44+
component="span"
45+
sx={{
46+
display: { xs: 'none', md: 'flex' },
47+
alignItems: 'center',
48+
justifyContent: leftDrawerOpened ? 'flex-start' : 'center',
49+
width: '100%',
50+
overflow: 'visible',
51+
transition: 'all 200ms cubic-bezier(0.4, 0, 0.2, 1)'
52+
}}
53+
>
54+
<LogoSection isMini={!leftDrawerOpened} />
3755
</Box>
3856
{!matchUpMd && (
3957
<IconButton

web/src/layout/MainLayout/LogoSection/index.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { MENU_OPEN } from 'store/actions';
1111

1212
// ==============================|| MAIN LOGO ||============================== //
1313

14-
const LogoSection = () => {
14+
const LogoSection = ({ isMini = false }) => {
1515
const defaultId = useSelector((state) => state.customization.defaultId);
1616
const dispatch = useDispatch();
1717

@@ -23,13 +23,15 @@ const LogoSection = () => {
2323
to={config.basename}
2424
sx={{
2525
transition: 'all 0.2s ease-in-out',
26+
padding: isMini ? 0 : undefined,
27+
minWidth: 0,
2628
'&:hover': {
2729
opacity: 0.9
2830
}
2931
}}
3032
>
31-
<Box sx={{ display: 'flex', alignItems: 'center' }}>
32-
<Logo />
33+
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
34+
<Logo isMini={isMini} />
3335
</Box>
3436
</ButtonBase>
3537
);

web/src/ui-component/Logo.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useTheme } from '@mui/material/styles';
1414

1515
// ==============================|| LOGO SVG ||============================== //
1616

17-
const Logo = () => {
17+
const Logo = ({ isMini = false }) => {
1818
const siteInfo = useSelector((state) => state.siteInfo);
1919
const theme = useTheme();
2020
const defaultLogo = theme.palette.mode === 'light' ? logoLight : logoDark;
@@ -25,7 +25,18 @@ const Logo = () => {
2525

2626
const logoToDisplay = siteInfo.logo ? siteInfo.logo : defaultLogo;
2727

28-
return <img src={logoToDisplay} alt={siteInfo.system_name} height="50" />;
28+
return (
29+
<img
30+
src={logoToDisplay}
31+
alt={siteInfo.system_name}
32+
style={{
33+
height: isMini ? '28px' : '50px',
34+
maxWidth: isMini ? '48px' : 'none',
35+
objectFit: 'contain',
36+
transition: 'all 200ms cubic-bezier(0.4, 0, 0.2, 1)'
37+
}}
38+
/>
39+
);
2940
};
3041

3142
export default Logo;

0 commit comments

Comments
 (0)