This commit is contained in:
mmc
2026-05-07 17:09:19 +08:00
parent 9cf26ce2bd
commit 5ef889e435
5 changed files with 439 additions and 112 deletions

View File

@@ -5,7 +5,7 @@ import {
} from 'antd';
import {
PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined,
AppstoreOutlined, SwapOutlined, VideoCameraOutlined, AlertOutlined
AppstoreOutlined, SwapOutlined, VideoCameraOutlined
} from '@ant-design/icons';
const { Option } = Select;
@@ -44,7 +44,7 @@ const modelDetailList: Record<number, {
{ id: 2, code: 'record_status', name: '录像状态', type: 'string', rw: 'r', isAlarm: false },
],
events: [{ id: 1, code: 'alarm_perimeter', name: '周界入侵告警' }],
actions: [{ id: 1, code: 'take_snapshot', name: '截图' }]
actions: [{ actionId: 'take_snapshot', actionName: '截图', params: {} }]
},
11: {
props: [
@@ -101,6 +101,11 @@ export default function DeviceAccessPage() {
const [itemType, setItemType] = useState<'props' | 'events' | 'actions'>('props');
const [itemForm] = Form.useForm();
// 指令 + 参数 新增状态
const [actionModal, setActionModal] = useState(false);
const [currentAction, setCurrentAction] = useState<any>(null);
const [paramList, setParamList] = useState<any[]>([]);
// 字段映射(实时增删改查,实时保存)
const [mappingList, setMappingList] = useState(mappingInitList);
const [mappingModal, setMappingModal] = useState(false);
@@ -128,15 +133,35 @@ export default function DeviceAccessPage() {
setVisible(true);
};
// 产品提交
// 提交
const handleSubmit = () => {
form.validateFields().then(values => {
message.success('产品信息保存成功');
if (modalType === 'model') {
const submitData = {
name: values.name,
connectType: values.connectType,
version: "1.0",
deviceType: values.deviceType,
supportProperties: modelDetail.props.map(p => ({
propertyKey: p.code,
propertyName: p.name,
dataType: p.type,
unit: p.unit || "",
required: true,
defaultValue: null
})),
supportActions: modelDetail.actions
};
console.log("最终提交物模型:", submitData);
message.success("物模型保存成功");
} else {
message.success("保存成功");
}
setVisible(false);
});
};
// 物模型
// 属性/事件 编辑
const openItemModal = (type: 'props' | 'events' | 'actions', record?: any) => {
setItemType(type);
itemForm.resetFields();
@@ -163,18 +188,14 @@ export default function DeviceAccessPage() {
else mappingForm.setFieldsValue({ productId: editData?.id });
setMappingModal(true);
};
// 新增/编辑 → 立即保存
const saveMapping = () => {
mappingForm.validateFields().then(val => {
let newList = [...mappingList];
if (val.id) {
// 编辑
const index = newList.findIndex(x => x.id === val.id);
if (index >= 0) newList[index] = val;
message.success('字段映射修改成功');
} else {
// 新增
newList.push({ ...val, id: Date.now() });
message.success('字段映射新增成功');
}
@@ -183,8 +204,6 @@ export default function DeviceAccessPage() {
setMappingModal(false);
});
};
// 删除 → 立即保存
const deleteMapping = (id: number) => {
const newList = mappingList.filter(x => x.id !== id);
setMappingList(newList);
@@ -201,9 +220,9 @@ export default function DeviceAccessPage() {
{ title: 'SN', dataIndex: 'sn' },
{ title: '所属产品', dataIndex: 'productName' },
{ title: '物模型', dataIndex: 'modelName' },
{ title: '协议', dataIndex: 'protocolType', render: t => <Tag>{t.toUpperCase()}</Tag> },
{ title: '协议', render: t => <Tag>{t.protocolType.toUpperCase()}</Tag> },
{ title: '状态', render: r => <Tag color={r.onlineStatus ? 'green' : 'red'}>{r.onlineStatus ? '在线' : '离线'}</Tag> },
{ title: '操作', render: r => <Space><Button type="text" icon={<EditOutlined />} onClick={() => openModal('device', r)}>编辑</Button></Space> }
{ title: '操作', render: r => <Button type="text" icon={<EditOutlined />} onClick={() => openModal('device', r)}>编辑</Button> }
];
const productColumns = [
@@ -239,8 +258,8 @@ export default function DeviceAccessPage() {
</Card>
{activeTab === 'device' && <Card><Space className="mb-3"><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('device')}>新增设备</Button></Space><Table rowKey="id" columns={deviceColumns} dataSource={deviceList} /></Card>}
{activeTab === 'product' && <Card><Space><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('product')}>新增产品</Button></Space><Table rowKey="id" columns={productColumns} dataSource={productList} /></Card>}
{activeTab === 'model' && <Card><Space><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('model')}>新增物模型</Button></Space><Table rowKey="id" columns={modelColumns} dataSource={modelList} /></Card>}
{activeTab === 'product' && <Card><Space className="mb-3"><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('product')}>新增产品</Button></Space><Table rowKey="id" columns={productColumns} dataSource={productList} /></Card>}
{activeTab === 'model' && <Card><Space className="mb-3"><Button type="primary" icon={<PlusOutlined />} onClick={() => openModal('model')}>新增物模型</Button></Space><Table rowKey="id" columns={modelColumns} dataSource={modelList} /></Card>}
<Modal open={visible} width={850} onCancel={() => setVisible(false)} onOk={handleSubmit} destroyOnClose
title={modalType === 'device' ? '设备配置' : modalType === 'product' ? '产品配置' : '物模型配置'}>
@@ -281,7 +300,6 @@ export default function DeviceAccessPage() {
<Form.Item label="默认协议类型" name="protocolType"><Select value={productProtocol} onChange={setProductProtocol}><Option value="onvif">ONVIF</Option><Option value="rtsp">RTSP</Option><Option value="mqtt">MQTT</Option></Select></Form.Item>
{productProtocol === 'mqtt' && <><Divider>MQTT 厂商级 Topic 配置</Divider><Form.Item label="设备上报 Topic" name="publishTopic"><Input /></Form.Item><Form.Item label="平台下发 Topic" name="subscribeTopic"><Input /></Form.Item></>}
</TabPane>
<TabPane tab="字段映射" key="mapping">
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => openMappingModal()} className="mb-2">新增映射</Button>
<Table size="small" dataSource={mappingList.filter(x => x.productId === editData?.id)} pagination={false}
@@ -305,9 +323,24 @@ export default function DeviceAccessPage() {
{modalType === 'model' && (
<>
<Form.Item label="模型名称" name="name" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item label="模型编码" name="code" rules={[{ required: true }]}><Input /></Form.Item>
<Form.Item label="模型描述" name="desc"><Input.TextArea rows={2} /></Form.Item>
<div style={{ display: "flex", gap: 16, marginBottom: 16 }}>
<div style={{ flex: 1 }}>
<Form.Item label="模型名称" name="name" rules={[{ required: true }]}>
<Input />
</Form.Item>
</div>
<div style={{ flex: 1 }}>
<Form.Item label="连接协议" name="connectType" initialValue="MQTT">
<Input />
</Form.Item>
</div>
<div style={{ flex: 1 }}>
<Form.Item label="设备类型" name="deviceType" initialValue={1}>
<InputNumber style={{ width: "100%" }} />
</Form.Item>
</div>
</div>
<Divider>属性列表</Divider>
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => openItemModal('props')} className="mb-2">新增属性</Button>
<Table size="small" dataSource={modelDetail.props} pagination={false} columns={[
@@ -315,10 +348,41 @@ export default function DeviceAccessPage() {
{ title: '告警', render: r => <Switch checked={r.isAlarm} disabled size="small" /> },
{ title: '操作', render: r => <Space><Button type="text" icon={<EditOutlined />} onClick={() => openItemModal('props', r)}>编辑</Button><Popconfirm onConfirm={() => deleteItem('props', r.id)}><Button type="text" danger icon={<DeleteOutlined />}>删除</Button></Popconfirm></Space> }
]} />
<Divider>事件列表</Divider>
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => openItemModal('events')} className="mb-2">新增事件</Button>
<Table size="small" dataSource={modelDetail.events} pagination={false} columns={[{ title: '编码', dataIndex: 'code' }, { title: '名称', dataIndex: 'name' }, { title: '操作', render: r => <Button type="text" icon={<EditOutlined />} onClick={() => openItemModal('events', r)}>编辑</Button> }]} />
<Divider>指令列表</Divider>
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => {
setCurrentAction({ actionId: '', actionName: '', params: {} });
setParamList([]);
setActionModal(true);
}} className="mb-2">新增指令</Button>
<Table size="small" dataSource={modelDetail.actions} pagination={false} columns={[
{ title: '指令编码', dataIndex: 'actionId' },
{ title: '指令名称', dataIndex: 'actionName' },
{ title: '参数', render: r => Object.keys(r.params || {}).join(',') || '无' },
{
title: '操作', render: r => (
<Space>
<Button type="text" onClick={() => {
setCurrentAction(r);
const arr = [];
for (let k in r.params) {
arr.push({ paramKey: k, ...r.params[k] });
}
setParamList(arr);
setActionModal(true);
}}>编辑</Button>
<Popconfirm onConfirm={() => {
setModelDetail({
...modelDetail,
actions: modelDetail.actions.filter(x => x.actionId !== r.actionId)
})
}}>
<Button type="text" danger>删除</Button>
</Popconfirm>
</Space>
)
}
]} />
</>
)}
</Form>
@@ -333,7 +397,92 @@ export default function DeviceAccessPage() {
</Form>
</Modal>
{/* 字段映射弹窗:操作即保存 */}
{/* 指令 + 参数 弹窗 */}
<Modal
title="配置指令"
open={actionModal}
onCancel={() => setActionModal(false)}
onOk={() => {
const params = paramList.reduce((obj, item) => {
obj[item.paramKey] = {
type: item.type,
description: item.desc || '',
default: item.defaultValue
};
return obj;
}, {});
const action = {
actionId: currentAction.actionId,
actionName: currentAction.actionName,
params
};
const exists = modelDetail.actions.some(x => x.actionId === currentAction.actionId);
let newActions = [];
if (exists) {
newActions = modelDetail.actions.map(x => x.actionId === currentAction.actionId ? action : x);
} else {
newActions = [...modelDetail.actions, action];
}
setModelDetail({ ...modelDetail, actions: newActions });
setActionModal(false);
message.success('保存成功');
}}
width={700}
>
<div style={{ marginBottom: 16 }}>
<Input
placeholder="指令编码 如 restart"
value={currentAction?.actionId}
onChange={(e) => setCurrentAction({ ...currentAction, actionId: e.target.value })}
style={{ width: '48%', marginRight: '4%' }}
/>
<Input
placeholder="指令名称 如 重启设备"
value={currentAction?.actionName}
onChange={(e) => setCurrentAction({ ...currentAction, actionName: e.target.value })}
style={{ width: '48%' }}
/>
</div>
<Divider>指令参数</Divider>
{paramList.map((item, index) => (
<div key={index} style={{ display: 'flex', gap: 8, marginBottom: 10, alignItems: 'center' }}>
<Input placeholder="参数名" value={item.paramKey} onChange={(e) => {
const arr = [...paramList];
arr[index].paramKey = e.target.value;
setParamList(arr);
}} />
<Select value={item.type} style={{ width: 100 }} onChange={(v) => {
const arr = [...paramList];
arr[index].type = v;
setParamList(arr);
}}>
<Select.Option value="int">int</Select.Option>
<Select.Option value="string">string</Select.Option>
</Select>
<Input placeholder="描述" value={item.desc} onChange={(e) => {
const arr = [...paramList];
arr[index].desc = e.target.value;
setParamList(arr);
}} />
<Input placeholder="默认值" value={item.defaultValue} onChange={(e) => {
const arr = [...paramList];
arr[index].defaultValue = e.target.value;
setParamList(arr);
}} />
<Button danger size="small" onClick={() => setParamList(paramList.filter((_, i) => i !== index))}>删</Button>
</div>
))}
<Button size="small" type="dashed" block onClick={() => {
setParamList([...paramList, { paramKey: '', type: 'int', desc: '', defaultValue: '' }])
}}>+ 添加参数</Button>
</Modal>
<Modal open={mappingModal} width={600} zIndex={1002} destroyOnClose onCancel={() => setMappingModal(false)} onOk={saveMapping} title="字段映射配置">
<Form form={mappingForm} layout="vertical">
<Form.Item name="id" hidden /><Form.Item name="productId" hidden />

View File

@@ -411,43 +411,46 @@ export default function UserRolePage() {
onChange: (selectedRowKeys) => setSelectedUserIds(selectedRowKeys)
}}
columns={[
{ title: '用户账号', dataIndex: 'userName' },
{ title: '用户昵称', dataIndex: 'nickName' },
{ title: '手机号', dataIndex: 'phonenumber' },
{ title: '邮箱', dataIndex: 'email' },
// 所属机构
{ title: '用户账号', dataIndex: 'userName', ellipsis: true },
{ title: '用户昵称', dataIndex: 'nickName', ellipsis: true },
{ title: '手机号', dataIndex: 'phonenumber', ellipsis: true },
{ title: '邮箱', dataIndex: 'email', ellipsis: true },
{
title: '所属机构',
render: (_, r) => {
const org = orgList.find(o => o.id == r.orgId);
return org ? org.orgName : '—';
}
},
ellipsis: true
},
// 所属场站(纯缓存匹配,无接口)
{
title: '所属场站',
render: (_, r) => {
if (!r.siteId) return '—';
const site = allSiteList.find(s => s.id == r.siteId);
return site ? site.siteName : '—';
}
},
ellipsis: true
},
{
title: '角色',
render: (_, r) => (r.roles || []).map(i => (
<Tag color="blue" key={i.roleId}>{i?.roleKey}</Tag>
))
)),
ellipsis: true
},
{
title: '状态',
title: '状态', dataIndex: 'status', width: 80,
render: (_, s) => s.status === '0'
? <Tag color="green">正常</Tag>
: <Tag color="red">停用</Tag>
},
{
title: '操作',
width: 220,
fixed: 'right',
render: (_, r) => (
<Space>
<Space wrap>
<Button type="text" icon={<EditOutlined style={{ color: '#1890ff' }} />} onClick={() => handleEditUser(r)}>编辑</Button>
<Popconfirm onConfirm={() => handleDeleteUser(r.userId)} title="确定删除该用户吗?">
<Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
@@ -468,6 +471,8 @@ export default function UserRolePage() {
onChange={(p) => setUserPagination({ ...userPagination, pageNum: p.current!, pageSize: p.pageSize! })}
bordered
size="middle"
// 👇 下面这行是修复不自适应的关键
scroll={{ x: 'max-content' }}
/>
</TabPane>

View File

@@ -1,21 +1,157 @@
import React from 'react';
import { Card, Row, Col, Space, Empty } from 'antd';
import { AlertOutlined, CloseCircleOutlined, ExclamationCircleOutlined, CheckCircleOutlined } from '@ant-design/icons';
import React, { useState } from 'react';
import {
Card, Row, Col, Select, DatePicker, Input, Button, Space, Table, Tag,
Statistic, Typography, Tabs
} from 'antd';
import {
BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined
} from '@ant-design/icons';
const AntdCard = Card as any;
const { RangePicker } = DatePicker;
const { Text } = Typography;
const AlarmOverview = () => {
return (
<div style={{ padding: 24 }}>
<Row gutter={16} style={{ marginBottom: 24 }}>
<Col span={6}><AntdCard size="small"><Space><div style={{ background: '#e6f4ff', borderRadius: 8, padding: 8 }}><AlertOutlined style={{ color: '#1677ff', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>告警总数</div><div style={{ fontWeight: 600 }}>45</div></div></Space></AntdCard></Col>
<Col span={6}><AntdCard size="small"><Space><div style={{ background: '#fff2f0', borderRadius: 8, padding: 8 }}><CloseCircleOutlined style={{ color: '#ff4d4f', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>严重告警</div><div style={{ fontWeight: 600 }}>12</div></div></Space></AntdCard></Col>
<Col span={6}><AntdCard size="small"><Space><div style={{ background: '#fff7e6', borderRadius: 8, padding: 8 }}><ExclamationCircleOutlined style={{ color: '#fa8c16', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>警告告警</div><div style={{ fontWeight: 600 }}>20</div></div></Space></AntdCard></Col>
<Col span={6}><AntdCard size="small"><Space><div style={{ background: '#f6ffed', borderRadius: 8, padding: 8 }}><CheckCircleOutlined style={{ color: '#52c41a', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>已处理</div><div style={{ fontWeight: 600 }}>13</div></div></Space></AntdCard></Col>
</Row>
<AntdCard title="告警地图"><Empty description="告警地图(可接入GIS)" /></AntdCard>
</div>
);
// 级别 + 状态颜色
const levelColor = {
严重: 'red',
重要: 'orange',
一般: 'gold',
提示: 'blue'
};
export default AlarmOverview;
const statusColor = {
处理中: 'processing',
待处理: 'warning',
已关闭: 'success'
};
// 模拟数据
const mockAlerts = [
{ id: 'DEVICE_OFFLINE_CAM-02', content: '设备离线', device: 'CAM-02', level: '提示', time: '2026-04-28 17:22:04', duration: '1小时23分', status: '待处理', handler: '-' },
{ id: 'INV_TEMP_HIGH_INV-A02', content: '逆变器温度过高', device: 'INV-A02', level: '重要', time: '2026-04-28 17:21:54', duration: '1小时23分', status: '待处理', handler: '-' },
{ id: 'AL-20260428-001', content: 'INV-A02 温度过高', device: 'INV-A02', level: '重要', time: '2026-04-28 10:54:45', duration: '36分钟', status: '待处理', handler: '-' },
{ id: 'AL-20260428-002', content: 'CMB-A01 组串电流异常', device: 'CMB-A01', level: '一般', time: '2026-04-28 10:32:45', duration: '52分钟', status: '处理中', handler: '张运维' },
{ id: 'AL-20260428-003', content: 'CAM-02 视频离线', device: 'CAM-02', level: '提示', time: '2026-04-28 09:32:45', duration: '0分钟', status: '待处理', handler: '-' },
];
export default function AlarmCenterPage() {
const [selectedAlert, setSelectedAlert] = useState<any>(mockAlerts[0]);
const [detailVisible, setDetailVisible] = useState(true);
const columns = [
{ title: '告警编号', dataIndex: 'id', width: 180 },
{ title: '告警内容', dataIndex: 'content', ellipsis: true },
{ title: '来源设备', dataIndex: 'device', width: 120 },
{ title: '告警级别', dataIndex: 'level', width: 100, render: l => <Tag color={levelColor[l]}>{l}</Tag> },
{ title: '发生时间', dataIndex: 'time', width: 160 },
{ title: '持续时长', dataIndex: 'duration', width: 100 },
{ title: '处理状态', dataIndex: 'status', width: 100, render: s => <Tag color={statusColor[s]}>{s}</Tag> },
{ title: '负责人', dataIndex: 'handler', width: 100 },
{
title: '操作', width: 120,
render: (_, record) => (
<Space>
<Button type="link" onClick={() => { setSelectedAlert(record); setDetailVisible(true); }}>查看</Button>
<Button type="link">更多</Button>
</Space>
)
}
];
return (
<div style={{ background: '#f5f7fa', minHeight: '100vh', padding: '0 24px 24px' }}>
{/* ===================== 统一宽度容器 ===================== */}
<div style={{ display: 'flex', gap: 16, marginTop: 16 }}>
{/* ===================== 左侧:所有模块宽度完全一致 ===================== */}
<div style={{ flex: 1 }}>
{/* 筛选卡片 */}
<Card style={{ borderRadius: 8, border: 'none', marginBottom: 16 }} bodyStyle={{ padding: '16px' }}>
<Row gutter={16} align="middle">
<Col><Select placeholder="告警级别" style={{ width: 120 }} /></Col>
<Col><Select placeholder="告警类型" style={{ width: 120 }} /></Col>
<Col><Select placeholder="设备类型" style={{ width: 120 }} /></Col>
<Col><RangePicker placeholder={['开始', '结束']} style={{ width: 240 }} /></Col>
<Col><Select placeholder="处理状态" style={{ width: 120 }} /></Col>
<Col flex="auto"><Input placeholder="搜索告警编号/内容/设备" style={{ width: '100%' }} /></Col>
<Col><Space><Button>重置</Button><Button type="primary">查询</Button></Space></Col>
</Row>
</Card>
{/* 统计卡片 */}
<Row gutter={16} style={{ marginBottom: 16 }}>
<Col span={4}><Card bordered={false} style={{ borderRadius: 8 }}><Statistic title="今日告警总数" value={5} prefix={<BellOutlined style={{ color: '#ff4d4f' }} />} valueStyle={{ fontSize: 22 }} /><div style={{ fontSize: 12, color: '#999' }}>昨日 28</div></Card></Col>
<Col span={4}><Card bordered={false} style={{ borderRadius: 8 }}><Statistic title="严重告警" value={0} prefix={<ExclamationCircleOutlined style={{ color: '#ff4d4f' }} />} valueStyle={{ fontSize: 22 }} /><div style={{ fontSize: 12, color: '#999' }}>重要 2</div></Card></Col>
<Col span={4}><Card bordered={false} style={{ borderRadius: 8 }}><Statistic title="处理中" value={1} prefix={<ClockCircleOutlined style={{ color: '#faad14' }} />} valueStyle={{ fontSize: 22 }} /><div style={{ fontSize: 12, color: '#999' }}>待处理 4</div></Card></Col>
<Col span={4}><Card bordered={false} style={{ borderRadius: 8 }}><Statistic title="已关闭" value={0} prefix={<CheckCircleOutlined style={{ color: '#52c41a' }} />} valueStyle={{ fontSize: 22 }} /><div style={{ fontSize: 12, color: '#999' }}>闭环完成</div></Card></Col>
<Col span={4}><Card bordered={false} style={{ borderRadius: 8 }}><Statistic title="平均响应" value="49分钟" prefix={<ClockCircleOutlined style={{ color: '#1890ff' }} />} valueStyle={{ fontSize: 22 }} /><div style={{ fontSize: 12, color: '#999' }}>时间估算</div></Card></Col>
</Row>
{/* 告警列表(宽度 = 筛选卡片 完全一致) */}
<Card bordered={false} style={{ borderRadius: 8 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
<div>
<Typography.Text strong style={{ fontSize: 16 }}>告警列表(共8条)</Typography.Text><br />
<Text type="secondary" style={{ fontSize: 12 }}>点击告警查看详情</Text>
</div>
</div>
<Table
rowKey="id"
columns={columns}
dataSource={mockAlerts}
pagination={{ pageSize: 8 }}
scroll={{ x: '100%' }}
style={{ width: '100%' }}
/>
</Card>
</div>
{/* ===================== 右侧详情面板 ===================== */}
{detailVisible && selectedAlert && (
<div style={{ width: 360, flexShrink: 0 }}>
<Card title="告警详情" bordered={false} style={{ borderRadius: 8, height: '100%' }}>
<div style={{ marginBottom: 20 }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<div style={{ display: 'flex', alignItems: 'center' }}>
<ExclamationCircleOutlined style={{ color: '#ff4d4f', marginRight: 8 }} />
<span style={{ fontSize: 16, fontWeight: 500 }}>{selectedAlert.content}</span>
</div>
<Tag color={levelColor[selectedAlert.level]}>{selectedAlert.level}</Tag>
</div>
<div style={{ fontSize: 12, color: '#999', marginTop: 4 }}>{selectedAlert.id}</div>
</div>
<div style={{ background: '#fafafa', borderRadius: 8, padding: 16, marginBottom: 16 }}>
<Row gutter={[16, 16]}>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>来源设备</div><div>{selectedAlert.device}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>发生时间</div><div>{selectedAlert.time}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>持续时长</div><div>{selectedAlert.duration}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>处理状态</div><div>{selectedAlert.status}</div></Col>
</Row>
</div>
<div style={{ marginBottom: 16 }}>
<div style={{ fontWeight: 500, marginBottom: 8 }}>根因分析建议</div>
<div style={{ fontSize: 12, color: '#666', lineHeight: 1.7 }}>
设备离线/网络异常<br />
电源或通讯模块故障<br />
现场信号弱或采集器异常
</div>
</div>
<Space direction="vertical" style={{ width: '100%' }}>
<Button type="primary" block>确认告警</Button>
<Button block>标记处理中</Button>
<Button block danger>关闭告警</Button>
</Space>
</Card>
</div>
)}
</div>
</div>
);
}

View File

@@ -1,19 +1,20 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import {
Card, Table, Button, Space, Popconfirm, Tag, Badge,
Modal, Form, Input, Select, Switch
Modal, Form, Input, Select, Switch, message
} from 'antd';
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
// 从你的设备接入页面 导入 物模型数据
//import { modelList, modelDetailList } from './DeviceAccessPage';
const AntdCard = Card as any;
const { Option } = Input;
const { Search } = Input;
// 模拟数据
const mockRules = [
{ id: 1, name: '温度超温', deviceType: 'sensor', level: 'warn', condition: 'temp > 60', status: true },
{ id: 2, name: '视频信号丢失', deviceType: 'camera', level: 'error', condition: 'signal == 0', status: true },
{ id: 3, name: '电池低电量', deviceType: 'battery', level: 'info', condition: 'power < 20', status: false },
{ id: 1, name: '温度超温', deviceType: 'sensor', modelId:11, propCode:'temp', level: 'warn', condition: 'temp > 60', status: true },
{ id: 2, name: '电池低电量', deviceType: 'battery', modelId:12, propCode:'battery', level: 'info', condition: 'battery < 20', status: false },
];
const AlarmRules = () => {
@@ -23,12 +24,18 @@ const AlarmRules = () => {
const [editingId, setEditingId] = useState<number | null>(null);
const [form] = Form.useForm();
// 搜索筛选
// 下拉选项
const [deviceTypeOpts, setDeviceTypeOpts] = useState([
{ value: 'sensor', label: '传感器' },
{ value: 'camera', label: '摄像头' },
{ value: 'battery', label: '电池设备' },
]);
const [propList, setPropList] = useState<any[]>([]);
// 搜索
const handleSearch = (value: string) => {
const res = list.filter(item =>
item.name.includes(value) ||
item.deviceType.includes(value) ||
item.condition.includes(value)
item.name.includes(value) || item.condition.includes(value)
);
setFilteredList(res);
};
@@ -44,25 +51,27 @@ const AlarmRules = () => {
const openEdit = (record: any) => {
setEditingId(record.id);
form.setFieldsValue(record);
loadProps(record.modelId);
setModalVisible(true);
};
// 保存(新增 + 编辑)
// 保存
const handleSave = () => {
form.validateFields().then(values => {
const data = {
...values,
condition: `${values.propCode} ${values.symbol} ${values.threshold}`
};
if (editingId !== null) {
// 编辑
const updated = list.map(item =>
item.id === editingId ? { ...item, ...values } : item
);
const updated = list.map(item => item.id === editingId ? { ...item, ...data } : item);
setList(updated);
setFilteredList(updated);
message.success('修改成功');
} else {
// 新增
const newRule = { ...values, id: Date.now() };
const newList = [...list, newRule];
setList(newList);
setFilteredList(newList);
const newRule = { ...data, id: Date.now() };
setList([...list, newRule]);
setFilteredList([...list, newRule]);
message.success('新增成功');
}
setModalVisible(false);
});
@@ -73,8 +82,25 @@ const AlarmRules = () => {
const newList = list.filter(x => x.id !== id);
setList(newList);
setFilteredList(newList);
message.success('删除成功');
};
// 加载物模型属性
const loadProps = (modelId: number) => {
//const detail = modelDetailList[modelId];
//if (detail?.props) {
// setPropList(detail.props.map(p => ({ value: p.code, label: p.name })));
//} else {
// setPropList([]);
//}
};
// 选择物模型后加载属性
//useEffect(() => {
// const modelId = form.getFieldValue('modelId');
// if (modelId) loadProps(modelId);
//}, [form.getFieldValue('modelId')]);
const columns = [
{ title: '规则名称', dataIndex: 'name' },
{ title: '设备类型', dataIndex: 'deviceType' },
@@ -82,28 +108,21 @@ const AlarmRules = () => {
title: '告警级别',
render: (r: any) => {
const color = r.level === 'error' ? 'red' : r.level === 'warn' ? 'orange' : 'blue';
const text = r.level === 'error' ? '严重' : r.level === 'warn' ? '警告' : '提示';
const text = { error:'严重', warn:'警告', info:'提示' }[r.level];
return <Tag color={color}>{text}</Tag>;
}
},
{ title: '触发条件', dataIndex: 'condition' },
{
title: '状态',
render: (r: any) => (
<Badge status={r.status ? 'success' : 'error'} text={r.status ? '启用' : '禁用'} />
)
render: (r: any) => <Badge status={r.status ? 'success' : 'error'} text={r.status ? '启用' : '禁用'} />
},
{
title: '操作',
render: (r: any) => (
<Space>
<Button type="link" icon={<EditOutlined />} onClick={() => openEdit(r)}>编辑</Button>
<Popconfirm
title="确定删除这条规则吗?"
onConfirm={() => handleDelete(r.id)}
>
<Button type="link" danger icon={<DeleteOutlined />}>删除</Button>
</Popconfirm>
<Popconfirm onConfirm={() => handleDelete(r.id)}><Button type="link" danger>删除</Button></Popconfirm>
</Space>
)
}
@@ -112,51 +131,68 @@ const AlarmRules = () => {
return (
<div style={{ padding: 24 }}>
<AntdCard
title="告警规则"
title="告警规则配置"
extra={
<Space>
{/* 修复:使用 Input.Search */}
<Search
placeholder="搜索规则名称/设备/条件"
style={{ width: 260 }}
onSearch={handleSearch}
/>
<Button icon={<PlusOutlined />} type="primary" onClick={openAdd}>
新增规则
</Button>
<Search placeholder="搜索" style={{ width: 260 }} onSearch={handleSearch} />
<Button icon={<PlusOutlined />} type="primary" onClick={openAdd}>新增规则</Button>
</Space>
}
>
<Table
rowKey="id"
columns={columns}
dataSource={filteredList}
pagination={{ pageSize: 10 }}
/>
<Table rowKey="id" columns={columns} dataSource={filteredList} />
</AntdCard>
{/* 新增/编辑 弹窗 */}
<Modal
title={editingId ? '编辑告警规则' : '新增告警规则'}
title={editingId ? '编辑规则' : '新增规则'}
open={modalVisible}
onCancel={() => setModalVisible(false)}
onOk={handleSave}
maskClosable={false}
width={600}
>
<Form form={form} layout="vertical">
<Form.Item label="规则名称" name="name" rules={[{ required: true, message: '请输入规则名称' }]}>
<Input placeholder="例如:温度超温告警" />
<Form.Item label="规则名称" name="name" rules={[{ required: true }]}>
<Input placeholder="例如:温度超上限" />
</Form.Item>
<Form.Item label="设备类型" name="deviceType" rules={[{ required: true }]}>
<Select>
<Select.Option value="sensor">传感器</Select.Option>
<Select.Option value="camera">摄像头</Select.Option>
<Select.Option value="battery">电池设备</Select.Option>
<Select.Option value="inverter">逆变器</Select.Option>
{deviceTypeOpts.map(o => <Select.Option key={o.value} value={o.value}>{o.label}</Select.Option>)}
</Select>
</Form.Item>
<Form.Item label="关联物模型" name="modelId" rules={[{ required: true }]}>
<Select
onChange={(val) => {
form.setFieldValue('modelId', val);
loadProps(val);
}}
>
{/*{modelList.map(m => (
<Select.Option key={m.id} value={m.id}>{m.name}</Select.Option>
))}*/}
</Select>
</Form.Item>
<Form.Item label="监控属性" name="propCode" rules={[{ required: true }]}>
<Select>
{propList.map(p => (
<Select.Option key={p.value} value={p.value}>{p.label}</Select.Option>
))}
</Select>
</Form.Item>
<Form.Item label="比较符号" name="symbol" rules={[{ required: true }]}>
<Select style={{ width: 100 }}>
<Select.Option value=">">大于 </Select.Option>
<Select.Option value="<">小于 </Select.Option>
<Select.Option value="==">等于 ==</Select.Option>
</Select>
</Form.Item>
<Form.Item label="阈值" name="threshold" rules={[{ required: true }]}>
<Input placeholder="填写数值" />
</Form.Item>
<Form.Item label="告警级别" name="level" rules={[{ required: true }]}>
<Select>
<Select.Option value="error">严重</Select.Option>
@@ -165,12 +201,8 @@ const AlarmRules = () => {
</Select>
</Form.Item>
<Form.Item label="触发条件" name="condition" rules={[{ required: true }]}>
<Input placeholder="例如:temp > 60 / power < 20" />
</Form.Item>
<Form.Item label="是否启用" name="status" valuePropName="checked">
<Switch checkedChildren="启用" unCheckedChildren="禁用" />
<Form.Item label="启用" name="status" valuePropName="checked">
<Switch />
</Form.Item>
</Form>
</Modal>