index.js 4.16 KB
Newer Older
bert committed
1 2 3 4 5
import React, { PropTypes } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Link } from 'react-router';
import { Menu, Icon, Badge, notification } from 'antd';
bert committed
6
import * as MenuAction  from '../../store/modules/menu/menu_action';
bert committed
7

bert committed
8
import { logout } from '../../store/modules/user/user_action';
bert committed
9 10 11

// import * as Util from '../../util';

bert committed
12 13
import logo from './logo.jpg'
import touxiang from './touxiang.jpg'
bert committed
14 15 16 17 18 19

const SubMenu = Menu.SubMenu

import styles from '../../views/App/index.less'

const defaultProps = {
bert committed
20 21
    leftMenu: [],
    currentIndex: 0
bert committed
22 23 24
}

const propTypes = {
bert committed
25 26
    leftMenu: PropTypes.array,
    currentIndex: PropTypes.number
bert committed
27 28 29
}

const contextTypes = {
bert committed
30 31
    router: PropTypes.object.isRequired,
    store: PropTypes.object.isRequired
bert committed
32 33 34
};

class Sidebar extends React.Component {
bert committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    constructor(props) {
        super(props)

        this.menuClickHandle = this.menuClickHandle.bind(this);
        this.logout = this.logout.bind(this);
    }

    componentDidMount() {
        this.props.MenuAction.getCaseMenu();
    }

    menuClickHandle(item) {
        this.props.updateNavPath(item.keyPath, item.key)
        console.log('menuClickHandle click ', item);
        this.setState({
            current: item.key,
        });
    }
    logout() {
        this.props.logout();
    }
    onClick(e) {
    }

    render() {
        const { leftMenu } = this.props
        console.log('this.props', this.props.dispatch);

        let openKey = []
        const menu = leftMenu.map((item) => {
            openKey.push('sub' + item.key)

            return (
                <Menu.Item style={{ zIndex: 10 }} key={item.key}>
                    <Link to={'' + item.key}>
                        <Badge dot={item.dot}>
                            <Icon type={item.icon} />
                        </Badge>
                        <span className={styles["nav-text"]}>{item.name}</span>

                        <span className={styles["nav-badge"]} style={{ float: 'right' }}>{ item.num }</span>
                    </Link>
                </Menu.Item>
            )
        });
        // <div className="nav-portrait-title">编辑显示昵称</div>
        // return (
        //     <aside className="ant-layout-sider">
        //         <div className="ant-layout-logo"><img src={logo} /><span className="nav-text">催费跟踪后台</span></div>
        //         <div className="ant-layout-portrait">
        //           <div className="nav-portrait"><img src={OPERATOR_INFO.avatarUrl + OPERATOR_INFO.operatorId} /></div>
        //           <div className="nav-portrait-name">{OPERATOR_INFO.operator}</div>
        //           <div className="nav-portrait-title" onClick={this.logout}>注销</div>
        //         </div>
        //         <Menu mode="inline" theme="dark" onClick={this.onClick.bind(this)} selectedKeys={defaultSelectedKeys}>
        //           { menu }
        //         </Menu>
        //       </aside>
        // )

        return (
            <aside className={styles["ant-layout-sider"]}>
                <div className={styles["ant-layout-logo"]}><img src={logo} /><span className={styles["nav-text"]}>xxxx后台</span></div>
                <div className={styles["ant-layout-portrait"]} style={{ marginBottom: '10px' }}>
                    <div className={styles["nav-portrait"]}><img src={touxiang} /></div>
                    <div className={styles["nav-portrait-name"]}>admin</div>
                </div>
                <Menu mode="inline" theme="dark" onClick={this.onClick.bind(this) }>
                    { menu }
                </Menu>
            </aside>
        )
    }
bert committed
108 109 110 111 112 113
}

Sidebar.propTypes = propTypes;
Sidebar.defaultProps = defaultProps;
Sidebar.contextTypes = contextTypes;
function mapStateToProps(state) {
bert committed
114 115 116 117 118 119
    console.log('state', state);
    return {
        leftMenuType: state.menu.leftMenuType,
        leftMenu: state.menu.leftMenu,
        currentIndex: state.menu.currentIndex,
    }
bert committed
120 121 122
}

function mapDispatchToProps(dispatch) {
bert committed
123 124 125 126
    return {
        logout: bindActionCreators(logout, dispatch),
        MenuAction: bindActionCreators(MenuAction, dispatch)
    }
bert committed
127 128 129
}

export default connect(mapStateToProps, mapDispatchToProps)(Sidebar)