log.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { getTaskV3LogListApi } from "@/services/adqV3"
  3. import { Button, Drawer, Space, Table, Tag } from "antd"
  4. import React, { useEffect, useState } from "react"
  5. import { columnsLog } from "./tableConfig"
  6. import DynamicLog from "./dynamicLog"
  7. interface Props {
  8. data: any
  9. visible?: boolean,
  10. onClose?: () => void
  11. }
  12. /**
  13. * 创建日志
  14. * @returns
  15. */
  16. const Log: React.FC<Props> = (props) => {
  17. /*****************************/
  18. const { data, visible, onClose } = props
  19. const { id, taskName } = data
  20. const [queryForm, setQueryForm] = useState<PULLIN.GetTaskV3LogProps>({ pageNum: 1, pageSize: 20 })
  21. const getTaskV3LogList = useAjax((params) => getTaskV3LogListApi(params), { formatResult: true })
  22. /*****************************/
  23. useEffect(() => {
  24. getList()
  25. }, [queryForm, id])
  26. /** 获取列表 */
  27. const getList = () => {
  28. if (id) {
  29. getTaskV3LogList.run({ ...queryForm, taskId: id })
  30. }
  31. }
  32. return <Drawer
  33. bodyStyle={{ padding: 0 }}
  34. title={<Space>
  35. <span>{taskName + ' 日志'}</span>
  36. <Button type="link" onClick={() => getTaskV3LogList.refresh()}>刷新</Button>
  37. </Space>}
  38. width={1400}
  39. placement="right"
  40. onClose={() => { onClose && onClose() }}
  41. visible={visible}
  42. >
  43. <Table
  44. columns={columnsLog()}
  45. dataSource={getTaskV3LogList?.data?.data?.records}
  46. size="small"
  47. loading={getTaskV3LogList?.loading}
  48. scroll={{ y: 600 }}
  49. bordered
  50. rowKey={'id'}
  51. pagination={{
  52. pageSize: queryForm.pageSize,
  53. current: queryForm.pageNum,
  54. total: getTaskV3LogList?.data?.data?.total || 0,
  55. showTotal: (total) => <Tag color="cyan">总共{total}数据</Tag>
  56. }}
  57. onChange={(pagination) => {
  58. let { current, pageSize } = pagination
  59. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  60. newQueryForm.pageNum = current
  61. newQueryForm.pageSize = pageSize
  62. setQueryForm(newQueryForm)
  63. }}
  64. expandable={{
  65. expandedRowRender: record => <DynamicLog record={record} />
  66. }}
  67. />
  68. </Drawer>
  69. }
  70. export default React.memo(Log)