index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import React, { useState, useEffect, useRef } from 'react';
  2. import { Form, Input, Button, Table, Select, Pagination, Space, Menu, Dropdown, Modal, Breadcrumb, message, Row, Col, Tooltip } from 'antd';
  3. import '@common/common.less';
  4. import { useSelector } from 'react-redux'
  5. import apiObj from '@api/index';
  6. const { post, api, xPost } = apiObj;
  7. const { Option } = Select;
  8. function ExceptionLog() {
  9. useEffect(() => {
  10. getAbnormalLog();
  11. }, []);
  12. const [logList, setLogList] = useState([]);
  13. const [total, setTotal] = useState(0);
  14. const [size, setSize] = useState(15);
  15. const [msvisible, setMsvisible] = useState(false);
  16. const [tipText, setTipText] = useState('');
  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 getAbnormalLog(param) {
  32. post(api.getAbnormalLog, 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. getAbnormalLog()
  47. }
  48. function changePage(page, pageSize) {
  49. params.current = page
  50. params.size = pageSize
  51. setCurrent(page)
  52. setParams(params)
  53. getAbnormalLog()
  54. }
  55. function showModal(operationErrorInfo) {
  56. setMsvisible(true)
  57. setTipText(operationErrorInfo)
  58. }
  59. function handleOk() {
  60. setMsvisible(false)
  61. }
  62. function handleCancel() {
  63. setMsvisible(false)
  64. }
  65. const onFinish = (value) => {
  66. const param = {
  67. ...data,
  68. ...value
  69. }
  70. setCurrent(1)
  71. setParams(param)
  72. getAbnormalLog(param);
  73. };
  74. const onReset = () => {
  75. setCurrent(1)
  76. setParams(data)
  77. form.resetFields();
  78. getAbnormalLog(data);
  79. };
  80. const columns = [
  81. { title: '编号', dataIndex: 'operationId', key: 'index' },
  82. { title: '请求URL', dataIndex: 'operationUrl', key: 'index' },
  83. { title: '请求方式', dataIndex: 'operationWay', key: 'index' },
  84. {
  85. title: '请求参数', key: 'index', render: (text, record) => (
  86. <Tooltip placement="top" title={record.operationParam}>
  87. <span className="record">{record.operationParam}</span>
  88. </Tooltip>
  89. )
  90. },
  91. { title: 'IP地址', dataIndex: 'operationIp', key: 'index' },
  92. { title: '用户代理', dataIndex: 'operationName', key: 'index' },
  93. { title: '创建时间', dataIndex: 'gmtCreate', key: 'index' },
  94. {
  95. title: '操作', dataIndex: 'key', render: (text, record) => (
  96. <Space size="middle">
  97. <a onClick={e => showModal(record.operationErrorInfo)}>查看</a>
  98. </Space>
  99. )
  100. }
  101. ]
  102. return (
  103. <div className="wrapper">
  104. <div className="filter-box">
  105. <Form
  106. form={form}
  107. name="normal_login"
  108. onFinish={onFinish}
  109. initialValues={{ status: '' }}
  110. >
  111. <Row gutter={24}>
  112. <Col span={5} key={0}>
  113. <Form.Item label="请求方式" name="operationWay">
  114. <Input placeholder="请求方式" autoComplete='off'/>
  115. </Form.Item>
  116. </Col>
  117. <Col span={5} key={1}>
  118. <Form.Item label="IP地址" name="operationIp">
  119. <Input placeholder="IP地址" autoComplete='off'/>
  120. </Form.Item>
  121. </Col>
  122. <Col span={6} key={3}>
  123. <Form.Item>
  124. <Button type="primary" htmlType="submit">
  125. 查询
  126. </Button>
  127. <Button onClick={onReset}>
  128. 重置
  129. </Button>
  130. </Form.Item>
  131. </Col>
  132. </Row>
  133. </Form>
  134. </div>
  135. <div className="table">
  136. <div className="table-header">
  137. <h2 className="table-title">异常日志</h2>
  138. </div>
  139. <Table
  140. columns={columns}
  141. scroll={{ y: 'calc(100vh - 360px)' }}
  142. dataSource={logList}
  143. rowKey={record => record.id}
  144. pagination={{
  145. current: current,
  146. pageSize: size,
  147. size: 'small',
  148. showSizeChanger: true,
  149. pageSizeOptions: ['15', '30', '60', '120'],
  150. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  151. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  152. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  153. total: total
  154. }} />
  155. <Modal
  156. title="查看异常"
  157. okText='确定'
  158. cancelText='取消'
  159. width={400}
  160. visible={msvisible}
  161. onOk={handleOk}
  162. onCancel={handleCancel}
  163. maskClosable={false}
  164. >
  165. <p>{tipText}</p>
  166. </Modal>
  167. </div>
  168. </div >
  169. )
  170. }
  171. export default ExceptionLog;