Browse Source

Fix menu click exception

pull/1607/head
jim 8 years ago
parent
commit
c1c36b6118
  1. 5
      .webpackrc.js
  2. 12
      package.json
  3. 2
      src/components/Sidebar/index.js
  4. 26
      src/components/SiderMenu/SiderMenu.js

5
.webpackrc.js

@ -2,9 +2,7 @@ const path = require('path');
export default {
entry: 'src/index.js',
extraBabelPlugins: [
['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],
],
extraBabelPlugins: [['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }]],
env: {
development: {
extraBabelPlugins: ['dva-hmr'],
@ -19,5 +17,6 @@ export default {
template: './src/index.ejs',
},
publicPath: '/',
disableDynamicImport: true,
hash: true,
};

12
package.json

@ -39,7 +39,7 @@
"path-to-regexp": "^2.1.0",
"prop-types": "^15.5.10",
"qs": "^6.5.0",
"rc-drawer-menu": "^0.5.0",
"rc-drawer-menu": "^1.1.0",
"react": "^16.3.1",
"react-container-query": "^0.11.0",
"react-document-title": "^2.0.3",
@ -51,14 +51,14 @@
"devDependencies": {
"@types/react": "^16.3.8",
"@types/react-dom": "^16.0.5",
"antd-theme-webpack-plugin": "^1.0.8",
"babel-eslint": "^8.1.2",
"babel-plugin-dva-hmr": "^0.4.1",
"babel-plugin-import": "^1.6.7",
"babel-plugin-module-resolver": "^3.1.1",
"cross-env": "^5.1.1",
"antd-theme-webpack-plugin": "^1.0.8",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-runtime": "^6.9.2",
"cross-env": "^5.1.1",
"cross-port-killer": "^1.0.1",
"enzyme": "^3.1.0",
"eslint": "^4.14.0",
@ -74,13 +74,13 @@
"husky": "^0.14.3",
"lint-staged": "^7.0.5",
"mockjs": "^1.0.1-beta3",
"prettier": "1.12.1",
"prettier": "1.13.2",
"pro-download": "^1.0.1",
"redbox-react": "^1.5.0",
"regenerator-runtime": "^0.11.1",
"roadhog": "^2.4.1",
"roadhog": "2.3.0",
"roadhog-api-doc": "^1.0.3",
"stylelint": "^8.4.0",
"stylelint": "^9.2.1",
"stylelint-config-prettier": "^3.0.4",
"stylelint-config-standard": "^18.0.0"
},

2
src/components/Sidebar/index.js

@ -136,7 +136,7 @@ class Sidebar extends PureComponent {
<DrawerMenu
parent={null}
level={null}
iconChild={null}
handleChild={null}
open={collapse}
placement="right"
width="336px"

26
src/components/SiderMenu/SiderMenu.js

@ -65,16 +65,22 @@ export const getMenuMatchKeys = (flatMenuKeys, paths) =>
);
export default class SiderMenu extends PureComponent {
static getDerivedStateFromProps(nextProps) {
return {
openKeys: getDefaultCollapsedSubMenus(nextProps),
};
static getDerivedStateFromProps(props, state) {
const { pathname } = state;
if (props.location.pathname !== pathname) {
return {
pathname: props.location.pathname,
openKeys: getDefaultCollapsedSubMenus(props),
};
}
return null;
}
constructor(props) {
super(props);
this.menus = props.menuData;
this.flatMenuKeys = getFlatMenuKeys(props.menuData);
this.state = {
pathname: props.location.pathname,
openKeys: getDefaultCollapsedSubMenus(props),
};
}
@ -113,7 +119,7 @@ export default class SiderMenu extends PureComponent {
<Link
to={itemPath}
target={target}
replace={itemPath === this.props.location.pathname}
replace={itemPath === this.state.pathname}
onClick={
this.props.isMobile
? () => {
@ -200,13 +206,17 @@ export default class SiderMenu extends PureComponent {
return ItemDom;
};
isMainMenu = key => {
return this.props.menuData.some(item => key && (item.key === key || item.path === key));
return this.props.menuData.some(item => {
if (key) {
return item.key === key || item.path === key;
}
return false;
});
};
handleOpenChange = openKeys => {
const lastOpenKey = openKeys[openKeys.length - 1];
const moreThanOne = openKeys.filter(openKey => this.isMainMenu(openKey)).length > 1;
this.setState({
openKeys: moreThanOne ? [lastOpenKey] : [...openKeys],
openKeys: moreThanOne ? [openKeys.pop()] : [...openKeys],
});
};
render() {

Loading…
Cancel
Save