告警工单初始化
This commit is contained in:
@@ -30,7 +30,7 @@ import {
|
||||
} from '../../api/systemSetting';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { RootState } from '@/src/store';
|
||||
import utils, { workOrderTypeOptions, getWorkOrderTypeText, errorLevelOptions, LEVEL_TAG_COLOR } from '@/lib/utils';
|
||||
import utils, { errorSourceOptions, getErrorSourceText } from '@/lib/utils';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
@@ -121,6 +121,7 @@ const AlarmModelManagement: React.FC = () => {
|
||||
form.setFieldsValue({
|
||||
errorCode: record.errorCode,
|
||||
modelId: record.modelId,
|
||||
sourceType: record.sourceType,
|
||||
autoGenerateOrder: record.autoGenerateOrder
|
||||
});
|
||||
setModalVisible(true);
|
||||
@@ -183,7 +184,8 @@ const AlarmModelManagement: React.FC = () => {
|
||||
// 后端要求字段
|
||||
errorCode: values.errorCode,
|
||||
modelId: values.modelId,
|
||||
autoGenerateOrder: values.autoGenerateOrder ?? false
|
||||
autoGenerateOrder: values.autoGenerateOrder ?? false,
|
||||
sourceType: values.sourceType ?? 1
|
||||
};
|
||||
const res = await saveAlarmOrderConfigApi(submitParams);
|
||||
if (res.code === 200 && res.data === true) {
|
||||
@@ -200,6 +202,12 @@ const AlarmModelManagement: React.FC = () => {
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{ title: '错误编码', dataIndex: 'errorCode', key: 'errorCode' },
|
||||
{
|
||||
title: '错误来源',
|
||||
dataIndex: 'sourceType',
|
||||
key: 'sourceType',
|
||||
render: (val: string) => getErrorSourceText(val)
|
||||
},
|
||||
{
|
||||
title: '关联工单模型',
|
||||
dataIndex: 'modelId',
|
||||
@@ -284,6 +292,15 @@ const AlarmModelManagement: React.FC = () => {
|
||||
<Select placeholder="请选择工单模型" options={modelOptions} allowClear />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="错误来源"
|
||||
name="sourceType"
|
||||
rules={[{ required: true, message: '请选择错误来源' }]}
|
||||
>
|
||||
<Select placeholder="请选择错误来源" options={errorSourceOptions} allowClear />
|
||||
</Form.Item>
|
||||
|
||||
|
||||
{/* 是否自动生成工单 */}
|
||||
<Form.Item
|
||||
label="自动生成工单"
|
||||
|
||||
@@ -7,10 +7,11 @@ import {
|
||||
BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined,
|
||||
SearchOutlined, ReloadOutlined, FileTextOutlined, NotificationOutlined,
|
||||
EyeOutlined,
|
||||
EditOutlined
|
||||
EditOutlined,
|
||||
ExclamationOutlined
|
||||
} from '@ant-design/icons';
|
||||
import dayjs from 'dayjs';
|
||||
import { exportTable } from "../../lib/utils.js"
|
||||
import { errorLevelOptions, exportTable } from "../../lib/utils.js"
|
||||
|
||||
// 接口引入
|
||||
import {
|
||||
@@ -24,14 +25,12 @@ import {
|
||||
import { UniversalBarChart, UniversalLineChart, UniversalPieChart } from '../recharts.jsx';
|
||||
import { addWorkOrder } from '@/api/workOrder.js';
|
||||
import { alarmLevelConfig, alarmTypeMap, handleStatusMap } from '../../constants.js';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { RootState } from '@/src/store/index.js';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
const { Text } = Typography;
|
||||
const { Option } = Select;
|
||||
|
||||
// ====================== 你提供的枚举 ======================
|
||||
|
||||
// 颜色映射(从枚举自动生成)
|
||||
const levelColor = Object.keys(alarmLevelConfig).reduce((map, key) => {
|
||||
map[key] = alarmLevelConfig[key].color;
|
||||
return map;
|
||||
@@ -42,6 +41,70 @@ const levelText = Object.keys(alarmLevelConfig).reduce((map, key) => {
|
||||
return map;
|
||||
}, {});
|
||||
|
||||
// 级别颜色配置
|
||||
const levelColorMap = {
|
||||
ERROR: '#FF4D4F', // 错误 红
|
||||
WARNING: '#FA8C16', // 警告 橙
|
||||
INFO: '#1890FF', // 信息 蓝
|
||||
};
|
||||
|
||||
|
||||
// 快速根据 value 获取 label
|
||||
const getLevelLabel = (val) => {
|
||||
const item = errorLevelOptions.find(opt => opt.value === val);
|
||||
return item?.label || '未知';
|
||||
};
|
||||
|
||||
/**
|
||||
* 通用告警级别标签组件
|
||||
* @param level 接口返回字符串 INFO / WARNING / ERROR
|
||||
* @param size small表格 | large详情弹窗
|
||||
*/
|
||||
const AlarmLevelTag = ({ level, size = 'small' }) => {
|
||||
const color = levelColorMap[level] || '#86909C';
|
||||
const text = getLevelLabel(level);
|
||||
|
||||
// 详情大标签
|
||||
if (size === 'large') {
|
||||
return (
|
||||
<Tag
|
||||
color={color}
|
||||
style={{
|
||||
border: 'none',
|
||||
color: '#fff',
|
||||
padding: '4px 10px',
|
||||
fontSize: 14,
|
||||
borderRadius: 4,
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
gap: 6
|
||||
}}
|
||||
>
|
||||
{text}
|
||||
</Tag>
|
||||
);
|
||||
}
|
||||
|
||||
// 表格小标签
|
||||
return (
|
||||
<Tag
|
||||
color={color}
|
||||
style={{
|
||||
border: 'none',
|
||||
color: '#fff',
|
||||
padding: '2px 6px',
|
||||
fontSize: 12,
|
||||
borderRadius: 2,
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
gap: 4
|
||||
}}
|
||||
>
|
||||
{text}
|
||||
</Tag>
|
||||
);
|
||||
};
|
||||
|
||||
export default function AlarmCenterPage() {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -55,6 +118,8 @@ export default function AlarmCenterPage() {
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
const [todayData, setTodayData] = useState({});
|
||||
const [yesterdayData, setYesterdayData] = useState({});
|
||||
const { stationId } = useSelector((state: RootState) => state.station);
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [editForm] = Form.useForm();
|
||||
@@ -86,8 +151,8 @@ export default function AlarmCenterPage() {
|
||||
const fetchList = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await getAlarmList({ pageNum, pageSize, ...queryParams });
|
||||
if (res.code === 0) {
|
||||
const res = await getAlarmList({ pageNum, pageSize, ...queryParams, siteId: stationId });
|
||||
if (res.code === 200) {
|
||||
setAlarmList(res.rows || []);
|
||||
setTotal(res.total || 0);
|
||||
}
|
||||
@@ -189,7 +254,7 @@ export default function AlarmCenterPage() {
|
||||
fetchList();
|
||||
|
||||
|
||||
}, [pageNum]);
|
||||
}, [pageNum, stationId]);
|
||||
useEffect(() => {
|
||||
fetchTodayAndYesterdayStat();
|
||||
fetchStat();
|
||||
@@ -201,7 +266,6 @@ export default function AlarmCenterPage() {
|
||||
{
|
||||
title: '告警编号',
|
||||
dataIndex: 'alarmNo',
|
||||
width: 180,
|
||||
render: (text) => <Text style={{ color: '#165DFF', fontWeight: 500 }}>{text}</Text>
|
||||
},
|
||||
{
|
||||
@@ -218,7 +282,7 @@ export default function AlarmCenterPage() {
|
||||
{
|
||||
title: '设备名称',
|
||||
dataIndex: 'deviceName',
|
||||
width: 160
|
||||
width: 280
|
||||
},
|
||||
{
|
||||
title: '告警类型',
|
||||
@@ -230,11 +294,8 @@ export default function AlarmCenterPage() {
|
||||
title: '告警级别',
|
||||
dataIndex: 'alarmLevel',
|
||||
width: 100,
|
||||
render: (l) => (
|
||||
<Tag color={levelColor[l]} style={{ borderRadius: 2, border: 'none', color: '#fff' }}>
|
||||
{levelText[l]}
|
||||
</Tag>
|
||||
)
|
||||
render: (l) => <AlarmLevelTag level={l} size="small" />
|
||||
|
||||
},
|
||||
{
|
||||
title: '告警时间',
|
||||
@@ -379,10 +440,9 @@ export default function AlarmCenterPage() {
|
||||
priorityLevel: currentAlarm.alarmLevel === 1 ? 1 : 2, // 严重=高,其他=中
|
||||
deviceId: currentAlarm.deviceId || '',
|
||||
deviceName: currentAlarm.deviceName || '',
|
||||
deviceType: '', // 没有就传空
|
||||
siteId: '',
|
||||
siteName: '',
|
||||
orgId: '',
|
||||
deviceType: currentAlarm.deviceType, // 没有就传空
|
||||
siteId: stationId,
|
||||
orgId: userInfo?.orgId || '',
|
||||
assigneeId: '',
|
||||
assigneeName: '',
|
||||
collaboratorIds: '',
|
||||
@@ -752,7 +812,7 @@ export default function AlarmCenterPage() {
|
||||
title="告警详情"
|
||||
open={drawerVisible}
|
||||
onClose={() => setDrawerVisible(false)}
|
||||
width={420}
|
||||
width={480}
|
||||
destroyOnClose
|
||||
>
|
||||
<Spin spinning={detailLoading}>
|
||||
@@ -767,9 +827,7 @@ export default function AlarmCenterPage() {
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
||||
<span style={{ fontSize: 16, fontWeight: 700 }}>{currentAlarm.alarmTitle}</span>
|
||||
<Tag color={levelColor[currentAlarm.alarmLevel]} style={{ borderRadius: 2, border: 'none', color: '#fff' }}>
|
||||
{levelText[currentAlarm.alarmLevel]}
|
||||
</Tag>
|
||||
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: '#86909C' }}>告警编号:{currentAlarm.alarmNo}</div>
|
||||
</div>
|
||||
@@ -795,7 +853,6 @@ export default function AlarmCenterPage() {
|
||||
return <Tag color={color}>{handleStatusMap[status] || '-'}</Tag>;
|
||||
})()}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="负责人">{currentAlarm.handleUserName || '-'}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
|
||||
{/* 告警描述 */}
|
||||
@@ -902,11 +959,8 @@ export default function AlarmCenterPage() {
|
||||
name="alarmLevel"
|
||||
rules={[{ required: true, message: '请选择告警级别' }]}
|
||||
>
|
||||
<Select>
|
||||
<Option value={1}>严重</Option>
|
||||
<Option value={2}>重要</Option>
|
||||
<Option value={3}>一般</Option>
|
||||
<Option value={4}>提示</Option>
|
||||
<Select options={errorLevelOptions}>
|
||||
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user