index.tsx 4.6 KB
Newer Older
Z
zengqiao 已提交
1
import React, { useEffect, useState } from 'react';
2 3
import { Button, Form, Input, Select, ProTable, DatePicker, Utils, Tooltip, Divider } from 'knowdesign';
import { IconFont } from '@knowdesign/icons';
G
GraceWalk 已提交
4 5
import api from '@src/api';
import { defaultPagination } from '@src/constants/common';
Z
zengqiao 已提交
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
import TypicalListCard from '../../components/TypicalListCard';
import './index.less';
import moment from 'moment';

const { request } = Utils;
const { RangePicker } = DatePicker;

export default () => {
  const [loading, setLoading] = useState(true);
  const [configGroupList, setConfigGroupList] = useState<{ label: string; value: string }[]>([]);
  const [data, setData] = useState([]);
  const [pagination, setPagination] = useState<any>(defaultPagination);
  const [form] = Form.useForm();

  const columns = [
    {
      title: '模块',
      dataIndex: 'targetType',
      lineClampOne: true,
    },
    {
      title: '操作对象',
      dataIndex: 'target',
      width: 350,
      lineClampOne: true,
    },
    {
      title: '行为',
      dataIndex: 'operateType',
      width: 80,
      lineClampOne: true,
    },
    {
      title: '操作内容',
      dataIndex: 'detail',
      width: 350,
      lineClampOne: true,
Z
zengqiao 已提交
43 44 45 46 47 48 49
      render(content) {
        return (
          <Tooltip placement="bottomLeft" title={content}>
            {content}
          </Tooltip>
        );
      },
Z
zengqiao 已提交
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    },
    {
      title: '操作时间',
      dataIndex: 'updateTime',
      width: 200,
      render: (date) => moment(date).format('YYYY-MM-DD HH:mm:ss'),
    },
    {
      title: '操作人',
      dataIndex: 'operator',
    },
  ];

  const getData = (query = {}) => {
    const formData = form.getFieldsValue();
    if (formData.time) {
      formData.startTime = moment(formData.time[0]).valueOf();
      formData.endTime = moment(formData.time[1]).valueOf();
    }
    delete formData.time;
    const data = {
      page: pagination.current,
      size: pagination.pageSize,
      ...formData,
      ...query,
    };

    setLoading(true);
    request(api.oplogList, {
      method: 'POST',
      data,
    }).then(
      (res: any) => {
        const { pageNo, pageSize, pages, total } = res.pagination;
        if (pageNo > pages && pages !== 0) {
          getData({ page: pages });
          return false;
        }

        setPagination({
          ...pagination,
          current: pageNo,
          pageSize,
          total,
        });
        setData(res.bizData);
        setLoading(false);
      },
      () => setLoading(false)
    );
  };

  const onTableChange = (curPagination) => {
    getData({ page: curPagination.current, size: curPagination.pageSize });
  };

  useEffect(() => {
    // 获取模块列表
    request(api.oplogTypeList).then((res: string[]) => {
      const options = res.map((item) => ({
        label: item,
        value: item,
      }));
      setConfigGroupList(options);
    });
    // 获取数据
    getData();
  }, []);

  return (
    <>
      <TypicalListCard title="操作记录">
        <div className="operate-bar">
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
          <div className="left">
            <div className="refresh-icon" onClick={() => getData()}>
              <IconFont className="icon" type="icon-shuaxin1" />
            </div>
            <Divider type="vertical" style={{ height: 20, top: 0 }} />

            <Form form={form} layout="inline" onFinish={() => getData({ page: 1 })}>
              <Form.Item name="targetType">
                <Select placeholder="请选择模块" options={configGroupList} style={{ width: 160 }} />
              </Form.Item>
              <Form.Item name="target">
                <Input placeholder="请输入操作对象" />
              </Form.Item>
              <Form.Item name="detail">
                <Input placeholder="请输入操作内容" />
              </Form.Item>
              <Form.Item name="time">
                <RangePicker showTime />
              </Form.Item>
              <Form.Item>
                <Button type="primary" ghost htmlType="submit">
                  查询
                </Button>
              </Form.Item>
            </Form>
          </div>
Z
zengqiao 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
        </div>

        <ProTable
          tableProps={{
            showHeader: false,
            loading,
            rowKey: 'id',
            dataSource: data,
            paginationProps: pagination,
            columns,
            lineFillColor: true,
            attrs: {
              onChange: onTableChange,
              scroll: {
                scrollToFirstRowOnChange: true,
                x: true,
                y: 'calc(100vh - 270px)',
              },
            },
          }}
        />
      </TypicalListCard>
    </>
  );
};