pages_alert_handle_logs.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import React, { useState, useEffect } from 'react';
  2. import {
  3. Button, Table, Space,
  4. Form, Input, Select, message,
  5. Card, DatePicker,
  6. } from 'antd';
  7. import dayjs from 'dayjs';
  8. import 'dayjs/locale/zh-cn';
  9. // 从share/types.ts导入所有类型,包括MapMode
  10. import type {
  11. AlertHandleLog, Attachment,
  12. } from '../share/monitorTypes.ts';
  13. import {
  14. HandleType, ProblemType,
  15. HandleTypeNameMap, ProblemTypeNameMap,
  16. } from '../share/monitorTypes.ts';
  17. import { AlertHandleAPI } from './api/index.ts';
  18. // 告警处理记录页面
  19. export const AlertHandleLogsPage = () => {
  20. const [loading, setLoading] = useState(false);
  21. const [alertHandleData, setAlertHandleData] = useState<AlertHandleLog[]>([]);
  22. const [pagination, setPagination] = useState({
  23. current: 1,
  24. pageSize: 10,
  25. total: 0,
  26. });
  27. const [formRef] = Form.useForm();
  28. useEffect(() => {
  29. fetchAlertHandleData();
  30. }, [pagination.current, pagination.pageSize]);
  31. const fetchAlertHandleData = async () => {
  32. setLoading(true);
  33. try {
  34. const values = formRef.getFieldsValue();
  35. const params = {
  36. page: pagination.current,
  37. pageSize: pagination.pageSize,
  38. alert_id: values.alert_id,
  39. handler_id: values.handler_id,
  40. handle_type: values.handle_type,
  41. problem_type: values.problem_type,
  42. start_time: values.time?.[0]?.format('YYYY-MM-DD HH:mm:ss'),
  43. end_time: values.time?.[1]?.format('YYYY-MM-DD HH:mm:ss'),
  44. };
  45. const response = await AlertHandleAPI.getAlertHandleData(params);
  46. if (response) {
  47. setAlertHandleData(response.data || []);
  48. setPagination({
  49. ...pagination,
  50. total: response.total || 0,
  51. });
  52. }
  53. } catch (error) {
  54. console.error('获取告警处理记录失败:', error);
  55. message.error('获取告警处理记录失败');
  56. } finally {
  57. setLoading(false);
  58. }
  59. };
  60. const handleSearch = (values: any) => {
  61. setPagination({
  62. ...pagination,
  63. current: 1,
  64. });
  65. fetchAlertHandleData();
  66. };
  67. const handleTableChange = (newPagination: any) => {
  68. setPagination({
  69. ...pagination,
  70. current: newPagination.current,
  71. pageSize: newPagination.pageSize,
  72. });
  73. };
  74. const handleTypeOptions = [
  75. { label: '确认', value: HandleType.CONFIRM },
  76. { label: '解决', value: HandleType.RESOLVE },
  77. { label: '忽略', value: HandleType.IGNORE },
  78. ];
  79. const problemTypeOptions = [
  80. { label: '设备故障', value: ProblemType.DEVICE },
  81. { label: '网络故障', value: ProblemType.NETWORK },
  82. { label: '电源故障', value: ProblemType.POWER },
  83. { label: '施工影响', value: ProblemType.CONSTRUCTION },
  84. { label: '其他原因', value: ProblemType.OTHER },
  85. ];
  86. const columns = [
  87. {
  88. title: '记录ID',
  89. dataIndex: 'id',
  90. key: 'id',
  91. width: 80,
  92. },
  93. {
  94. title: '告警ID',
  95. dataIndex: 'alert_id',
  96. key: 'alert_id',
  97. width: 80,
  98. },
  99. {
  100. title: '处理人',
  101. dataIndex: 'handler_id',
  102. key: 'handler_id',
  103. },
  104. {
  105. title: '处理类型',
  106. dataIndex: 'handle_type',
  107. key: 'handle_type',
  108. render: (type: HandleType) => HandleTypeNameMap[type] || type,
  109. },
  110. {
  111. title: '问题类型',
  112. dataIndex: 'problem_type',
  113. key: 'problem_type',
  114. render: (type: ProblemType) => ProblemTypeNameMap[type] || type,
  115. },
  116. {
  117. title: '处理结果',
  118. dataIndex: 'handle_result',
  119. key: 'handle_result',
  120. ellipsis: true,
  121. },
  122. {
  123. title: '附件数',
  124. dataIndex: 'attachments',
  125. key: 'attachments',
  126. render: (attachments: Attachment[]) => attachments?.length || 0,
  127. },
  128. {
  129. title: '禁用通知',
  130. dataIndex: 'notify_disabled',
  131. key: 'notify_disabled',
  132. render: (value: number) => value === 1 ? '是' : '否',
  133. },
  134. {
  135. title: '处理时间',
  136. dataIndex: 'handle_time',
  137. key: 'handle_time',
  138. render: (text: Date) => dayjs(text).format('YYYY-MM-DD HH:mm:ss'),
  139. },
  140. {
  141. title: '操作',
  142. key: 'action',
  143. render: (_: any, record: AlertHandleLog) => (
  144. <Space size="middle">
  145. <Button size="small" onClick={() => message.info(`查看处理记录ID: ${record.id}`)}>
  146. 查看
  147. </Button>
  148. </Space>
  149. ),
  150. },
  151. ];
  152. return (
  153. <div>
  154. <Card title="告警处理记录" style={{ marginBottom: 16 }}>
  155. <Form
  156. form={formRef}
  157. layout="inline"
  158. onFinish={handleSearch}
  159. style={{ marginBottom: 16 }}
  160. >
  161. <Form.Item name="alert_id" label="告警ID">
  162. <Input placeholder="输入告警ID" style={{ width: 120 }} />
  163. </Form.Item>
  164. <Form.Item name="handle_type" label="处理类型">
  165. <Select
  166. placeholder="选择处理类型"
  167. style={{ width: 150 }}
  168. allowClear
  169. options={handleTypeOptions}
  170. />
  171. </Form.Item>
  172. <Form.Item name="problem_type" label="问题类型">
  173. <Select
  174. placeholder="选择问题类型"
  175. style={{ width: 150 }}
  176. allowClear
  177. options={problemTypeOptions}
  178. />
  179. </Form.Item>
  180. <Form.Item name="time" label="处理时间">
  181. <DatePicker.RangePicker
  182. showTime
  183. style={{ width: 380 }}
  184. />
  185. </Form.Item>
  186. <Form.Item>
  187. <Button type="primary" htmlType="submit">
  188. 查询
  189. </Button>
  190. </Form.Item>
  191. </Form>
  192. <Table
  193. columns={columns}
  194. dataSource={alertHandleData}
  195. rowKey="id"
  196. pagination={pagination}
  197. loading={loading}
  198. onChange={handleTableChange}
  199. />
  200. </Card>
  201. </div>
  202. );
  203. };