基础设置页面 设备管理页面
This commit is contained in:
397
src/components/SystemSetting/BasicSettings.tsx
Normal file
397
src/components/SystemSetting/BasicSettings.tsx
Normal file
@@ -0,0 +1,397 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Form,
|
||||
Input,
|
||||
Select,
|
||||
Switch,
|
||||
Button,
|
||||
Row,
|
||||
Col,
|
||||
Card as AntdCard,
|
||||
Tag,
|
||||
Table,
|
||||
message,
|
||||
Typography,
|
||||
Space,
|
||||
Modal,
|
||||
} from 'antd';
|
||||
import {
|
||||
CloudOutlined,
|
||||
TeamOutlined,
|
||||
BellOutlined,
|
||||
DatabaseOutlined,
|
||||
CalendarOutlined,
|
||||
CheckCircleOutlined,
|
||||
SyncOutlined,
|
||||
DownloadOutlined,
|
||||
FileTextOutlined,
|
||||
DeleteOutlined,
|
||||
RestOutlined,
|
||||
} from '@ant-design/icons';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const BasicSettings = () => {
|
||||
const [form] = Form.useForm();
|
||||
const handleSave = () => {
|
||||
message.success('设置已保存');
|
||||
};
|
||||
|
||||
// 设备接入状态数据
|
||||
const deviceStatusData = [
|
||||
{ name: '逆变器', count: '5/5', status: '正常', color: '#52c41a' },
|
||||
{ name: '汇流箱', count: '20/20', status: '正常', color: '#52c41a' },
|
||||
{ name: '摄像头', count: '12/12', status: '正常', color: '#52c41a' },
|
||||
{ name: '无人机', count: '2/2', status: '正常', color: '#52c41a' },
|
||||
{ name: 'API接口', count: '正常', status: '正常', color: '#52c41a' },
|
||||
{ name: 'Modbus', count: '正常', status: '正常', color: '#52c41a' },
|
||||
];
|
||||
|
||||
// 服务配置数据
|
||||
const serviceConfigData = [
|
||||
{ name: 'MQTT配置', value: 'tcp://localhost:1883', status: '离线', statusColor: '#8c8c8c' },
|
||||
{ name: '视频服务配置', value: '待接入 RTSP / WebRTC 服务', status: '待处理', statusColor: '#fa8c16' },
|
||||
{ name: 'AI服务配置', value: 'http://ai-service.local', status: '待处理', statusColor: '#fa8c16' },
|
||||
{ name: 'API密钥管理', value: '正常', status: '正常', statusColor: '#52c41a' },
|
||||
];
|
||||
|
||||
// 视频服务配置数据
|
||||
const videoServiceData = [
|
||||
{ name: '视频服务数', value: '1' },
|
||||
{ name: '启用服务数', value: '1' },
|
||||
{ name: '摄像头总数', value: '3' },
|
||||
{ name: '离线摄像头', value: '3' },
|
||||
{ name: '在线流数量', value: '0' },
|
||||
{ name: '服务状态', value: 'ONLINE', statusColor: '#52c41a' },
|
||||
{ name: 'API地址', value: 'http://127.0.0.1:9997' },
|
||||
{ name: 'HLS地址', value: 'http://127.0.0.1:8888' },
|
||||
{ name: 'WebRTC地址', value: 'http://127.0.0.1:8889' },
|
||||
{ name: '检测结果', value: 'HTTP 401 - http://127.0.0.1...' },
|
||||
];
|
||||
|
||||
// MQTT接入状态数据
|
||||
const mqttStatusData = [
|
||||
{ name: '启用状态', value: '已启用', statusColor: '#52c41a' },
|
||||
{ name: '连接状态', value: '已连接', statusColor: '#52c41a' },
|
||||
{ name: 'Broker', value: 'tcp://localhost:1883' },
|
||||
{ name: '客户端ID', value: 'solar-platform-backend' },
|
||||
{ name: '遥测主题', value: 'pv/+/device/+/telemetry' },
|
||||
{ name: '状态主题', value: 'pv/+/device/+/status' },
|
||||
{ name: '最近连接', value: '2026-05-07 18:30:40' },
|
||||
{ name: '最近错误', value: '-' },
|
||||
];
|
||||
|
||||
// MQTT消息日志数据
|
||||
const mqttLogData = [
|
||||
{ topic: 'pv/1/device/ROBOT-01/ack', device: 'ROBOT-01', type: 'ACK', parse: 'SUCCESS' },
|
||||
{ topic: 'pv/1/device/ROBOT-01/ack', device: 'ROBOT-01', type: 'ACK', parse: 'SUCCESS' },
|
||||
{ topic: 'pv/1/device/CAM-02/status', device: 'CAM-02', type: 'STATUS', parse: 'SUCCESS' },
|
||||
{ topic: 'pv/1/device/INV-A02/telemetry', device: 'INV-A02', type: 'TELEMETRY', parse: 'SUCCESS' },
|
||||
];
|
||||
|
||||
// WebSocket状态数据
|
||||
const wsStatusData = [
|
||||
{ name: '服务状态', value: '已启用', statusColor: '#52c41a' },
|
||||
{ name: '前端连接', value: '已连接', statusColor: '#52c41a' },
|
||||
{ name: 'Endpoint', value: '/ws/pv' },
|
||||
{ name: '在线连接数', value: '2' },
|
||||
{ name: '最近推送', value: '-' },
|
||||
{ name: '推送时间', value: '-' },
|
||||
{ name: '前端端点', value: 'ws://47.100.102.7:10469/de...' },
|
||||
{ name: '最近错误', value: '-' },
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24, background: '#f0f2f5', minHeight: '100vh' }}>
|
||||
{/* 顶部卡片 */}
|
||||
<Row gutter={16} style={{ marginBottom: 24 }}>
|
||||
<Col span={5}>
|
||||
<AntdCard size="small">
|
||||
<Space>
|
||||
<div style={{ background: '#e6f4ff', borderRadius: 8, padding: 8 }}>
|
||||
<CloudOutlined style={{ color: '#1677ff', fontSize: 20 }} />
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 13, color: '#666' }}>当前版本</div>
|
||||
<div style={{ fontWeight: 600 }}>v2.8.1 <Tag color="blue">最新版</Tag></div>
|
||||
</div>
|
||||
</Space>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
<Col span={5}>
|
||||
<AntdCard size="small">
|
||||
<Space>
|
||||
<div style={{ background: '#f6ffed', borderRadius: 8, padding: 8 }}>
|
||||
<TeamOutlined style={{ color: '#52c41a', fontSize: 20 }} />
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 13, color: '#666' }}>在线用户</div>
|
||||
<div style={{ fontWeight: 600 }}>12 <span style={{ color: '#52c41a', fontSize: 12 }}>↑ 2</span></div>
|
||||
</div>
|
||||
</Space>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
<Col span={5}>
|
||||
<AntdCard size="small">
|
||||
<Space>
|
||||
<div style={{ background: '#fff2f0', borderRadius: 8, padding: 8 }}>
|
||||
<BellOutlined style={{ color: '#ff4d4f', fontSize: 20 }} />
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 13, color: '#666' }}>告警通道</div>
|
||||
<div style={{ fontWeight: 600 }}>3 / 4 <span style={{ color: '#52c41a', fontSize: 12 }}>正常</span></div>
|
||||
</div>
|
||||
</Space>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
<Col span={5}>
|
||||
<AntdCard size="small">
|
||||
<Space>
|
||||
<div style={{ background: '#e6fffb', borderRadius: 8, padding: 8 }}>
|
||||
<DatabaseOutlined style={{ color: '#13c2c2', fontSize: 20 }} />
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 13, color: '#666' }}>数据备份状态</div>
|
||||
<div style={{ fontWeight: 600 }}>正常 <span style={{ color: '#52c41a', fontSize: 12 }}>●</span></div>
|
||||
</div>
|
||||
</Space>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<AntdCard size="small">
|
||||
<Space>
|
||||
<div style={{ background: '#f9f0ff', borderRadius: 8, padding: 8 }}>
|
||||
<CalendarOutlined style={{ color: '#722ed1', fontSize: 20 }} />
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 13, color: '#666' }}>最近更新</div>
|
||||
<div style={{ fontWeight: 600 }}>2025-05-20</div>
|
||||
</div>
|
||||
</Space>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={16}>
|
||||
{/* 左侧主内容 */}
|
||||
<Col span={16}>
|
||||
{/* 平台参数 */}
|
||||
<AntdCard title="平台参数" style={{ marginBottom: 16 }}>
|
||||
<Form form={form} layout="vertical">
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item label="系统名称" name="systemName">
|
||||
<Input defaultValue="光伏场站智能监控与运维系统" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item label="默认电站" name="defaultSite">
|
||||
<Select defaultValue="1MW 光伏电站">
|
||||
<Select.Option value="1MW">1MW 光伏电站</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item label="数据刷新频率" name="refreshRate">
|
||||
<Select defaultValue="5分钟">
|
||||
<Select.Option value="5">5分钟</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item label="地图服务" name="mapService">
|
||||
<Select defaultValue="高德地图">
|
||||
<Select.Option value="amap">高德地图</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<Form.Item label="AI建议自动生成" valuePropName="checked">
|
||||
<Switch defaultChecked />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</AntdCard>
|
||||
|
||||
{/* 通知与告警策略 */}
|
||||
<AntdCard title="通知与告警策略" style={{ marginBottom: 16 }}>
|
||||
<Row gutter={16} style={{ marginBottom: 16 }}>
|
||||
<Col span={8}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 16px', border: '1px solid #e8e8e8', borderRadius: 8 }}>
|
||||
<Text strong>短信</Text>
|
||||
<Switch defaultChecked />
|
||||
</div>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 16px', border: '1px solid #e8e8e8', borderRadius: 8 }}>
|
||||
<Text strong>邮件</Text>
|
||||
<Switch defaultChecked />
|
||||
</div>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 16px', border: '1px solid #e8e8e8', borderRadius: 8 }}>
|
||||
<Text strong>企业微信</Text>
|
||||
<Switch defaultChecked />
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16}>
|
||||
<Col span={8}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 16px', border: '1px solid #e8e8e8', borderRadius: 8 }}>
|
||||
<Text strong>系统通知</Text>
|
||||
<Switch defaultChecked />
|
||||
</div>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 16px', border: '1px solid #e8e8e8', borderRadius: 8 }}>
|
||||
<Text strong>严重告警立即通知</Text>
|
||||
<Switch defaultChecked />
|
||||
</div>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 16px', border: '1px solid #e8e8e8', borderRadius: 8 }}>
|
||||
<Text strong>通信中断通知</Text>
|
||||
<Switch defaultChecked />
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
</AntdCard>
|
||||
|
||||
{/* 用户与权限预览 */}
|
||||
<AntdCard title="用户与权限预览">
|
||||
<Table
|
||||
size="small"
|
||||
pagination={false}
|
||||
columns={[
|
||||
{ title: '用户名', dataIndex: 'name' },
|
||||
{ title: '角色', dataIndex: 'role' },
|
||||
{ title: '手机号', dataIndex: 'phone' },
|
||||
{ title: '状态', dataIndex: 'status', render: (text) => <span style={{ color: '#52c41a' }}>{text}</span> },
|
||||
]}
|
||||
dataSource={[
|
||||
{ name: '张运维', role: '超级管理员', phone: '138****0001', status: '在线' },
|
||||
{ name: '李工程师', role: '运维工程师', phone: '139****0002', status: '在线' },
|
||||
{ name: '王班长', role: '巡检主管', phone: '137****0003', status: '在线' },
|
||||
{ name: '赵分析师', role: '数据分析师', phone: '136****0004', status: '在线' },
|
||||
]}
|
||||
/>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
|
||||
{/* 右侧边栏 */}
|
||||
<Col span={8}>
|
||||
{/* 设备接入状态 */}
|
||||
<AntdCard title="设备接入状态" style={{ marginBottom: 16 }}>
|
||||
<Row gutter={16}>
|
||||
{deviceStatusData.map((item, index) => (
|
||||
<Col span={12} key={index}>
|
||||
<div style={{ border: '1px solid #e8e8e8', borderRadius: 8, padding: 12, marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 13, color: '#666', marginBottom: 4 }}>{item.name}</div>
|
||||
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 4 }}>{item.count}</div>
|
||||
<div style={{ color: item.color, fontSize: 13 }}>{item.status}</div>
|
||||
</div>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
</AntdCard>
|
||||
|
||||
{/* 服务配置展示 */}
|
||||
<AntdCard title="服务配置展示" style={{ marginBottom: 16 }}>
|
||||
{serviceConfigData.map((item, index) => (
|
||||
<div key={index} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 0', borderBottom: index !== serviceConfigData.length - 1 ? '1px solid #e8e8e8' : 'none' }}>
|
||||
<div>
|
||||
<div style={{ fontWeight: 500, marginBottom: 4 }}>{item.name}</div>
|
||||
<div style={{ fontSize: 13 }}>{item.value}</div>
|
||||
</div>
|
||||
<Tag color={item.statusColor === '#52c41a' ? 'success' : item.statusColor === '#fa8c16' ? 'warning' : 'default'}>{item.status}</Tag>
|
||||
</div>
|
||||
))}
|
||||
</AntdCard>
|
||||
|
||||
{/* 视频服务配置状态 */}
|
||||
<AntdCard title="视频服务配置状态" style={{ marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 13, color: '#666', marginBottom: 16 }}>来自 /pv/video/summary 与 /pv/video/media-server/list</div>
|
||||
<Row gutter={16}>
|
||||
{videoServiceData.map((item, index) => (
|
||||
<Col span={12} key={index}>
|
||||
<div style={{ border: '1px solid #e8e8e8', borderRadius: 8, padding: 12, marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 13, color: '#666', marginBottom: 4 }}>{item.name}</div>
|
||||
<div style={{ fontSize: 16, fontWeight: 600, color: item.statusColor || '#333' }}>{item.value}</div>
|
||||
</div>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
<Button type="primary" style={{ width: '100%' }} onClick={() => message.info('检测视频服务')}>检测视频服务</Button>
|
||||
</AntdCard>
|
||||
|
||||
{/* MQTT接入状态 */}
|
||||
<AntdCard title="MQTT接入状态" style={{ marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 13, color: '#666', marginBottom: 16 }}>来自 /pv/mqtt/status,后端未登录时显示预览兜底数据</div>
|
||||
<Row gutter={16}>
|
||||
{mqttStatusData.map((item, index) => (
|
||||
<Col span={12} key={index}>
|
||||
<div style={{ border: '1px solid #e8e8e8', borderRadius: 8, padding: 12, marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 13, color: '#666', marginBottom: 4 }}>{item.name}</div>
|
||||
<div style={{ fontSize: 16, fontWeight: 600, color: item.statusColor || '#333' }}>{item.value}</div>
|
||||
</div>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
</AntdCard>
|
||||
|
||||
{/* MQTT消息日志 */}
|
||||
<AntdCard title="MQTT消息日志" style={{ marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 13, color: '#666', marginBottom: 16 }}>阶段3A用于验证遥测原始消息落库</div>
|
||||
<Table
|
||||
size="small"
|
||||
pagination={false}
|
||||
columns={[
|
||||
{ title: 'Topic', dataIndex: 'topic' },
|
||||
{ title: '设备', dataIndex: 'device' },
|
||||
{ title: '类型', dataIndex: 'type' },
|
||||
{ title: '解析', dataIndex: 'parse' },
|
||||
]}
|
||||
dataSource={mqttLogData}
|
||||
/>
|
||||
</AntdCard>
|
||||
|
||||
{/* WebSocket实时推送 */}
|
||||
<AntdCard title="WebSocket实时推送" style={{ marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 13, color: '#666', marginBottom: 16 }}>来自 /pv/ws/status,并显示前端本地连接状态</div>
|
||||
<Row gutter={16}>
|
||||
{wsStatusData.map((item, index) => (
|
||||
<Col span={12} key={index}>
|
||||
<div style={{ border: '1px solid #e8e8e8', borderRadius: 8, padding: 12, marginBottom: 16 }}>
|
||||
<div style={{ fontSize: 13, color: '#666', marginBottom: 4 }}>{item.name}</div>
|
||||
<div style={{ fontSize: 16, fontWeight: 600, color: item.statusColor || '#333' }}>{item.value}</div>
|
||||
</div>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
</AntdCard>
|
||||
|
||||
{/* 系统维护 */}
|
||||
<AntdCard title="系统维护">
|
||||
<Row gutter={16}>
|
||||
<Col span={12} style={{ marginBottom: 16 }}>
|
||||
<Button style={{ width: '100%' }} icon={<DeleteOutlined />}>清理缓存</Button>
|
||||
</Col>
|
||||
<Col span={12} style={{ marginBottom: 16 }}>
|
||||
<Button style={{ width: '100%' }} icon={<RestOutlined />}>重启服务</Button>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Button style={{ width: '100%' }} icon={<DownloadOutlined />}>备份下载</Button>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Button style={{ width: '100%' }} icon={<FileTextOutlined />}>日志导出</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default BasicSettings;
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined,
|
||||
AppstoreOutlined, SwapOutlined, VideoCameraOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { addDeviceModel, getDeviceModelList } from '../../api/deviceAccess.ts';
|
||||
import { addDeviceModel, getDeviceModelList, updateDeviceModel } from '../../api/deviceAccess.ts';
|
||||
|
||||
const { Option } = Select;
|
||||
const { TabPane } = Tabs;
|
||||
@@ -116,13 +116,26 @@ export default function DeviceAccessPage() {
|
||||
const [filterForm] = Form.useForm();
|
||||
const [filteredModelList, setFilteredModelList] = useState(modelList);
|
||||
|
||||
// ========== 物模型分页(只加这里) ==========
|
||||
// ========== 物模型分页 ==========
|
||||
const [pagination, setPagination] = useState({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: modelList.length,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
// 删除物模型
|
||||
const handleDeleteModel = (id) => {
|
||||
// 这里替换成你的真实删除接口
|
||||
//deleteDeviceModel(id).then(res => {
|
||||
// if (res.code === 200) {
|
||||
// message.success('删除成功');
|
||||
// getModel(); // 删除后刷新列表
|
||||
// } else {
|
||||
// message.error('删除失败:' + res.msg);
|
||||
// }
|
||||
//}).catch(() => message.error('删除请求异常'));
|
||||
};
|
||||
|
||||
// 打开弹窗
|
||||
const openModal = (type: string, record?: any) => {
|
||||
setModalType(type);
|
||||
@@ -131,7 +144,25 @@ export default function DeviceAccessPage() {
|
||||
|
||||
if (record) {
|
||||
form.setFieldsValue(record);
|
||||
if (type === 'model') setModelDetail(modelDetailList[record.id] || { props: [], events: [], actions: [] });
|
||||
if (type === 'model') {
|
||||
// 接口数据 → 前端格式转换
|
||||
const props = record.supportProperties?.map(p => ({
|
||||
id: p.id,
|
||||
code: p.propertyKey,
|
||||
name: p.propertyName,
|
||||
type: p.dataType,
|
||||
unit: p.unit,
|
||||
required: p.required,
|
||||
defaultValue: p.defaultValue,
|
||||
isAlarm: p.isAlarm
|
||||
})) || [];
|
||||
const actions = record.supportActions?.map(a => ({
|
||||
actionId: a.actionId,
|
||||
actionName: a.actionName,
|
||||
params: a.params || {}
|
||||
})) || [];
|
||||
setModelDetail({ props, events: [], actions });
|
||||
}
|
||||
if (type === 'device') {
|
||||
setDeviceProtocol(record.protocolType);
|
||||
setModelDetail(modelDetailList[record.modelId] || { props: [] });
|
||||
@@ -155,10 +186,9 @@ export default function DeviceAccessPage() {
|
||||
connectType: values.connectType || '',
|
||||
};
|
||||
getDeviceModelList(params).then(res => {
|
||||
// 接口返回格式自行替换:res.list / res.total
|
||||
if (res.code === 200) {
|
||||
// setFilteredModelList(res.data.list);
|
||||
// setPagination(prev => ({ ...prev, total: res.data.total }));
|
||||
setFilteredModelList(res.rows);
|
||||
setPagination(prev => ({ ...prev, total: res.total }));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -166,14 +196,14 @@ export default function DeviceAccessPage() {
|
||||
// 筛选
|
||||
const handleFilter = () => {
|
||||
setPagination(prev => ({ ...prev, current: 1 }));
|
||||
setTimeout(() => getModel(), 0);
|
||||
getModel();
|
||||
};
|
||||
|
||||
// 重置
|
||||
const handleReset = () => {
|
||||
filterForm.resetFields();
|
||||
setPagination(prev => ({ ...prev, current: 1 }));
|
||||
setTimeout(() => getModel(), 0);
|
||||
getModel();
|
||||
};
|
||||
|
||||
// 分页切换
|
||||
@@ -187,6 +217,7 @@ export default function DeviceAccessPage() {
|
||||
form.validateFields().then(values => {
|
||||
if (modalType === 'model') {
|
||||
const submitData = {
|
||||
id: editData?.id,
|
||||
name: values.name,
|
||||
connectType: values.connectType,
|
||||
version: '1.0',
|
||||
@@ -206,12 +237,25 @@ export default function DeviceAccessPage() {
|
||||
params: act.params || {}
|
||||
}))
|
||||
};
|
||||
addDeviceModel(submitData).then(res => {
|
||||
if (res.code === 200) {
|
||||
message.success('物模型保存成功');
|
||||
getModel(); // 保存后刷新列表
|
||||
}
|
||||
});
|
||||
if (editData) {
|
||||
// 编辑:调用 updateDeviceModel,自动带 id
|
||||
updateDeviceModel(submitData).then(res => {
|
||||
if (res.code === 200) {
|
||||
message.success('编辑成功');
|
||||
getModel();
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 新增
|
||||
addDeviceModel(submitData).then(res => {
|
||||
if (res.code === 200) {
|
||||
message.success('新增成功');
|
||||
getModel();
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
console.log('✅ 提交物模型', submitData);
|
||||
}
|
||||
setVisible(false);
|
||||
@@ -272,7 +316,7 @@ export default function DeviceAccessPage() {
|
||||
if (activeTab === 'model') {
|
||||
getModel();
|
||||
}
|
||||
}, [ pagination.pageSize, activeTab]);
|
||||
}, [pagination.current, pagination.pageSize, activeTab]);
|
||||
|
||||
// 表格列
|
||||
const deviceColumns = [
|
||||
@@ -301,11 +345,58 @@ export default function DeviceAccessPage() {
|
||||
}
|
||||
];
|
||||
|
||||
// ====================== 已增加属性列 + 指令列 ======================
|
||||
const modelColumns = [
|
||||
{ title: '模型名称', dataIndex: 'name' },
|
||||
{ title: '连接协议', dataIndex: 'connectType' },
|
||||
{ title: '操作', render: r => <Button type="text" icon={<EditOutlined />} onClick={() => openModal('model', r)}>编辑</Button> }
|
||||
];
|
||||
{
|
||||
title: '属性列表',
|
||||
width: 300,
|
||||
render: (record) => {
|
||||
const list = record.supportProperties || [];
|
||||
if (list.length === 0) return <span style={{ color: '#999' }}>无属性</span>;
|
||||
return (
|
||||
<Space size={[4, 4]} wrap>
|
||||
{list.map(item => (
|
||||
<Tag key={item.id} color="blue">{item.propertyName}</Tag>
|
||||
))}
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '指令列表',
|
||||
width: 300,
|
||||
render: (record) => {
|
||||
const list = record.supportActions || [];
|
||||
if (list.length === 0) return <span style={{ color: '#999' }}>无指令</span>;
|
||||
return (
|
||||
<Space size={[4, 4]} wrap>
|
||||
{list.map(item => (
|
||||
<Tag key={item.id} color="green">{item.actionName}</Tag>
|
||||
))}
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
render: r => (
|
||||
<Space>
|
||||
<Button type="text" icon={<EditOutlined />} onClick={() => openModal('model', r)}>编辑</Button>
|
||||
|
||||
{/* 增加删除按钮 + 确认框 */}
|
||||
<Popconfirm
|
||||
title="确定要删除该物模型吗?"
|
||||
onConfirm={() => handleDeleteModel(r.id)}
|
||||
okText="确定"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
}];
|
||||
|
||||
return (
|
||||
<div className="p-5 bg-[#f5f7fa] min-h-screen">
|
||||
|
||||
183
src/components/SystemSetting/DeviceManagement.tsx
Normal file
183
src/components/SystemSetting/DeviceManagement.tsx
Normal file
@@ -0,0 +1,183 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Table,
|
||||
Input,
|
||||
Button,
|
||||
Form,
|
||||
Select,
|
||||
Space,
|
||||
Tag,
|
||||
message,
|
||||
Modal,
|
||||
Tabs,
|
||||
} from 'antd';
|
||||
import {
|
||||
SearchOutlined,
|
||||
ReloadOutlined,
|
||||
PlusOutlined,
|
||||
EditOutlined,
|
||||
DeleteOutlined,
|
||||
} from '@ant-design/icons';
|
||||
|
||||
// 模拟数据
|
||||
const allDeviceList = [
|
||||
{ id: 1, code: 'CAM-01', name: '摄像头 CAM-01', type: 'CAMERA', online: 'ONLINE', status: 'NORMAL' },
|
||||
{ id: 2, code: 'CAM-02', name: '摄像头 CAM-02', type: 'CAMERA', online: 'OFFLINE', status: 'FAULT' },
|
||||
{ id: 3, code: 'CAM-03', name: '摄像头 CAM-03', type: 'CAMERA', online: 'ONLINE', status: 'NORMAL' },
|
||||
{ id: 4, code: 'CLEAN-01', name: '清洗机器人 CLEAN-01', type: 'CLEANING_DEVICE', online: 'ONLINE', status: 'IDLE' },
|
||||
{ id: 5, code: 'CMB-A01', name: '汇流箱 CMB-A01', type: 'COMBINER_BOX', online: 'ONLINE', status: 'WARNING' },
|
||||
{ id: 6, code: 'CMB-A02', name: '汇流箱 CMB-A02', type: 'COMBINER_BOX', online: 'ONLINE', status: 'NORMAL' },
|
||||
{ id: 7, code: 'INV-A01', name: '逆变器 INV-A01', type: 'INVERTER', online: 'ONLINE', status: 'NORMAL' },
|
||||
{ id: 8, code: 'INV-A02', name: '逆变器 INV-A02', type: 'INVERTER', online: 'ONLINE', status: 'WARNING' },
|
||||
{ id: 9, code: 'INV-B01', name: '逆变器 INV-B01', type: 'INVERTER', online: 'ONLINE', status: 'NORMAL' },
|
||||
{ id: 10, code: 'METER-01', name: '电表 METER-01', type: 'METER', online: 'ONLINE', status: 'NORMAL' },
|
||||
{ id: 11, code: 'ROBOT-01', name: '运维机器人 ROBOT-01', type: 'ROBOT', online: 'ONLINE', status: 'IDLE' },
|
||||
{ id: 12, code: 'DRONE-01', name: '无人机 DRONE-01', type: 'DRONE', online: 'OFFLINE', status: 'FAULT' },
|
||||
{ id: 13, code: 'WEATHER-01', name: '气象站 WEATHER-01', type: 'WEATHER_STATION', online: 'ONLINE', status: 'NORMAL' },
|
||||
];
|
||||
|
||||
// Tab 配置
|
||||
const tabs = [
|
||||
{ key: 'all', label: '设备管理', filter: () => true },
|
||||
{ key: 'camera', label: '摄像头管理', filter: (item) => item.type === 'CAMERA' },
|
||||
{ key: 'smart', label: '智能装备', filter: (item) => ['CLEANING_DEVICE', 'ROBOT', 'DRONE'].includes(item.type) },
|
||||
];
|
||||
|
||||
export default function DeviceManagementPage() {
|
||||
const [activeTab, setActiveTab] = useState('all');
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [deviceList, setDeviceList] = useState(allDeviceList);
|
||||
|
||||
// 根据 Tab 过滤数据
|
||||
const filteredByTab = deviceList.filter(tabs.find(t => t.key === activeTab).filter);
|
||||
|
||||
// 表格列定义
|
||||
const columns = [
|
||||
{ title: '设备编码', dataIndex: 'code', key: 'code' },
|
||||
{ title: '设备名称', dataIndex: 'name', key: 'name' },
|
||||
{ title: '类型', dataIndex: 'type', key: 'type' },
|
||||
{
|
||||
title: '在线',
|
||||
dataIndex: 'online',
|
||||
key: 'online',
|
||||
render: (text) => (
|
||||
<Tag color={text === 'ONLINE' ? 'green' : 'red'}>{text}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '运行',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
render: (text) => {
|
||||
const colorMap = {
|
||||
NORMAL: 'green',
|
||||
FAULT: 'red',
|
||||
WARNING: 'orange',
|
||||
IDLE: 'blue',
|
||||
};
|
||||
return <Tag color={colorMap[text] || 'default'}>{text}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Button type="link" icon={<EditOutlined />} onClick={() => handleEdit(record)}>编辑</Button>
|
||||
<Button type="link" danger icon={<DeleteOutlined />} onClick={() => handleDelete(record)}>删除</Button>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
// 查询
|
||||
const handleSearch = () => {
|
||||
form.validateFields().then(values => {
|
||||
const keyword = values.keyword?.toLowerCase() || '';
|
||||
setLoading(true);
|
||||
setTimeout(() => {
|
||||
const filtered = allDeviceList.filter(item =>
|
||||
item.name.toLowerCase().includes(keyword) || item.code.toLowerCase().includes(keyword)
|
||||
);
|
||||
setDeviceList(filtered);
|
||||
setLoading(false);
|
||||
}, 300);
|
||||
});
|
||||
};
|
||||
|
||||
// 重置
|
||||
const handleReset = () => {
|
||||
form.resetFields();
|
||||
setDeviceList(allDeviceList);
|
||||
};
|
||||
|
||||
// 新增
|
||||
const handleAdd = () => {
|
||||
message.info('打开新增设备弹窗');
|
||||
};
|
||||
|
||||
// 编辑
|
||||
const handleEdit = (record) => {
|
||||
message.info(`编辑设备:${record.name}`);
|
||||
};
|
||||
|
||||
// 删除
|
||||
const handleDelete = (record) => {
|
||||
Modal.confirm({
|
||||
title: '确认删除',
|
||||
content: `确定要删除设备 ${record.name} 吗?`,
|
||||
onOk: () => {
|
||||
message.success(`设备 ${record.name} 已删除`);
|
||||
setDeviceList(prev => prev.filter(item => item.id !== record.id));
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24 }}>
|
||||
<Tabs
|
||||
activeKey={activeTab}
|
||||
onChange={setActiveTab}
|
||||
style={{ marginBottom: 16 }}
|
||||
>
|
||||
<Tabs.TabPane key="all" tab="设备管理" />
|
||||
<Tabs.TabPane key="camera" tab="摄像头管理" />
|
||||
<Tabs.TabPane key="smart" tab="智能装备" />
|
||||
</Tabs>
|
||||
|
||||
{/* 筛选栏 */}
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Form form={form} layout="inline">
|
||||
<Form.Item name="keyword">
|
||||
<Input placeholder="请输入设备名称" style={{ width: 220 }} />
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" icon={<SearchOutlined />} onClick={handleSearch}>查询</Button>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button icon={<ReloadOutlined />} onClick={handleReset}>重置</Button>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>新增</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
{/* 表格 */}
|
||||
<Table
|
||||
rowKey="id"
|
||||
columns={columns}
|
||||
dataSource={filteredByTab}
|
||||
loading={loading}
|
||||
pagination={{
|
||||
total: filteredByTab.length,
|
||||
pageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total) => `共 ${total} 条`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user