|
@@ -0,0 +1,121 @@
|
|
|
+import React, { PureComponent } from 'react';
|
|
|
+import { connect } from 'react-redux';
|
|
|
+import { actionCreators } from './store';
|
|
|
+import { BrowserRouter, Route,Link } from 'react-router-dom';
|
|
|
+
|
|
|
+class Submenu extends PureComponent {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ render() {
|
|
|
+ // const { inputValue, handleInputFocus,handleInputChange, menu, list } = this.props;
|
|
|
+ return (
|
|
|
+ <nav id="js-primary-nav" class="primary-nav" role="navigation">
|
|
|
+ <ul id="js-nav-menu" class="nav-menu">
|
|
|
+ <li class="active">
|
|
|
+ <a href="contact.html" title="联系人" data-filter-tags="联系人">
|
|
|
+ <i class="fal fa-address-book"></i>
|
|
|
+ <span class="nav-link-text">联系人</span>
|
|
|
+ </a>
|
|
|
+ </li>
|
|
|
+ <li class="">
|
|
|
+ <a href="company.html" title="公司" data-filter-tags="公司">
|
|
|
+ <i class="fal fa-building "></i>
|
|
|
+ <span class="nav-link-text">公司</span>
|
|
|
+ </a>
|
|
|
+ </li>
|
|
|
+ </ul>
|
|
|
+ <div class="filter-message js-filter-message bg-success-600"></div>
|
|
|
+ </nav>
|
|
|
+
|
|
|
+ // <div>
|
|
|
+ // <BrowserRouter>
|
|
|
+ // <div>
|
|
|
+
|
|
|
+ // <ul>
|
|
|
+ // <li><Link to='/'>首页</Link></li>
|
|
|
+ // <li><Link to='/company'>关于</Link></li>
|
|
|
+ // </ul>
|
|
|
+
|
|
|
+ // {/* <Route path='/' exact component={Home}></Route>
|
|
|
+ // <Route path='/detail' exact component={Detail}></Route> */}
|
|
|
+ // <Route path='/' exact render={()=><div>联系人</div>} ></Route>
|
|
|
+ // <Route path='/company' exact render={()=><div>公司</div>} ></Route>
|
|
|
+
|
|
|
+ // </div>
|
|
|
+ // </BrowserRouter>
|
|
|
+ // {/* innerRef */}
|
|
|
+ // <div >{inputValue}</div>
|
|
|
+ // <input onFocus={() => handleInputFocus(list)} ref={(input)=>{this.ivalue=input}} onChange={()=>handleInputChange(this.ivalue)} />
|
|
|
+ // {menu}
|
|
|
+ // <div>{this.getListArea()}</div>
|
|
|
+ // </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ //组件即将要被挂在的时候执行的方法--
|
|
|
+ componentDidMount(){
|
|
|
+ //逻辑代码可以写在mapDispathToProps里 this.props.方法
|
|
|
+
|
|
|
+ // axios.get('/api/submenuList.json').then((res) => {
|
|
|
+ // const data = res.data;
|
|
|
+ // dispatch(changeList(data.data));
|
|
|
+ // }).catch(() => {
|
|
|
+ // console.log('error');
|
|
|
+ // })
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * store里的数据映射到这个组件里的state
|
|
|
+ * @param {*} state
|
|
|
+ */
|
|
|
+const mapStateToProps = (state) => {
|
|
|
+
|
|
|
+ return {
|
|
|
+ //menu: state.submenu.menu
|
|
|
+ menu: state.getIn(['submenu', 'menu']),
|
|
|
+ list: state.getIn(['submenu', 'list']),
|
|
|
+ inputValue: state.getIn(['submenu', 'inputValue']),
|
|
|
+ }
|
|
|
+ // return {
|
|
|
+ // focused: state.getIn(['header', 'focused']),
|
|
|
+ // list: state.getIn(['header', 'list']),
|
|
|
+ // page: state.getIn(['header', 'page']),
|
|
|
+ // totalPage: state.getIn(['header', 'totalPage']),
|
|
|
+ // mouseIn: state.getIn(['header', 'mouseIn'])
|
|
|
+ // }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 要改变store里的内容需要调用dispatch方法
|
|
|
+ * @param {*} dispatch
|
|
|
+ */
|
|
|
+const mapDispathToProps = (dispatch) => {
|
|
|
+ return {
|
|
|
+ handleInputFocus(list) {
|
|
|
+
|
|
|
+ // const action = {
|
|
|
+ // type: 'aearch_focus'
|
|
|
+ // };
|
|
|
+ //发送给store--提取出action--避免发送重复的ajax请求
|
|
|
+ (list.size === 0) && dispatch(actionCreators.getList());
|
|
|
+ // if(list.size>0){
|
|
|
+ // dispatch(actionCreators.getList());
|
|
|
+ // }
|
|
|
+ dispatch(actionCreators.searchFocus());
|
|
|
+ },
|
|
|
+ handleInputChange(ivalueElem){
|
|
|
+
|
|
|
+ dispatch(actionCreators.changeInputValue(ivalueElem.value));
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+export default connect(mapStateToProps, mapDispathToProps)(Submenu);
|