index.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { Button, Form, FormInstance, Input, Radio, Select, Table } from "antd";
  2. import { useCallback, useMemo, useRef, useState } from "react";
  3. import { debounce } from "lodash";
  4. import { DageTableActions } from "@dage/pc-components";
  5. import { useNavigate } from "react-router-dom";
  6. const DEFAULT_PARAMS = {
  7. pageNum: 1,
  8. pageSize: 20,
  9. };
  10. export default function InformationPage() {
  11. const navigate = useNavigate();
  12. const formRef = useRef<FormInstance>(null);
  13. const [loading, setLoading] = useState(false);
  14. const [list, setList] = useState<[]>([]);
  15. const [params, setParams] = useState({
  16. ...DEFAULT_PARAMS,
  17. });
  18. const [total, setTotal] = useState(0);
  19. const COLUMNS = useMemo(() => {
  20. return [
  21. {
  22. title: "标题",
  23. dataIndex: "title",
  24. },
  25. {
  26. title: "问题数量",
  27. dataIndex: "nickName",
  28. },
  29. {
  30. title: "已收集份数",
  31. dataIndex: "date",
  32. },
  33. {
  34. title: "发布日期",
  35. dataIndex: "date",
  36. },
  37. {
  38. title: "展示状态",
  39. dataIndex: "date",
  40. },
  41. {
  42. title: "操作",
  43. render: (item: any) => {
  44. return <DageTableActions onEdit={() => {}} onDelete={() => {}} />;
  45. },
  46. },
  47. ];
  48. }, []);
  49. const handleReset = useCallback(() => {
  50. formRef.current?.resetFields();
  51. }, [formRef]);
  52. const debounceSearch = useMemo(
  53. () => debounce((changedVal: unknown, vals: any) => {}, 500),
  54. []
  55. );
  56. const paginationChange = useCallback(
  57. () => (pageNum: number, pageSize: number) => {
  58. setParams({ ...params, pageNum, pageSize });
  59. },
  60. [params]
  61. );
  62. return (
  63. <div className="information">
  64. <Form ref={formRef} layout="inline" onValuesChange={debounceSearch}>
  65. <Form.Item label="搜索项" name="stage">
  66. <Input
  67. placeholder="请输入标题,最多10字"
  68. maxLength={10}
  69. showCount
  70. allowClear
  71. />
  72. </Form.Item>
  73. <Form.Item>
  74. <Button
  75. type="primary"
  76. onClick={() => navigate("/questionnaire/create")}
  77. >
  78. 新增
  79. </Button>
  80. </Form.Item>
  81. <Form.Item>
  82. <Button onClick={handleReset}>重置</Button>
  83. </Form.Item>
  84. </Form>
  85. <Table
  86. loading={loading}
  87. className="page-table"
  88. dataSource={list}
  89. columns={COLUMNS}
  90. rowKey="id"
  91. pagination={{
  92. showQuickJumper: true,
  93. position: ["bottomCenter"],
  94. showSizeChanger: true,
  95. current: params.pageNum,
  96. pageSize: params.pageSize,
  97. total,
  98. onChange: paginationChange(),
  99. }}
  100. />
  101. </div>
  102. );
  103. }