chengmw
9 days ago 96f4f1ea3a088d315a60c65bae50b5074441bf4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import React, { useEffect, useState } from 'react';
import { Typography, Row, Col, Card, message } from 'antd';
import CaseSearchForm from '../components/case/CaseSearchForm';
import CaseList from '../components/case/CaseList';
import PaginationBar from '../components/common/PaginationBar';
import { fetchCaseList } from '../services/caseService';
 
const { Title } = Typography;
 
const CaseSearchPage = () => {
  const [loading, setLoading] = useState(false);
  const [queryParams, setQueryParams] = useState({
    keyword: '',
    page: 1,
    pageSize: 10,
  });
  const [data, setData] = useState({
    list: [],
    pageInfo: { page: 1, pageSize: 10, total: 0 },
  });
 
  const loadData = async (params = queryParams) => {
    setLoading(true);
    try {
      const res = await fetchCaseList(params);
      setData(res);
    } catch (e) {
      console.error(e);
      message.error('加载案例列表失败');
    } finally {
      setLoading(false);
    }
  };
 
  useEffect(() => {
    loadData();
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
 
  const handleSearch = (values) => {
    const newParams = {
      ...queryParams,
      ...values,
      page: 1,
    };
    setQueryParams(newParams);
    loadData(newParams);
  };
 
  const handlePageChange = (page, pageSize) => {
    const newParams = { ...queryParams, page, pageSize };
    setQueryParams(newParams);
    loadData(newParams);
  };
 
  return (
    <div>
      <Title level={3}>典型案例搜索</Title>
      <Row gutter={16}>
        <Col span={24}>
          <Card style={{ marginBottom: 16 }} title="查询条件">
            <CaseSearchForm onSearch={handleSearch} loading={loading} />
          </Card>
        </Col>
      </Row>
 
      <Row gutter={16}>
        <Col span={24}>
          <Card
            title={`查询结果(共 ${data.pageInfo.total} 条)`}
            loading={loading}
          >
            <CaseList list={data.list} />
            <PaginationBar
              page={data.pageInfo.page}
              pageSize={data.pageInfo.pageSize}
              total={data.pageInfo.total}
              onChange={handlePageChange}
            />
          </Card>
        </Col>
      </Row>
    </div>
  );
};
 
export default CaseSearchPage;