TopSearch.tsx 3.66 KB
Newer Older
陈帅's avatar
陈帅 committed
1
import React from 'react';
陈帅's avatar
陈帅 committed
2
import { Row, Col, Table, Tooltip, Card, Icon } from 'antd';
陈帅's avatar
陈帅 committed
3
import { FormattedMessage } from 'umi-plugin-react/locale';
陈帅's avatar
陈帅 committed
4 5 6
import Charts from './Charts';
import Trend from './Trend';
import NumberInfo from './NumberInfo';
陈帅's avatar
陈帅 committed
7
import numeral from 'numeral';
8
import styles from '../style.less';
陈帅's avatar
陈帅 committed
9
import { ISearchData, IVisitData2 } from '../data';
10 11

const { MiniArea } = Charts;
陈帅's avatar
陈帅 committed
12 13 14

const columns = [
  {
15
    title: <FormattedMessage id="BLOCK_NAME.table.rank" defaultMessage="Rank" />,
陈帅's avatar
陈帅 committed
16 17 18 19 20
    dataIndex: 'index',
    key: 'index',
  },
  {
    title: (
21
      <FormattedMessage id="BLOCK_NAME.table.search-keyword" defaultMessage="Search keyword" />
陈帅's avatar
陈帅 committed
22 23 24
    ),
    dataIndex: 'keyword',
    key: 'keyword',
陈帅's avatar
陈帅 committed
25
    render: (text: React.ReactNode) => <a href="/">{text}</a>,
陈帅's avatar
陈帅 committed
26 27
  },
  {
28
    title: <FormattedMessage id="BLOCK_NAME.table.users" defaultMessage="Users" />,
陈帅's avatar
陈帅 committed
29 30
    dataIndex: 'count',
    key: 'count',
陈帅's avatar
陈帅 committed
31
    sorter: (a: { count: number }, b: { count: number }) => a.count - b.count,
陈帅's avatar
陈帅 committed
32 33 34
    className: styles.alignRight,
  },
  {
35
    title: <FormattedMessage id="BLOCK_NAME.table.weekly-range" defaultMessage="Weekly Range" />,
陈帅's avatar
陈帅 committed
36 37
    dataIndex: 'range',
    key: 'range',
陈帅's avatar
陈帅 committed
38 39
    sorter: (a: { range: number }, b: { range: number }) => a.range - b.range,
    render: (text: React.ReactNode, record: { status: number }) => (
陈帅's avatar
陈帅 committed
40 41 42 43 44 45 46
      <Trend flag={record.status === 1 ? 'down' : 'up'}>
        <span style={{ marginRight: 4 }}>{text}%</span>
      </Trend>
    ),
  },
];

陈帅's avatar
陈帅 committed
47 48 49 50 51 52 53 54 55 56 57
const TopSearch = ({
  loading,
  visitData2,
  searchData,
  dropdownGroup,
}: {
  loading: boolean;
  visitData2: IVisitData2[];
  dropdownGroup: React.ReactNode;
  searchData: ISearchData[];
}) => (
陈帅's avatar
陈帅 committed
58 59 60 61
  <Card
    loading={loading}
    bordered={false}
    title={
xiaohuoni's avatar
xiaohuoni committed
62 63 64 65
      <FormattedMessage
        id="BLOCK_NAME.analysis.online-top-search"
        defaultMessage="Online Top Search"
      />
陈帅's avatar
陈帅 committed
66 67 68 69 70 71 72 73 74
    }
    extra={dropdownGroup}
    style={{ marginTop: 24 }}
  >
    <Row gutter={68}>
      <Col sm={12} xs={24} style={{ marginBottom: 24 }}>
        <NumberInfo
          subTitle={
            <span>
xiaohuoni's avatar
xiaohuoni committed
75 76 77 78
              <FormattedMessage
                id="BLOCK_NAME.analysis.search-users"
                defaultMessage="search users"
              />
陈帅's avatar
陈帅 committed
79
              <Tooltip
xiaohuoni's avatar
xiaohuoni committed
80 81 82
                title={
                  <FormattedMessage id="BLOCK_NAME.analysis.introduce" defaultMessage="introduce" />
                }
陈帅's avatar
陈帅 committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
              >
                <Icon style={{ marginLeft: 8 }} type="info-circle-o" />
              </Tooltip>
            </span>
          }
          gap={8}
          total={numeral(12321).format('0,0')}
          status="up"
          subTotal={17.1}
        />
        <MiniArea line height={45} data={visitData2} />
      </Col>
      <Col sm={12} xs={24} style={{ marginBottom: 24 }}>
        <NumberInfo
          subTitle={
            <span>
              <FormattedMessage
100
                id="BLOCK_NAME.analysis.per-capita-search"
陈帅's avatar
陈帅 committed
101 102 103
                defaultMessage="Per Capita Search"
              />
              <Tooltip
xiaohuoni's avatar
xiaohuoni committed
104 105 106
                title={
                  <FormattedMessage id="BLOCK_NAME.analysis.introduce" defaultMessage="introduce" />
                }
陈帅's avatar
陈帅 committed
107 108 109 110 111 112 113 114 115 116 117 118 119
              >
                <Icon style={{ marginLeft: 8 }} type="info-circle-o" />
              </Tooltip>
            </span>
          }
          total={2.7}
          status="down"
          subTotal={26.2}
          gap={8}
        />
        <MiniArea line height={45} data={visitData2} />
      </Col>
    </Row>
陈帅's avatar
陈帅 committed
120
    <Table<any>
陈帅's avatar
陈帅 committed
121 122 123 124 125 126 127 128 129 130
      rowKey={record => record.index}
      size="small"
      columns={columns}
      dataSource={searchData}
      pagination={{
        style: { marginBottom: 0 },
        pageSize: 5,
      }}
    />
  </Card>
陈帅's avatar
陈帅 committed
131
);
陈帅's avatar
陈帅 committed
132 133

export default TopSearch;