loginIpDetails.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { useAjax } from '@/Hook/useAjax';
  2. import { getRoleIpDetailListApi } from '@/services/gsData';
  3. import { Modal, Table } from 'antd';
  4. import React, { useEffect, useState } from 'react';
  5. const LoginIpDetails: React.FC<{ roleId: any, icon?: React.ReactNode }> = ({ roleId, icon }) => {
  6. /*********************************/
  7. const [visible, setVisible] = useState<boolean>(false)
  8. const getRoleIpDetailList = useAjax((params) => getRoleIpDetailListApi(params))
  9. /*********************************/
  10. useEffect(() => {
  11. if (visible) {
  12. getRoleIpDetailList.run({ roleId })
  13. }
  14. }, [roleId, visible])
  15. return <>
  16. <a onClick={() => setVisible(true)}>{icon}</a>
  17. {visible && <Modal
  18. title={<strong>登录IP(角色ID:{roleId})</strong>}
  19. visible={visible}
  20. onCancel={() => setVisible(false)}
  21. footer={null}
  22. width={700}
  23. >
  24. <Table
  25. columns={[
  26. {
  27. title: 'IP',
  28. dataIndex: 'ip',
  29. key: 'ip',
  30. },
  31. {
  32. title: 'IP角色数量',
  33. dataIndex: 'ipRoleCount',
  34. key: 'ipRoleCount',
  35. }
  36. ]}
  37. rowKey={'ip'}
  38. dataSource={getRoleIpDetailList?.data?.records}
  39. loading={getRoleIpDetailList?.loading}
  40. size="small"
  41. bordered
  42. pagination={false}
  43. />
  44. </Modal>}
  45. </>
  46. };
  47. export default React.memo(LoginIpDetails);