From 70aaad416e7da790bdd225e2c0b6e22cbe7e71af Mon Sep 17 00:00:00 2001 From: vapao Date: Mon, 16 Mar 2020 11:04:52 +0800 Subject: [PATCH] =?UTF-8?q?F=20=E4=BF=AE=E5=A4=8D=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E6=A0=8F=E6=9F=90=E4=BA=9B=E6=83=85=E5=86=B5=E4=B8=8B=E6=9C=AA?= =?UTF-8?q?=E6=8C=89=E9=A2=84=E6=9C=9F=E5=B1=95=E7=A4=BA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_web/src/layout/Sider.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/spug_web/src/layout/Sider.js b/spug_web/src/layout/Sider.js index 8273a73..bbba8b3 100644 --- a/spug_web/src/layout/Sider.js +++ b/spug_web/src/layout/Sider.js @@ -17,14 +17,15 @@ import logo from './logo.svg'; class Sider extends React.Component { constructor(props) { super(props); - this.keysMap = {}; + this._init(props); this.state = { - selectedKeys: [props.location.pathname], - openKeys: [], + selectedKeys: [], + openKeys: [lodash.get(this.keysMap, props.location.pathname)], }; } - componentDidMount() { + _init() { + this.keysMap = {}; for (let item of menus.filter(x => x.child)) { for (let m of item.child) { this.keysMap[m.path] = item.title @@ -61,7 +62,6 @@ class Sider extends React.Component { }; handleSelect = ({key}) => { - this.setState({selectedKeys: [key]}); history.push(key) }; @@ -72,13 +72,8 @@ class Sider extends React.Component { }; render() { - const subKey = lodash.get(this.keysMap, this.props.location.pathname); - let {openKeys} = this.state; - if (subKey && !openKeys.includes(subKey) && !this.props.collapsed) openKeys.push(subKey); return ( - +
Logo

Spug

@@ -86,8 +81,8 @@ class Sider extends React.Component { this.setState({openKeys})}