index.js 4.4 KB

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