index.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { DageTableActions } from "@dage/pc-components";
  2. import { Button, Table } from "antd";
  3. import { useCallback, useMemo, useState } from "react";
  4. import { useNavigate } from "react-router-dom";
  5. const DEFAULT_PARAMS = {
  6. pageNum: 1,
  7. pageSize: 20,
  8. };
  9. export default function BannerPage() {
  10. const navigate = useNavigate();
  11. const [list, setList] = useState<[]>([]);
  12. const [total, setTotal] = useState(0);
  13. const [loading, setLoading] = useState(false);
  14. const [params, setParams] = useState({
  15. ...DEFAULT_PARAMS,
  16. });
  17. const paginationChange = useCallback(
  18. () => (pageNum: number, pageSize: number) => {
  19. setParams({ ...params, pageNum, pageSize });
  20. },
  21. [params]
  22. );
  23. const COLUMNS = useMemo(() => {
  24. return [
  25. {
  26. title: "海报",
  27. dataIndex: "userName",
  28. },
  29. {
  30. title: "发布日期",
  31. dataIndex: "nickName",
  32. },
  33. {
  34. title: "操作",
  35. render: (item: any) => {
  36. return <DageTableActions onEdit={() => {}} onDelete={() => {}} />;
  37. },
  38. },
  39. ];
  40. }, []);
  41. return (
  42. <div>
  43. <div style={{ textAlign: "right" }}>
  44. <Button type="primary" onClick={() => navigate("/banner/create")}>
  45. 新增
  46. </Button>
  47. </div>
  48. <Table
  49. loading={loading}
  50. className="page-table"
  51. dataSource={list}
  52. columns={COLUMNS}
  53. rowKey="id"
  54. pagination={{
  55. showQuickJumper: true,
  56. position: ["bottomCenter"],
  57. showSizeChanger: true,
  58. current: params.pageNum,
  59. pageSize: params.pageSize,
  60. total,
  61. onChange: paginationChange(),
  62. }}
  63. />
  64. </div>
  65. );
  66. }