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

fix leftsidebar #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
44 changes: 22 additions & 22 deletions src/components/SideBar/LeftSideBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getIcon = icon => {
return icon;
};

export const getMeunMatchKeys = (flatMenu, path) => {
export const getMenuMatchKeys = (flatMenu, path) => {
return flatMenu.filter(item => {
return pathToRegexp(item.path).test(path);
});
Expand All @@ -50,16 +50,16 @@ class LeftSideBar extends PureComponent {
}

componentDidUpdate(prevProps, prevState) {
if (
!isEqual(
this.props.currentMenu.parentPath,
prevProps.currentMenu.parentPath
)
) {
this.setState({
openKeys: this.props.currentMenu.parentPath || []
});
}
//if (
// !isEqual(
// String(this.props.currentMenu.parentPath),
// String(prevProps.currentMenu.parentPath)
// )
//) {
// this.setState({
// openKeys: this.props.currentMenu.parentPath || []
// });
//}
}

/**
Expand All @@ -86,7 +86,7 @@ class LeftSideBar extends PureComponent {
to={itemPath}
target={target}
replace={itemPath === this.props.location.pathname}
onClick={isMobile ? onCollapse : () => {}}
onClick={isMobile ? onCollapse : () => { }}
>
{icon}
<span>{name}</span>
Expand All @@ -110,8 +110,8 @@ class LeftSideBar extends PureComponent {
<span>{item.name}</span>
</span>
) : (
item.name
)
item.name
)
}
key={item.path}
>
Expand Down Expand Up @@ -155,7 +155,7 @@ class LeftSideBar extends PureComponent {
// Get the currently selected menu
getSelectedMenuKeys = () => {
const pathname = this.props.location.pathname;
const selectMenu = getMeunMatchKeys(this.props.flatMenu, pathname)[0];
const selectMenu = getMenuMatchKeys(this.props.flatMenu, pathname)[0];
return selectMenu ? [selectMenu.path] : [];
};

Expand Down Expand Up @@ -202,12 +202,12 @@ class LeftSideBar extends PureComponent {
// Don't show popup menu when it is been collapsed
const menuProps = collapsed
? {
selectedKeys
}
selectedKeys
}
: {
openKeys,
selectedKeys
};
openKeys,
selectedKeys
};

const siderBar = (
<Sider
Expand Down Expand Up @@ -297,8 +297,8 @@ class LeftSideBar extends PureComponent {
{siderBar}
</Drawer>
) : (
siderBar
);
siderBar
);
}
}

Expand Down
60 changes: 30 additions & 30 deletions src/layouts/BasicLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class BasicLayout extends React.PureComponent {
collapsedRightSide: true, // 右边栏开关
theme, // 皮肤设置
user,
currentMenu: {},
currentMenu: this.getCurrentMenu(this.props),
isMobile: false
};

Expand Down Expand Up @@ -244,35 +244,35 @@ export default class BasicLayout extends React.PureComponent {
{theme.layout.indexOf('tabLayout') >= 0 ? (
<TabsLayout childRoutes={childRoutes} location={location} />
) : (
<Layout className="full-layout">
<Header>
<TopBar
expand={expandTopBar}
toggleRightSide={this.toggleRightSide}
collapsedRightSide={collapsedRightSide}
onCollapse={this.onCollapseTopBar}
currentMenu={currentMenu}
location={location}
theme={theme}
/>
</Header>
<Content style={{ overflow: 'hidden' }}>
<SwitchTransition>
<CSSTransition
key={location.pathname}
classNames="fade"
timeout={500}
>
<Layout className="full-layout">
<Content className="router-page">
<Switch location={location}>{childRoutes}</Switch>
</Content>
</Layout>
</CSSTransition>
</SwitchTransition>
</Content>
</Layout>
)}
<Layout className="full-layout">
<Header>
<TopBar
expand={expandTopBar}
toggleRightSide={this.toggleRightSide}
collapsedRightSide={collapsedRightSide}
onCollapse={this.onCollapseTopBar}
currentMenu={currentMenu}
location={location}
theme={theme}
/>
</Header>
<Content style={{ overflow: 'hidden' }}>
<SwitchTransition>
<CSSTransition
key={location.pathname}
classNames="fade"
timeout={500}
>
<Layout className="full-layout">
<Content className="router-page">
<Switch location={location}>{childRoutes}</Switch>
</Content>
</Layout>
</CSSTransition>
</SwitchTransition>
</Content>
</Layout>
)}
</Content>
<RightSideBar
collapsed={collapsedRightSide}
Expand Down