List.js 1.83 KB
Newer Older
偏右's avatar
偏右 committed
1
import React, { Component } from 'react';
陈帅's avatar
陈帅 committed
2
import { routerRedux, Route, Switch } from 'dva/router';
偏右's avatar
偏右 committed
3 4 5
import { connect } from 'dva';
import { Input } from 'antd';
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
ddcat1115's avatar
ddcat1115 committed
6
import { getRoutes } from '../../utils/utils';
偏右's avatar
偏右 committed
7 8 9

@connect()
export default class SearchList extends Component {
jim's avatar
jim committed
10
  handleTabChange = key => {
偏右's avatar
偏右 committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24
    const { dispatch, match } = this.props;
    switch (key) {
      case 'articles':
        dispatch(routerRedux.push(`${match.url}/articles`));
        break;
      case 'applications':
        dispatch(routerRedux.push(`${match.url}/applications`));
        break;
      case 'projects':
        dispatch(routerRedux.push(`${match.url}/projects`));
        break;
      default:
        break;
    }
jim's avatar
jim committed
25
  };
偏右's avatar
偏右 committed
26 27

  render() {
jim's avatar
jim committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41
    const tabList = [
      {
        key: 'articles',
        tab: '文章',
      },
      {
        key: 'applications',
        tab: '应用',
      },
      {
        key: 'projects',
        tab: '项目',
      },
    ];
偏右's avatar
偏右 committed
42 43 44 45 46 47 48 49 50 51 52 53 54

    const mainSearch = (
      <div style={{ textAlign: 'center' }}>
        <Input.Search
          placeholder="请输入"
          enterButton="搜索"
          size="large"
          onSearch={this.handleFormSubmit}
          style={{ width: 522 }}
        />
      </div>
    );

afc163's avatar
afc163 committed
55
    const { match, routerData, location } = this.props;
ddcat1115's avatar
ddcat1115 committed
56
    const routes = getRoutes(match.path, routerData);
偏右's avatar
偏右 committed
57 58 59 60 61 62

    return (
      <PageHeaderLayout
        title="搜索列表"
        content={mainSearch}
        tabList={tabList}
ddcat1115's avatar
ddcat1115 committed
63
        tabActiveKey={location.pathname.replace(`${match.path}/`, '')}
偏右's avatar
偏右 committed
64 65 66
        onTabChange={this.handleTabChange}
      >
        <Switch>
jim's avatar
jim committed
67 68 69
          {routes.map(item => (
            <Route key={item.key} path={item.path} component={item.component} exact={item.exact} />
          ))}
偏右's avatar
偏右 committed
70 71 72 73 74
        </Switch>
      </PageHeaderLayout>
    );
  }
}