From 6b05d343f15663c3edc1fa30d4555a6518608169 Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Fri, 3 Dec 2021 16:00:57 +0800 Subject: [PATCH] fix: Fix menu click range Fix menu click range Change-Id: Iee68fac62d1f406b7f560ff16ca7e0829eda0c49 --- src/layouts/Base/Menu.jsx | 40 ++++++++++++++++++++++++++----------- src/layouts/Base/index.less | 28 ++++++++++++++------------ 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/layouts/Base/Menu.jsx b/src/layouts/Base/Menu.jsx index ddbce42c..14f9262f 100644 --- a/src/layouts/Base/Menu.jsx +++ b/src/layouts/Base/Menu.jsx @@ -34,6 +34,7 @@ export class LayoutMenu extends Component { hover: false, openKeys: [], }; + this.maxTitleLength = 17; } get menu() { @@ -57,6 +58,10 @@ export class LayoutMenu extends Component { return this.props.rootStore; } + get routing() { + return this.props.rootStore.routing; + } + onCollapse = (collapsed) => { this.setState({ collapsed }); }; @@ -97,6 +102,14 @@ export class LayoutMenu extends Component { } }; + onClickMenuItem = ({ key }) => { + const path = getPath({ key }); + const { pathname } = this.props; + if (pathname !== path) { + this.routing.push(path); + } + }; + renderMenuItem = (item) => { const { collapsed, hover } = this.state; if (collapsed && !hover) { @@ -112,18 +125,21 @@ export class LayoutMenu extends Component { } if (!item.children || item.children.length === 0 || item.level) { return ( - + + {/* */} {item.icon} - - - {item.name.length >= 14 ? ( - - {item.name} - - ) : ( - item.name - )} - + + {item.name.length >= this.maxTitleLength ? ( + + {item.name} + + ) : ( + item.name + )} ); @@ -132,7 +148,7 @@ export class LayoutMenu extends Component { {item.icon} - {item.name.length >= 14 ? ( + {item.name.length >= this.maxTitleLength ? ( {item.name} diff --git a/src/layouts/Base/index.less b/src/layouts/Base/index.less index b50574cd..12f64f47 100644 --- a/src/layouts/Base/index.less +++ b/src/layouts/Base/index.less @@ -99,6 +99,8 @@ .anticon { font-size: @size-normal; margin-right: 20px; + float: left; + line-height: 44px; } & .ant-menu-item-selected { @@ -135,17 +137,7 @@ padding-right: 5px; } - .ant-menu-item > span > a { - padding-left: 13px; - display: inline-block; - width: 100%; - color: transparent; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - } - - .ant-menu-item > span > a::before { + .ant-menu-item > span::before { position: absolute; top: 18px; bottom: 0; @@ -157,11 +149,11 @@ border-radius: 50%; } - .ant-menu-item-selected > span > a::before { + .ant-menu-item-selected > span::before { background-color: #fff !important; } - .ant-menu-item-active > span > a::before { + .ant-menu-item-active > span::before { background-color: @primary-color; } @@ -321,3 +313,13 @@ box-shadow: 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 9px 28px 8px rgba(0, 0, 0, 0.05); } +.menu-item-title { + span { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + max-width: 140px; + display: inline-block; + } +}