index.tsx 3.8 KB

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