import React, { Component } from 'react' import { Link } from 'react-router-dom' import { Row, Col, Menu, AutoComplete, Input, Icon } from 'antd' import axios from 'axios' import { connect } from 'react-redux' import PropTypes from 'prop-types' const Option = AutoComplete.Option; @connect( state => { console.log(state); return { curUid: state.login.uid + '', curUserName: state.login.userName } } ) class LeftMenu extends Component { constructor(props) { super(props) this.state = { dataSource: [] } this.searchSign = 0; this._searchSign = 0; this.interval = null; } static propTypes = { curUid: PropTypes.string, curUserName: PropTypes.string } //延迟搜索 handleSearch = (value) => { if(!value || value.length < 1) return ; this.searchSign = this.searchSign + 1; this.interval && clearInterval(this.interval) this.interval = setInterval(() => { if (this.searchSign === this._searchSign) { this.interval = clearInterval(this.interval) axios.get('/user/search?q=' + value).then((res) => { if (res.data.errcode === 0) { this.setState({ dataSource: res.data.data }) } }) } else { this._searchSign = this.searchSign; } }, 600) } renderOption = (item) => { return ( ) } render() { const menus = [{ title: '个人资料', path: `/user/profile/${this.props.curUid}` }, { title: '用户管理', path: '/user/list' } ] let content = menus.map((menu) => { return ( {menu.title} ) }) const { dataSource } = this.state; return (
用户名 : {`${this.props.curUserName}`}
} />
{content}
) } } export default LeftMenu