index.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { useIntl } from '@@/plugin-locale/localeExports';
  2. import { useRef, useState } from 'react';
  3. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  4. import ProTable from '@jetlinks/pro-table';
  5. import type { SystemLogItem } from '@/pages/Log/System/typings';
  6. import { Tag, Tooltip } from 'antd';
  7. import moment from 'moment';
  8. import BaseService from '@/utils/BaseService';
  9. import { EyeOutlined } from '@ant-design/icons';
  10. import SearchComponent from '@/components/SearchComponent';
  11. import Detail from '@/pages/Log/System/Detail';
  12. import { useDomFullHeight } from '@/hooks';
  13. const service = new BaseService<SystemLogItem>('logger/system');
  14. const System = () => {
  15. const intl = useIntl();
  16. const actionRef = useRef<ActionType>();
  17. const [param, setParam] = useState({});
  18. const [visible, setVisible] = useState<boolean>(false);
  19. const [current, setCurrent] = useState<Partial<SystemLogItem>>({});
  20. const { minHeight } = useDomFullHeight(`.systemLog`, 24);
  21. const columns: ProColumns<SystemLogItem>[] = [
  22. {
  23. title: intl.formatMessage({
  24. id: 'pages.table.name',
  25. defaultMessage: '名称',
  26. }),
  27. dataIndex: 'name',
  28. ellipsis: true,
  29. fixed: 'left',
  30. },
  31. {
  32. title: '日志级别',
  33. dataIndex: 'level',
  34. width: 80,
  35. render: (text) => <Tag color={text === 'ERROR' ? 'red' : 'orange'}>{text}</Tag>,
  36. valueType: 'select',
  37. valueEnum: {
  38. ERROR: {
  39. text: 'ERROR',
  40. status: 'ERROR',
  41. },
  42. INFO: {
  43. text: 'INFO',
  44. status: 'INFO',
  45. },
  46. DEBUG: {
  47. text: 'DEBUG',
  48. status: 'DEBUG',
  49. },
  50. WARN: {
  51. text: 'WARN',
  52. status: 'WARN',
  53. },
  54. },
  55. },
  56. {
  57. title: intl.formatMessage({
  58. id: 'pages.log.system.logContent',
  59. defaultMessage: '日志内容',
  60. }),
  61. dataIndex: 'message',
  62. ellipsis: true,
  63. },
  64. {
  65. title: intl.formatMessage({
  66. id: 'pages.log.system.serviceName',
  67. defaultMessage: '服务名',
  68. }),
  69. dataIndex: 'context.server',
  70. width: 150,
  71. ellipsis: true,
  72. render: (text, record) => record?.context?.server || '',
  73. },
  74. {
  75. title: intl.formatMessage({
  76. id: 'pages.log.system.creationTime',
  77. defaultMessage: '创建时间',
  78. }),
  79. dataIndex: 'createTime',
  80. width: 200,
  81. sorter: true,
  82. ellipsis: true,
  83. valueType: 'dateTime',
  84. defaultSortOrder: 'descend',
  85. renderText: (text) => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  86. },
  87. {
  88. title: intl.formatMessage({
  89. id: 'pages.data.option',
  90. defaultMessage: '操作',
  91. }),
  92. valueType: 'option',
  93. align: 'center',
  94. width: 200,
  95. fixed: 'right',
  96. render: (text, record) => [
  97. <a
  98. key="editable"
  99. onClick={() => {
  100. setVisible(true);
  101. setCurrent(record);
  102. }}
  103. >
  104. <Tooltip title="查看">
  105. <EyeOutlined />
  106. </Tooltip>
  107. </a>,
  108. ],
  109. },
  110. ];
  111. return (
  112. <>
  113. <SearchComponent<SystemLogItem>
  114. field={columns}
  115. target="system-log"
  116. onSearch={(data) => {
  117. actionRef.current?.reset?.();
  118. setParam(data);
  119. }}
  120. />
  121. <ProTable<SystemLogItem>
  122. columns={columns}
  123. params={param}
  124. scroll={{ x: 1366 }}
  125. tableClassName={'systemLog'}
  126. tableStyle={{ minHeight }}
  127. request={async (params) =>
  128. service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
  129. }
  130. defaultParams={{ sorts: [{ createTime: 'desc' }] }}
  131. search={false}
  132. actionRef={actionRef}
  133. />
  134. {visible && (
  135. <Detail
  136. data={current}
  137. close={() => {
  138. setVisible(false);
  139. setCurrent({});
  140. }}
  141. />
  142. )}
  143. </>
  144. );
  145. };
  146. export default System;