import React, { Component } from 'react'; import { Tabs, Radio } from 'antd'; import './index.less'; class TabLayout extends Component { constructor(props) { super(props); const key = props.itemList && props.itemList.length > 0 ? props.itemList[0].key : ''; const defaultActiveKey = props.defaultActiveKey || key; this.state = { defaultActiveKey }; if (defaultActiveKey !== props.defaultActiveKey) this.onClick(defaultActiveKey); } onClick(tab) { if (this.props.onChange) this.props.onChange(tab); } getItem(item) { const { button = false } = this.props; return button ? ( {item.name} ) : ( ); } render() { const { button = false, itemList = [] } = this.props; const { defaultActiveKey } = this.state; return (
{button ? ( { this.onClick(e.target.value); }} buttonStyle="solid" > {itemList.map(item => { return this.getItem(item); })} ) : ( this.onClick(key)}> {itemList.map(item => { return this.getItem(item); })} )}
); } } export default TabLayout;