index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. console.log(123);
  12. }, []);
  13. const [logList, setLogList] = useState([]);
  14. const [total, setTotal] = useState(0);
  15. const [size, setSize] = useState(15);
  16. const [msvisible, setMsvisible] = useState(false);
  17. const [tipText, setTipText] = useState('');
  18. const [current, setCurrent] = useState(1);
  19. const [params, setParams] = useState({
  20. pages: 1,
  21. current: 1,
  22. size: 15
  23. });
  24. const [form] = Form.useForm();
  25. let list = []
  26. let data = {
  27. pages: 1,
  28. current: 1,
  29. size: 15
  30. }
  31. //表格数据
  32. function getAbnormalLog(param) {
  33. post(api.getAbnormalLog, param || params).then((res) => {
  34. if (res.data.code === 200) {
  35. const data = res.data.data;
  36. console.log(data);
  37. setLogList(data.records);
  38. setTotal(data.total)
  39. }
  40. })
  41. }
  42. function onSizeChange(current, pageSize) {
  43. params.current = current
  44. params.size = pageSize
  45. setSize(pageSize)
  46. setCurrent(current)
  47. setParams(params)
  48. getAbnormalLog()
  49. }
  50. function changePage(page, pageSize) {
  51. params.current = page
  52. params.size = pageSize
  53. setCurrent(page)
  54. setParams(params)
  55. getAbnormalLog()
  56. }
  57. function showModal(operationWay) {
  58. setMsvisible(true)
  59. getAbnormalLogWayAndIp(operationWay)
  60. }
  61. function handleOk() {
  62. setMsvisible(false)
  63. }
  64. function handleCancel() {
  65. setMsvisible(false)
  66. }
  67. function getAbnormalLogWayAndIp(operationWay) {
  68. let params = {
  69. mark:0,
  70. operationWay: operationWay
  71. }
  72. post(api.getAbnormalLogWayAndIp, params).then((res) => {
  73. if (res.data.code === 200) {
  74. const data = res.data.data;
  75. setTipText(data)
  76. }
  77. })
  78. }
  79. const onFinish = (value) => {
  80. const param = {
  81. ...data,
  82. ...value
  83. }
  84. setCurrent(1)
  85. setParams(param)
  86. getAbnormalLog(param);
  87. };
  88. const onReset = () => {
  89. setCurrent(1)
  90. setParams(data)
  91. form.resetFields();
  92. getAbnormalLog(data);
  93. };
  94. const columns = [
  95. { title: '编号', dataIndex: 'operationId', key: 'index' },
  96. { title: '请求URL', dataIndex: 'operationUrl', key: 'index' },
  97. { title: '请求方式', dataIndex: 'operationWay', key: 'index' },
  98. {
  99. title: '请求参数', key: 'index', render: (text, record) => (
  100. <Tooltip placement="top" title={record.operationParam}>
  101. <span className="record">{record.operationParam}</span>
  102. </Tooltip>
  103. )
  104. },
  105. { title: 'IP地址', dataIndex: 'operationIp', key: 'index' },
  106. { title: '用户代理', dataIndex: 'operationName', key: 'index' },
  107. { title: '创建时间', dataIndex: 'gmtCreate', key: 'index' },
  108. {
  109. title: '操作', dataIndex: 'key', render: (text, record) => (
  110. <Space size="middle">
  111. <a onClick={e => showModal(record.operationWay)}>查看</a>
  112. </Space>
  113. )
  114. }
  115. ]
  116. return (
  117. <div className="wrapper">
  118. <div className="filter-box">
  119. <Form
  120. form={form}
  121. name="normal_login"
  122. onFinish={onFinish}
  123. initialValues={{ status: '' }}
  124. >
  125. <Row gutter={24}>
  126. <Col span={5} key={0}>
  127. <Form.Item label="请求方式" name="operationWay">
  128. <Input placeholder="请求方式" autoComplete='off'/>
  129. </Form.Item>
  130. </Col>
  131. <Col span={5} key={1}>
  132. <Form.Item label="IP地址" name="operationIp">
  133. <Input placeholder="IP地址" autoComplete='off'/>
  134. </Form.Item>
  135. </Col>
  136. <Col span={6} key={3}>
  137. <Form.Item>
  138. <Button type="primary" htmlType="submit">
  139. 查询
  140. </Button>
  141. <Button onClick={onReset}>
  142. 重置
  143. </Button>
  144. </Form.Item>
  145. </Col>
  146. </Row>
  147. </Form>
  148. </div>
  149. <div className="table">
  150. <div className="table-header">
  151. <h2 className="table-title">异常日志</h2>
  152. </div>
  153. <Table
  154. columns={columns}
  155. scroll={{ y: 'calc(100vh - 320px)' }}
  156. dataSource={logList}
  157. rowKey={record => record.id}
  158. pagination={{
  159. current: current,
  160. pageSize: size,
  161. size: 'small',
  162. showSizeChanger: true,
  163. pageSizeOptions: ['15', '30', '60', '120'],
  164. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  165. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  166. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  167. total: total
  168. }} />
  169. <Modal
  170. title="查看异常"
  171. okText='确定'
  172. cancelText='取消'
  173. width={400}
  174. visible={msvisible}
  175. onOk={handleOk}
  176. onCancel={handleCancel}
  177. >
  178. <p>{tipText}</p>
  179. </Modal>
  180. </div>
  181. </div >
  182. )
  183. }
  184. export default ExceptionLog;