import * as React from 'react' import CommonTab from '&/components/common/commonTab'; import { taker, getApiUrl, getToUserId } from '&/helper'; interface Props { changeContent: Function, channelData: any, setDefatuleChannel: Function } interface State { hidden: boolean, activeCode: string, tabs: PropsItem[], isFetching: boolean; tabEleW: number } interface PropsItem { idx: string, //string,标签的唯一标识名称 eventKey: number, //number, 标签的id title: string, //string,标签内容 active: boolean, //boolean } export default class HeaderTab extends React.Component{ activeKey: number; constructor(props: Props) { super(props); this.state = { hidden: false, activeCode: '', tabs: [], isFetching: true, tabEleW: 0 } } componentDidMount() { this.getData(this.props); } componentWillReceiveProps(nextProps: Props) { this.getData(nextProps) } getData = async (props: Props) => { const { channelData } = props const ChannelUrl = getApiUrl(`proxy/GetUPaaSCoreGateway/TalentHonor/GetAppItems?code=Tabs&toUserId=${getToUserId()}`); const ChannelRes = await taker(ChannelUrl); let newChannelData: any[] = []; if (ChannelRes.Code === 200 && ChannelRes.OperationObject) { const channelResData = ChannelRes.OperationObject.map((item: any) => { return { name: item.Title, code: item.IsIframe ? `${item.Code}__ISIFRAME` : item.Code, isSystem: true, inCheck: true, } }) if (channelData !== undefined) { channelData.forEach((item: any) => { if (!item.isSystem || channelResData.find((i: any) => { return i.code == item.code })) newChannelData.push(item); }) } channelResData.forEach((item: any) => { if (!newChannelData.find((i: any) => { return i.code == item.code })) newChannelData.push(item) }) } if (channelData == undefined) { const { setDefatuleChannel } = this.props; setDefatuleChannel(newChannelData[0].code) } this.setState({ isFetching: false, tabs: this.getTabItems(newChannelData), tabEleW: this.tabEle.clientWidth }) } getTabItems = (ChannelData: any) => { const tabs: any[] = []; const { activeCode } = this.state; let newActiveCode = activeCode; ChannelData.forEach((item: any, index: number) => { if (item.inCheck) { if (!activeCode && index == 0) newActiveCode = item.code; tabs.push({ idx: item.code, title: item.name, active: item.code == newActiveCode ? true : false }) } }) if (newActiveCode != activeCode) { this.setState({ activeCode: newActiveCode }) } return tabs; } handelClick = (idx: any, event: any) => { let { tabs, activeCode } = this.state; let newTabItems: any = []; tabs.forEach((i, k) => { if (i.idx === idx) { activeCode = i.idx } newTabItems.push({ active: i.idx === idx, title: i.title, idx: i.idx }) }); this.setState({ tabs: newTabItems, activeCode }) this.props.changeContent(activeCode); } tabEle: any render() { const { isFetching, tabEleW } = this.state; return
this.tabEle = node}> { isFetching ? null : }
} }