动态菜单和动态路由的 antd pro

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import React, { Component } from 'react';
  2. import { routerRedux, Route, Switch } from 'dva/router';
  3. import { connect } from 'dva';
  4. import { Input } from 'antd';
  5. import PageHeaderLayout from '../../layouts/PageHeaderLayout';
  6. import { getRoutes } from '../../utils/utils';
  7. @connect()
  8. export default class SearchList extends Component {
  9. handleTabChange = key => {
  10. const { dispatch, match } = this.props;
  11. switch (key) {
  12. case 'articles':
  13. dispatch(routerRedux.push(`${match.url}/articles`));
  14. break;
  15. case 'applications':
  16. dispatch(routerRedux.push(`${match.url}/applications`));
  17. break;
  18. case 'projects':
  19. dispatch(routerRedux.push(`${match.url}/projects`));
  20. break;
  21. default:
  22. break;
  23. }
  24. };
  25. render() {
  26. const tabList = [
  27. {
  28. key: 'articles',
  29. tab: '文章',
  30. },
  31. {
  32. key: 'applications',
  33. tab: '应用',
  34. },
  35. {
  36. key: 'projects',
  37. tab: '项目',
  38. },
  39. ];
  40. const mainSearch = (
  41. <div style={{ textAlign: 'center' }}>
  42. <Input.Search
  43. placeholder="请输入"
  44. enterButton="搜索"
  45. size="large"
  46. onSearch={this.handleFormSubmit}
  47. style={{ width: 522 }}
  48. />
  49. </div>
  50. );
  51. const { match, routerData, location } = this.props;
  52. const routes = getRoutes(match.path, routerData);
  53. return (
  54. <PageHeaderLayout
  55. title="搜索列表"
  56. content={mainSearch}
  57. tabList={tabList}
  58. tabActiveKey={location.pathname.replace(`${match.path}/`, '')}
  59. onTabChange={this.handleTabChange}
  60. >
  61. <Switch>
  62. {routes.map(item => (
  63. <Route key={item.key} path={item.path} component={item.component} exact={item.exact} />
  64. ))}
  65. </Switch>
  66. </PageHeaderLayout>
  67. );
  68. }
  69. }