index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { Badge, Modal } from 'antd';
  2. import { observer } from '@formily/react';
  3. import { service, state } from '..';
  4. import ProTable, { ActionType, ProColumns } from '@jetlinks/pro-table';
  5. import SearchComponent from '@/components/SearchComponent';
  6. import { useLocation } from 'umi';
  7. import { InfoCircleOutlined } from '@ant-design/icons';
  8. import { useRef, useState } from 'react';
  9. const Log = observer(() => {
  10. const location = useLocation<{ id: string }>();
  11. const id = (location as any).query?.id;
  12. const columns: ProColumns<LogItem>[] = [
  13. {
  14. dataIndex: 'id',
  15. title: 'ID',
  16. ellipsis: true,
  17. },
  18. {
  19. dataIndex: 'notifyTime',
  20. title: '发送时间',
  21. valueType: 'dateTime',
  22. },
  23. {
  24. dataIndex: 'state',
  25. title: '状态',
  26. valueType: 'select',
  27. valueEnum: {
  28. success: {
  29. text: '成功',
  30. status: 'success',
  31. },
  32. error: {
  33. text: '失败',
  34. status: 'error',
  35. },
  36. },
  37. renderText: (text: { value: string; text: string }, record) => {
  38. return (
  39. <>
  40. <Badge status={text.value === 'success' ? 'success' : 'error'} text={text.text} />
  41. {text.value !== 'success' && (
  42. <a
  43. style={{ marginLeft: 5 }}
  44. key="info"
  45. onClick={() => {
  46. Modal.info({
  47. title: '错误信息',
  48. width: '30vw',
  49. content: (
  50. <div style={{ height: '300px', overflowY: 'auto' }}>{record.errorStack}</div>
  51. ),
  52. onOk() {},
  53. });
  54. }}
  55. >
  56. <InfoCircleOutlined />
  57. </a>
  58. )}
  59. </>
  60. );
  61. },
  62. },
  63. {
  64. dataIndex: 'action',
  65. title: '操作',
  66. valueType: 'option',
  67. hideInSearch: true,
  68. render: (text, record) => [
  69. <a
  70. onClick={() => {
  71. Modal.info({
  72. title: '详情信息',
  73. width: '30vw',
  74. content: (
  75. <div style={{ height: '300px', overflowY: 'auto' }}>
  76. {JSON.stringify(record.context)}
  77. </div>
  78. ),
  79. onOk() {},
  80. });
  81. }}
  82. >
  83. <InfoCircleOutlined />
  84. </a>,
  85. ],
  86. },
  87. ];
  88. const actionRef = useRef<ActionType>();
  89. const [param, setParam] = useState<any>();
  90. return (
  91. <Modal
  92. footer={null}
  93. onCancel={() => (state.log = false)}
  94. title="通知记录"
  95. width="65vw"
  96. visible={state.log && !!state.current?.id}
  97. >
  98. <SearchComponent
  99. model="simple"
  100. defaultParam={[{ column: 'notifyType$IN', value: id }]}
  101. field={columns}
  102. onSearch={(data) => {
  103. actionRef.current?.reset?.();
  104. setParam(data);
  105. }}
  106. enableSave={false}
  107. />
  108. <ProTable<LogItem>
  109. params={param}
  110. search={false}
  111. pagination={{
  112. pageSize: 5,
  113. }}
  114. columnEmptyText={''}
  115. columns={columns}
  116. request={async (params) =>
  117. service.getHistoryLog(state.current?.id || '', {
  118. ...params,
  119. sorts: [{ name: 'notifyTime', order: 'desc' }],
  120. })
  121. }
  122. />
  123. </Modal>
  124. );
  125. });
  126. export default Log;