fix:优化filterBar组件联动

This commit is contained in:
Apple 2022-12-27 17:59:25 +08:00
parent 4c6765925b
commit 9614778235
1 changed files with 8 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import _ from "lodash";
import Menu from "../menu/main.js"; import Menu from "../menu/main.js";
export default class filterSelect extends React.Component { export default class filterSelect extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
let menuList = _.map(props.data.menuList, (item) => { let menuList = _.map(props.data.menuList, (item) => {
@ -31,10 +32,7 @@ export default class filterSelect extends React.Component {
this.setState({ menuShow: isShow }); this.setState({ menuShow: isShow });
} }
mouseLeaveFn(){ mouseLeaveFn(){
window.document.addEventListener('click',()=>{ this.setState({ menuShow:false});
this.setState({ menuShow:false});
});
} }
mouseMenuFn(){ mouseMenuFn(){
this.setState({ menuShow: true }); this.setState({ menuShow: true });
@ -80,7 +78,11 @@ export default class filterSelect extends React.Component {
}); });
this.setState({ menuList: menuList }); this.setState({ menuList: menuList });
} }
componentDidMount(){
window.document.addEventListener('click',()=>{
this.setState({ menuShow:false});
});
}
render() { render() {
return ( return (
<div className="filterComponent"> <div className="filterComponent">
@ -91,7 +93,7 @@ export default class filterSelect extends React.Component {
this.onHandlerClick(); this.onHandlerClick();
}} }}
onMouseEnter={()=>this.mouseMenuFn()} onMouseEnter={()=>this.mouseMenuFn()}
onMouseLeave={()=>this.mouseLeaveFn()} // onMouseLeave={()=>this.mouseLeaveFn()}
> >
<span className="filter-label">{this.state.label}</span> <span className="filter-label">{this.state.label}</span>
<span className="filter-maohao">:</span> <span className="filter-maohao">:</span>