优化修复告警和工单
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Card, Row, Col, Select, DatePicker, Input, Button, Space, Table, Tag,
|
||||
Typography, message, Pagination, Spin, Drawer, Descriptions, Switch, Form
|
||||
Typography, message, Pagination, Spin, Drawer, Descriptions, Switch, Form, Modal
|
||||
} from 'antd';
|
||||
import {
|
||||
BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined,
|
||||
@@ -17,38 +17,18 @@ import {
|
||||
getAlarmDetail,
|
||||
getAlarmStatistics,
|
||||
handleAlarm,
|
||||
exportAlarm
|
||||
exportAlarm,
|
||||
updateAlarm
|
||||
} from '../../api/alarmApi.js';
|
||||
import { UniversalBarChart, UniversalLineChart, UniversalPieChart } from '../recharts.jsx';
|
||||
import { addWorkOrder } from '@/api/workOrder.js';
|
||||
import { alarmLevelConfig, alarmTypeMap, handleStatusMap } from '../../constants.js';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
const { Text } = Typography;
|
||||
const { Option } = Select;
|
||||
|
||||
// ====================== 你提供的枚举 ======================
|
||||
const alarmTypeMap = {
|
||||
1: '设备故障',
|
||||
2: '数据异常',
|
||||
3: '通信中断',
|
||||
4: '性能告警',
|
||||
5: '安全告警',
|
||||
6: '环境告警'
|
||||
};
|
||||
|
||||
const alarmLevelConfig = {
|
||||
1: { description: '严重', color: '#FF4D4F' },
|
||||
2: { description: '重要', color: '#FA8C16' },
|
||||
3: { description: '一般', color: '#FADB14' },
|
||||
4: { description: '提示', color: '#1890FF' }
|
||||
};
|
||||
|
||||
const handleStatusMap = {
|
||||
1: '待处理',
|
||||
2: '处理中',
|
||||
3: '已关闭',
|
||||
4: '已忽略'
|
||||
};
|
||||
|
||||
// 颜色映射(从枚举自动生成)
|
||||
const levelColor = Object.keys(alarmLevelConfig).reduce((map, key) => {
|
||||
@@ -73,6 +53,9 @@ export default function AlarmCenterPage() {
|
||||
const [pageSize] = useState(10);
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [editForm] = Form.useForm();
|
||||
|
||||
|
||||
// 查询条件
|
||||
const [queryParams, setQueryParams] = useState({
|
||||
@@ -173,6 +156,30 @@ export default function AlarmCenterPage() {
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
};
|
||||
// 打开修改告警弹窗
|
||||
const openEditModal = (record) => {
|
||||
editForm.setFieldsValue({
|
||||
id: record.id,
|
||||
alarmTitle: record.alarmTitle,
|
||||
alarmContent: record.alarmContent,
|
||||
alarmLevel: record.alarmLevel,
|
||||
alarmType: record.alarmType,
|
||||
});
|
||||
setEditModalVisible(true);
|
||||
};
|
||||
// 提交修改告警
|
||||
const handleUpdateAlarm = async (values) => {
|
||||
try {
|
||||
await updateAlarm(values);
|
||||
messageApi.success('修改成功');
|
||||
setEditModalVisible(false);
|
||||
fetchList(); // 刷新列表
|
||||
fetchStat(); // 刷新统计
|
||||
} catch (err) {
|
||||
messageApi.error('修改失败');
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
// 加载
|
||||
useEffect(() => {
|
||||
@@ -249,7 +256,12 @@ export default function AlarmCenterPage() {
|
||||
width: 100,
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<Button type="link" onClick={() => showDetail(record.id)}>查看</Button>
|
||||
<Space>
|
||||
<Button type="link" onClick={() => showDetail(record.id)}>查看</Button>
|
||||
{/* 新增修改按钮 */}
|
||||
<Button type="link" onClick={() => openEditModal(record)}>修改</Button>
|
||||
</Space>
|
||||
|
||||
)
|
||||
}
|
||||
];
|
||||
@@ -756,6 +768,76 @@ export default function AlarmCenterPage() {
|
||||
)}
|
||||
</Spin>
|
||||
</Drawer>
|
||||
{/* ====================== 修改告警弹窗 ====================== */}
|
||||
<Modal
|
||||
title="修改告警"
|
||||
open={editModalVisible}
|
||||
onCancel={() => setEditModalVisible(false)}
|
||||
footer={null}
|
||||
width={520}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form
|
||||
form={editForm}
|
||||
layout="vertical"
|
||||
onFinish={handleUpdateAlarm}
|
||||
>
|
||||
<Form.Item name="id" hidden>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="告警标题"
|
||||
name="alarmTitle"
|
||||
rules={[{ required: true, message: '请输入告警标题' }]}
|
||||
>
|
||||
<Input placeholder="请输入告警标题" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="告警级别"
|
||||
name="alarmLevel"
|
||||
rules={[{ required: true, message: '请选择告警级别' }]}
|
||||
>
|
||||
<Select>
|
||||
<Option value={1}>严重</Option>
|
||||
<Option value={2}>重要</Option>
|
||||
<Option value={3}>一般</Option>
|
||||
<Option value={4}>提示</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="告警类型"
|
||||
name="alarmType"
|
||||
rules={[{ required: true, message: '请选择告警类型' }]}
|
||||
>
|
||||
<Select>
|
||||
<Option value={1}>设备故障</Option>
|
||||
<Option value={2}>数据异常</Option>
|
||||
<Option value={3}>通信中断</Option>
|
||||
<Option value={4}>性能告警</Option>
|
||||
<Option value={5}>安全告警</Option>
|
||||
<Option value={6}>环境告警</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="告警内容"
|
||||
name="alarmContent"
|
||||
rules={[{ required: true, message: '请输入告警内容' }]}
|
||||
>
|
||||
<Input.TextArea rows={4} placeholder="请输入告警内容" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item style={{ textAlign: 'right', marginBottom: 0 }}>
|
||||
<Button onClick={() => setEditModalVisible(false)}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" style={{ marginLeft: 8 }}>
|
||||
确认修改
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user