diff --git a/.webpackrc.js b/.webpackrc.js index 79ac4d2983560f456d52272c58b0ef3dc7a9be96..fe823e7a8f2fc87986f1dc1310d4addaaa8ae7a5 100755 --- a/.webpackrc.js +++ b/.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, }; diff --git a/package.json b/package.json index 8cd618ff0bba0f5fddc13599fb856c684a25246f..cb2856771e46369c57ec08e6e0bbd094661b1de3 100755 --- a/package.json +++ b/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" }, diff --git a/src/components/Sidebar/index.js b/src/components/Sidebar/index.js index 1ba2b4a309d11c125614e76ef5fa0a61d0722bf1..b6436c8e1ac62c567ccd9443aedb2ee04f7418d3 100644 --- a/src/components/Sidebar/index.js +++ b/src/components/Sidebar/index.js @@ -136,7 +136,7 @@ class Sidebar extends PureComponent { ); 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 { { @@ -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() {