index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import React, { useState, useEffect, useRef } from 'react';
  2. import { Form, Input, Button, Table, Pagination, Row, Col, Tooltip, DatePicker } from 'antd';
  3. import '@common/common.less';
  4. import apiObj from '@api/index';
  5. import moment from "moment";
  6. import "moment/locale/zh-cn"
  7. const { post, api, xPost } = apiObj;
  8. const { RangePicker } = DatePicker;
  9. function OperationLog() {
  10. useEffect(() => {
  11. getOperationLog();
  12. }, []);
  13. const [logList, setLogList] = useState([]);
  14. const [total, setTotal] = useState(0);
  15. const [size, setSize] = useState(15);
  16. const [current, setCurrent] = useState(1);
  17. const [params, setParams] = useState({
  18. pages: 1,
  19. current: 1,
  20. size: 15
  21. });
  22. const [form] = Form.useForm();
  23. let list = []
  24. let data = {
  25. pages: 1,
  26. current: 1,
  27. size: size
  28. }
  29. //表格数据
  30. function getOperationLog(param) {
  31. post(api.getOperationLog, param || params).then((res) => {
  32. if (res.data.code === 200) {
  33. const data = res.data.data;
  34. setLogList(data.records);
  35. setTotal(data.total)
  36. }
  37. })
  38. }
  39. function onSizeChange(current, pageSize) {
  40. params.current = current
  41. params.size = pageSize
  42. setSize(pageSize)
  43. setCurrent(current)
  44. setParams(params)
  45. getOperationLog()
  46. }
  47. function changePage(page, pageSize) {
  48. params.current = page
  49. params.size = pageSize
  50. setParams(params)
  51. setCurrent(page)
  52. getOperationLog()
  53. }
  54. const onFinish = (value) => {
  55. if (value.time){
  56. value.startDate = moment(value.time[0]).format('YYYY-MM-DD')
  57. value.endDate = moment(value.time[1]).format('YYYY-MM-DD')
  58. }
  59. const param = {
  60. ...data,
  61. ...value,
  62. }
  63. setCurrent(1)
  64. setParams(param)
  65. getOperationLog(param);
  66. };
  67. const onReset = () => {
  68. setCurrent(1)
  69. setParams(data)
  70. form.resetFields();
  71. getOperationLog(data);
  72. };
  73. const columns = [
  74. { title: '编号', dataIndex: 'operationId', key: 'index' },
  75. { title: '操作人', dataIndex: 'operationName', key: 'index' },
  76. { title: '操作日期', dataIndex: 'operationDate', key: 'index' },
  77. { title: 'IP地址', dataIndex: 'operationIp', key: 'index' },
  78. {
  79. title: '操作记录', dataIndex: 'status', key: 'status', render: (text, record) => (
  80. <Tooltip placement="top" title={record.jsonResult}>
  81. <span className="record">{record.jsonResult}</span>
  82. </Tooltip>
  83. )
  84. },
  85. ]
  86. return (
  87. <div className="wrapper">
  88. <div className="filter-box">
  89. <Form
  90. form={form}
  91. name="normal_login"
  92. onFinish={onFinish}
  93. initialValues={{ status: '' }}
  94. >
  95. <Row gutter={24}>
  96. <Col span={5} key={0}>
  97. <Form.Item label="操作人" name="operationName">
  98. <Input placeholder="用户名" autoComplete='off'/>
  99. </Form.Item>
  100. </Col>
  101. <Col span={5} key={1}>
  102. <Form.Item name="time">
  103. <RangePicker
  104. placeholder={['开始时间', '结束时间']}
  105. />
  106. </Form.Item>
  107. </Col>
  108. <Col span={6} key={3}>
  109. <Form.Item>
  110. <Button type="primary" htmlType="submit">
  111. 查询
  112. </Button>
  113. <Button onClick={onReset}>
  114. 重置
  115. </Button>
  116. </Form.Item>
  117. </Col>
  118. </Row>
  119. </Form>
  120. </div>
  121. <div className="table">
  122. <div className="table-header">
  123. <h2 className="table-title">操作日志</h2>
  124. </div>
  125. <Table
  126. columns={columns}
  127. scroll={{ y: 'calc(100vh - 320px)' }}
  128. dataSource={logList}
  129. rowKey={record => record.id}
  130. pagination={{
  131. pageSize: size,
  132. size: 'small',
  133. current: current,
  134. showSizeChanger: true,
  135. pageSizeOptions: ['15', '30', '60', '120'],
  136. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  137. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  138. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  139. total: total
  140. }} />
  141. </div>
  142. </div >
  143. )
  144. }
  145. export default OperationLog;