index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 { DownOutlined, PlusOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
  4. import '@common/common.less';
  5. import { useSelector } from 'react-redux'
  6. import apiObj from '@api/index';
  7. const { post, api, xPost } = apiObj;
  8. const { Option } = Select;
  9. function LoginLog() {
  10. useEffect(() => {
  11. getLoginLog();
  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 getLoginLog(param) {
  31. post(api.getLoginLog, 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. getLoginLog()
  46. }
  47. function changePage(page, pageSize) {
  48. params.current = page
  49. params.size = pageSize
  50. setCurrent(page)
  51. setParams(params)
  52. getLoginLog()
  53. }
  54. const onFinish = (value) => {
  55. const param = {
  56. ...data,
  57. ...value
  58. }
  59. setCurrent(1)
  60. setParams(param)
  61. getLoginLog(param);
  62. };
  63. const onReset = () => {
  64. setCurrent(1)
  65. setParams(data)
  66. form.resetFields();
  67. getLoginLog(data);
  68. };
  69. const columns = [
  70. { title: '编号', dataIndex: 'loginId', key: 'index' },
  71. { title: '登录名', dataIndex: 'loginName', key: 'index' },
  72. { title: '登录日期', dataIndex: 'loginDate', key: 'index' },
  73. { title: 'IP地址', dataIndex: 'loginIp', key: 'index' },
  74. { title: '地区', dataIndex: 'loginAddress', key: 'index' },
  75. { title: '浏览器', dataIndex: 'loginBrowser', key: 'index' },
  76. ]
  77. return (
  78. <div className="wrapper">
  79. <div className="filter-box">
  80. <Form
  81. form={form}
  82. name="normal_login"
  83. onFinish={onFinish}
  84. initialValues={{ status: '' }}
  85. >
  86. <Row gutter={24}>
  87. <Col span={5} key={0}>
  88. <Form.Item label="登录名" name="loginName">
  89. <Input placeholder="登录名" autoComplete='off'/>
  90. </Form.Item>
  91. </Col>
  92. <Col span={5} key={1}>
  93. <Form.Item label="IP地址" name="loginIp">
  94. <Input placeholder="IP地址" autoComplete='off' />
  95. </Form.Item>
  96. </Col>
  97. <Col span={6} key={3}>
  98. <Form.Item>
  99. <Button type="primary" htmlType="submit">
  100. 查询
  101. </Button>
  102. <Button onClick={onReset}>
  103. 重置
  104. </Button>
  105. </Form.Item>
  106. </Col>
  107. </Row>
  108. </Form>
  109. </div>
  110. <div className="table">
  111. <div className="table-header">
  112. <h2 className="table-title">登录日志</h2>
  113. </div>
  114. <Table
  115. columns={columns}
  116. scroll={{ y: 'calc(100vh - 320px)' }}
  117. dataSource={logList}
  118. rowKey={record => record.id}
  119. pagination={{
  120. current: current,
  121. pageSize: size,
  122. size: 'small',
  123. showSizeChanger: true,
  124. pageSizeOptions: ['15', '30', '60', '120'],
  125. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  126. onShowSizeChange: (current, pageSize) => onSizeChange(current, pageSize), // 改变每页数量时更新显示
  127. onChange: (page, pageSize) => changePage(page, pageSize),//点击页码事件
  128. total: total
  129. }} />
  130. </div>
  131. </div >
  132. )
  133. }
  134. export default LoginLog;