Commit a8caa500 authored by afc163's avatar afc163

Add activeTabKey for PageHeader

parent 577ded4b
...@@ -88,6 +88,7 @@ ReactDOM.render( ...@@ -88,6 +88,7 @@ ReactDOM.render(
extraContent={extra} extraContent={extra}
breadcrumbList={breadcrumbList} breadcrumbList={breadcrumbList}
tabList={tabList} tabList={tabList}
tabActiveKey="detail"
onTabChange={onTabChange} onTabChange={onTabChange}
/> />
</div> </div>
......
...@@ -34,6 +34,7 @@ ReactDOM.render( ...@@ -34,6 +34,7 @@ ReactDOM.render(
extraContent={<div className="extraContent">extraContent</div>} extraContent={<div className="extraContent">extraContent</div>}
breadcrumbList={breadcrumbList} breadcrumbList={breadcrumbList}
tabList={tabList} tabList={tabList}
tabActiveKey="1"
/> />
</div> </div>
, mountNode); , mountNode);
......
...@@ -9,6 +9,7 @@ export interface PageHeaderProps { ...@@ -9,6 +9,7 @@ export interface PageHeaderProps {
params?: any; params?: any;
breadcrumbList?: Array<{ title: React.ReactNode; href?: string }>; breadcrumbList?: Array<{ title: React.ReactNode; href?: string }>;
tabList?: Array<{ key: string; tab: React.ReactNode }>; tabList?: Array<{ key: string; tab: React.ReactNode }>;
tabActiveKey?: string;
onTabChange?: (key: string) => void; onTabChange?: (key: string) => void;
linkElement?: React.ReactNode; linkElement?: React.ReactNode;
} }
......
...@@ -60,6 +60,7 @@ export default class PageHeader extends PureComponent { ...@@ -60,6 +60,7 @@ export default class PageHeader extends PureComponent {
const { const {
title, logo, action, content, extraContent, title, logo, action, content, extraContent,
breadcrumbList, tabList, className, linkElement = 'a', breadcrumbList, tabList, className, linkElement = 'a',
activeTabKey,
} = this.props; } = this.props;
const clsString = classNames(styles.pageHeader, className); const clsString = classNames(styles.pageHeader, className);
let breadcrumb; let breadcrumb;
...@@ -120,7 +121,10 @@ export default class PageHeader extends PureComponent { ...@@ -120,7 +121,10 @@ export default class PageHeader extends PureComponent {
breadcrumb = null; breadcrumb = null;
} }
const tabDefaultValue = tabList && (tabList.filter(item => item.default)[0] || tabList[0]); let tabDefaultValue;
if (activeTabKey !== undefined && tabList) {
tabDefaultValue = tabList.filter(item => item.default)[0] || tabList[0];
}
return ( return (
<div className={clsString}> <div className={clsString}>
...@@ -144,6 +148,7 @@ export default class PageHeader extends PureComponent { ...@@ -144,6 +148,7 @@ export default class PageHeader extends PureComponent {
<Tabs <Tabs
className={styles.tabs} className={styles.tabs}
defaultActiveKey={(tabDefaultValue && tabDefaultValue.key)} defaultActiveKey={(tabDefaultValue && tabDefaultValue.key)}
activeKey={activeTabKey}
onChange={this.onChange} onChange={this.onChange}
> >
{ {
......
...@@ -22,6 +22,7 @@ order: 11 ...@@ -22,6 +22,7 @@ order: 11
| params | 面包屑相关属性,路由的参数 | object | - | | params | 面包屑相关属性,路由的参数 | object | - |
| breadcrumbList | 面包屑数据,配置了 `routes` `params` 时此属性无效 | array<{title: ReactNode, href?: string}> | - | | breadcrumbList | 面包屑数据,配置了 `routes` `params` 时此属性无效 | array<{title: ReactNode, href?: string}> | - |
| tabList | tab 标题列表 | array<{key: string, tab: ReactNode}> | - | | tabList | tab 标题列表 | array<{key: string, tab: ReactNode}> | - |
| tabActiveKey | 当前高亮的 tab 项 | string | - |
| onTabChange | 切换面板的回调 | (key) => void | - | | onTabChange | 切换面板的回调 | (key) => void | - |
| linkElement | 定义链接的元素,默认为 `a`,可传入 react-router 的 Link | string\|ReactElement | - | | linkElement | 定义链接的元素,默认为 `a`,可传入 react-router 的 Link | string\|ReactElement | - |
......
...@@ -48,7 +48,7 @@ export default class SearchList extends Component { ...@@ -48,7 +48,7 @@ export default class SearchList extends Component {
</div> </div>
); );
const { match, routerData } = this.props; const { match, routerData, location } = this.props;
const routes = getRoutes(match.path, routerData); const routes = getRoutes(match.path, routerData);
return ( return (
...@@ -56,6 +56,7 @@ export default class SearchList extends Component { ...@@ -56,6 +56,7 @@ export default class SearchList extends Component {
title="搜索列表" title="搜索列表"
content={mainSearch} content={mainSearch}
tabList={tabList} tabList={tabList}
activeTabKey={location.pathname.replace(`${match.path}/`, '')}
onTabChange={this.handleTabChange} onTabChange={this.handleTabChange}
> >
<Switch> <Switch>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment