index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { logApi } from "@/api";
  2. import { GetLogListParams } from "@/types";
  3. import { Button, DatePicker, Form, FormInstance, Input, Table } from "antd";
  4. import { debounce } from "lodash";
  5. import { useCallback, useEffect, useMemo, useRef, useState } from "react";
  6. import { formatDate } from "@dage/utils";
  7. const DEFAULT_PARAMS: GetLogListParams = {
  8. pageNum: 1,
  9. pageSize: 20,
  10. startTime: "",
  11. endTime: "",
  12. };
  13. const { RangePicker } = DatePicker;
  14. export default function IndustrialMeta() {
  15. const formRef = useRef<FormInstance>(null);
  16. const [list, setList] = useState([]);
  17. const [total, setTotal] = useState(0);
  18. const [loading, setLoading] = useState(false);
  19. const [params, setParams] = useState<GetLogListParams>({
  20. ...DEFAULT_PARAMS,
  21. });
  22. const getList = useCallback(async () => {
  23. setLoading(true);
  24. try {
  25. const data = await logApi.getList(params);
  26. setList(data.records);
  27. setTotal(data.total);
  28. } finally {
  29. setLoading(false);
  30. }
  31. }, [params]);
  32. useEffect(() => {
  33. getList();
  34. }, [getList, params]);
  35. const debounceSearch = useMemo(
  36. () =>
  37. debounce(
  38. (changedVal: unknown, vals: GetLogListParams & { date: string[] }) => {
  39. const { date, ...rest } = vals;
  40. let startTime = "";
  41. let endTime = "";
  42. if (date && date[0] && date[1]) {
  43. startTime = formatDate(date[0]) + " 00:00:00";
  44. endTime = formatDate(date[1]) + " 23:59:59";
  45. }
  46. setParams({ ...params, ...rest, startTime, endTime });
  47. },
  48. 500
  49. ),
  50. [params]
  51. );
  52. const paginationChange = useCallback(
  53. () => (pageNum: number, pageSize: number) => {
  54. setParams({ ...params, pageNum, pageSize });
  55. },
  56. [params]
  57. );
  58. const handleReset = useCallback(() => {
  59. setParams({ ...DEFAULT_PARAMS });
  60. formRef.current?.resetFields();
  61. }, [formRef]);
  62. const COLUMNS = useMemo(() => {
  63. return [
  64. {
  65. title: "序号",
  66. render: (text: any, record: any, index: any) =>
  67. index + 1 + (params.pageNum - 1) * params.pageSize,
  68. },
  69. {
  70. title: "操作者",
  71. dataIndex: "userName",
  72. },
  73. {
  74. title: "操作日期",
  75. dataIndex: "createTime",
  76. },
  77. {
  78. title: "IP记录",
  79. dataIndex: "ip",
  80. },
  81. {
  82. title: "操作模块",
  83. dataIndex: "type",
  84. },
  85. {
  86. title: "操作事件",
  87. dataIndex: "description",
  88. },
  89. ];
  90. }, [params]);
  91. return (
  92. <div className="log">
  93. <Form ref={formRef} layout="inline" onValuesChange={debounceSearch}>
  94. <Form.Item label="账号" name="searchKey">
  95. <Input
  96. className="w220"
  97. placeholder="请输入关键字"
  98. maxLength={30}
  99. showCount
  100. allowClear
  101. />
  102. </Form.Item>
  103. <Form.Item label="操作日期" name="date">
  104. <RangePicker />
  105. </Form.Item>
  106. <Form.Item>
  107. <Button onClick={handleReset}>重置</Button>
  108. </Form.Item>
  109. </Form>
  110. <Table
  111. loading={loading}
  112. className="page-table"
  113. dataSource={list}
  114. columns={COLUMNS}
  115. rowKey="id"
  116. pagination={{
  117. showQuickJumper: true,
  118. position: ["bottomCenter"],
  119. showSizeChanger: true,
  120. current: params.pageNum,
  121. pageSize: params.pageSize,
  122. total,
  123. onChange: paginationChange(),
  124. }}
  125. />
  126. </div>
  127. );
  128. }