LoginTab.js 917 Bytes
Newer Older
ddcat1115's avatar
ddcat1115 committed
1 2
import React, { Component } from 'react';
import { Tabs } from 'antd';
jim's avatar
jim committed
3
import LoginContext from './loginContext';
ddcat1115's avatar
ddcat1115 committed
4 5 6 7 8

const { TabPane } = Tabs;

const generateId = (() => {
  let i = 0;
afc163's avatar
afc163 committed
9
  return (prefix = '') => {
ddcat1115's avatar
ddcat1115 committed
10 11 12 13 14
    i += 1;
    return `${prefix}${i}`;
  };
})();

jim's avatar
jim committed
15
class LoginTab extends Component {
ddcat1115's avatar
ddcat1115 committed
16 17 18 19
  constructor(props) {
    super(props);
    this.uniqueId = generateId('login-tab-');
  }
陈帅's avatar
陈帅 committed
20

jim's avatar
jim committed
21
  componentDidMount() {
陈帅's avatar
陈帅 committed
22 23
    const { tabUtil } = this.props;
    tabUtil.addTab(this.uniqueId);
ddcat1115's avatar
ddcat1115 committed
24
  }
陈帅's avatar
陈帅 committed
25

ddcat1115's avatar
ddcat1115 committed
26
  render() {
陈帅's avatar
陈帅 committed
27 28
    const { children } = this.props;
    return <TabPane {...this.props}>{children}</TabPane>;
ddcat1115's avatar
ddcat1115 committed
29 30
  }
}
jim's avatar
jim committed
31 32 33 34

const warpContext = props => {
  return (
    <LoginContext.Consumer>
35 36 37
      {value => {
        return <LoginTab tabUtil={value.tabUtil} {...props} />;
      }}
jim's avatar
jim committed
38 39 40
    </LoginContext.Consumer>
  );
};
41 42 43
// 标志位 用来判断是不是自定义组件
warpContext.typeName = 'LoginTab';

jim's avatar
jim committed
44
export default warpContext;