本文介紹Ant Tabs
一些 新增的功能和原理及思路介紹及更新日誌。html
Ant Tabs
基於 Ant Design Pro 2.0
基礎上修改的多標籤Tabs,修改此多標籤也是工做上的需求,原來後臺項目也是基於 Antd Design
來開發的,在 github上demo也不是不少,基本上也不符合本身的需求,因而就本着本身動手,豐衣足食
的思想,本身在Antd Design
的基礎上修改了部分文件。node
可是,中間也走了不少彎路,踩了不少坑,修改了多個版本最終才成了如今的需求,不過我以爲還能夠,僅供你們參考。react
主要修改文件 react-ant/src/layouts/BasicLayout.js
中引入Tabs
組件git
代碼解析github
constructor(props) {
super(props);
const {routes} = props.route,routeKey = '/home/home'; // routeKey 爲設置首頁設置 試試 '/dashboard/analysis' 或其餘key值
const tabLists = this.updateTree(routes);
let tabList=[];
tabLists.map((v) => {
if(v.key === routeKey){
if(tabList.length === 0){
v.closable = false
tabList.push(v);
}
}
});
this.state = ({
tabList:tabList,
tabListKey:[routeKey],
activeKey:routeKey,
routeKey
})
this.getPageTitle = memoizeOne(this.getPageTitle);
this.matchParamsPath = memoizeOne(this.matchParamsPath, isEqual);
}
複製代碼
updateTree = data => {
const treeData = data;
const treeList = [];
// 遞歸獲取樹列表
const getTreeList = data => {
data.forEach(node => {
if(!node.level){
treeList.push({ tab: node.name, key: node.path,locale:node.locale,closable:true,content:node.component });
}
if (node.routes && node.routes.length > 0) { //!node.hideChildrenInMenu &&
getTreeList(node.routes);
}
});
};
getTreeList(treeData);
return treeList;
};
複製代碼
routes
多維數據變成一維數據<SiderMenu
logo={logo}
theme={navTheme}
onCollapse={this.handleMenuCollapse}
menuData={menuData}
isMobile={isMobile}
{...this.props}
onHandlePage ={this.onHandlePage}
/>
複製代碼
{hidenAntTabs ?
(<Authorized authority={routerConfig} noMatch={<Exception403 />}> {children} </Authorized>) :
(this.state.tabList && this.state.tabList.length ? (
<Tabs // className={styles.tabs} activeKey={activeKey} onChange={this.onChange} tabBarExtraContent={operations} tabBarStyle={{background:'#fff'}} tabPosition="top" tabBarGutter={-1} hideAdd type="editable-card" onEdit={this.onEdit} > {this.state.tabList.map(item => ( <TabPane tab={item.tab} key={item.key} closable={item.closable}> <Authorized authority={routerConfig} noMatch={<Exception403 />}> {/*{item.content}*/} <Route key={item.key} path={item.path} component={item.content} exact={item.exact} /> </Authorized> </TabPane> ))} </Tabs> ) : null)} 複製代碼
onHandlePage ={this.onHandlePage}
Ant Tabs
的原理及功能Ant-Tabs
功能