feat:设备运维ops管理模块功能新增
This commit is contained in:
@@ -184,6 +184,44 @@
|
||||
icon: 'VideoCameraOutlined',
|
||||
component: './orders/EditTask',
|
||||
},
|
||||
{
|
||||
path: '/device-ops',
|
||||
name: '设备运维',
|
||||
icon: 'monitor',
|
||||
routes: [
|
||||
{
|
||||
path: '/device-ops/device.html',
|
||||
name: '设备管理',
|
||||
component: './device-ops/device',
|
||||
},
|
||||
{
|
||||
path: '/device-ops/device/:id',
|
||||
name: '设备详情',
|
||||
component: './device-ops/device/detail',
|
||||
hideInMenu: true,
|
||||
},
|
||||
{
|
||||
path: '/device-ops/group.html',
|
||||
name: '分组管理',
|
||||
component: './device-ops/group',
|
||||
},
|
||||
{
|
||||
path: '/device-ops/maintenance.html',
|
||||
name: '运维管理',
|
||||
component: './device-ops/maintenance',
|
||||
},
|
||||
{
|
||||
path: '/device-ops/monitor.html',
|
||||
name: '设备监控',
|
||||
component: './device-ops/monitor',
|
||||
},
|
||||
{
|
||||
path: '/device-ops/statistics.html',
|
||||
name: '统计分析',
|
||||
component: './device-ops/statistics',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
component: './404',
|
||||
},
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
import React, { useState } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import { Card, Row, Col, Descriptions, Tag, Timeline, Table, Statistic } from 'antd';
|
||||
import { Line } from '@ant-design/plots';
|
||||
import { useParams } from 'umi';
|
||||
|
||||
interface DeviceDetail {
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
status: string;
|
||||
model: string;
|
||||
serialNumber: string;
|
||||
location: string;
|
||||
installDate: string;
|
||||
lastMaintenance: string;
|
||||
nextMaintenance: string;
|
||||
manufacturer: string;
|
||||
specifications: string;
|
||||
}
|
||||
|
||||
interface MaintenanceRecord {
|
||||
id: string;
|
||||
date: string;
|
||||
type: string;
|
||||
operator: string;
|
||||
description: string;
|
||||
result: string;
|
||||
}
|
||||
|
||||
interface AlertRecord {
|
||||
id: string;
|
||||
time: string;
|
||||
type: string;
|
||||
level: string;
|
||||
message: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
const mockDeviceDetail: DeviceDetail = {
|
||||
id: '1',
|
||||
name: '设备A',
|
||||
type: '传感器',
|
||||
status: '在线',
|
||||
model: 'SENSOR-2024',
|
||||
serialNumber: 'SN20240320001',
|
||||
location: '1号车间',
|
||||
installDate: '2024-01-15',
|
||||
lastMaintenance: '2024-02-15',
|
||||
nextMaintenance: '2024-04-15',
|
||||
manufacturer: '某某科技',
|
||||
specifications: '温度范围:-20℃~80℃,精度:±0.1℃',
|
||||
};
|
||||
|
||||
const mockMaintenanceRecords: MaintenanceRecord[] = [
|
||||
{
|
||||
id: '1',
|
||||
date: '2024-02-15',
|
||||
type: '定期保养',
|
||||
operator: '张三',
|
||||
description: '更换滤芯,校准参数',
|
||||
result: '正常',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
date: '2024-01-15',
|
||||
type: '安装调试',
|
||||
operator: '李四',
|
||||
description: '设备安装及初始调试',
|
||||
result: '正常',
|
||||
},
|
||||
];
|
||||
|
||||
const mockAlertRecords: AlertRecord[] = [
|
||||
{
|
||||
id: '1',
|
||||
time: '2024-03-20 09:30:00',
|
||||
type: '温度告警',
|
||||
level: '高',
|
||||
message: '设备温度超过阈值',
|
||||
status: '已处理',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
time: '2024-03-19 15:20:00',
|
||||
type: '通信告警',
|
||||
level: '中',
|
||||
message: '设备通信中断',
|
||||
status: '已处理',
|
||||
},
|
||||
];
|
||||
|
||||
// 模拟性能数据
|
||||
const generatePerformanceData = () => {
|
||||
const data = [];
|
||||
for (let i = 0; i < 24; i++) {
|
||||
data.push({
|
||||
time: `${i}:00`,
|
||||
value: Math.floor(Math.random() * 100),
|
||||
type: 'CPU使用率',
|
||||
});
|
||||
data.push({
|
||||
time: `${i}:00`,
|
||||
value: Math.floor(Math.random() * 100),
|
||||
type: '内存使用率',
|
||||
});
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
const DeviceDetailPage: React.FC = () => {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const [deviceDetail] = useState<DeviceDetail>(mockDeviceDetail);
|
||||
const [maintenanceRecords] = useState<MaintenanceRecord[]>(mockMaintenanceRecords);
|
||||
const [alertRecords] = useState<AlertRecord[]>(mockAlertRecords);
|
||||
const [performanceData] = useState(generatePerformanceData());
|
||||
|
||||
const getStatusColor = (status: string) => {
|
||||
return status === '在线' ? 'green' : 'red';
|
||||
};
|
||||
|
||||
const getAlertLevelColor = (level: string) => {
|
||||
const colorMap: { [key: string]: string } = {
|
||||
'高': 'red',
|
||||
'中': 'orange',
|
||||
'低': 'blue',
|
||||
};
|
||||
return colorMap[level] || 'default';
|
||||
};
|
||||
|
||||
const maintenanceColumns = [
|
||||
{ title: '日期', dataIndex: 'date' },
|
||||
{ title: '类型', dataIndex: 'type' },
|
||||
{ title: '操作人', dataIndex: 'operator' },
|
||||
{ title: '描述', dataIndex: 'description' },
|
||||
{ title: '结果', dataIndex: 'result' },
|
||||
];
|
||||
|
||||
const alertColumns = [
|
||||
{ title: '时间', dataIndex: 'time' },
|
||||
{ title: '类型', dataIndex: 'type' },
|
||||
{
|
||||
title: '级别',
|
||||
dataIndex: 'level',
|
||||
render: (level: string) => (
|
||||
<Tag color={getAlertLevelColor(level)}>{level}</Tag>
|
||||
),
|
||||
},
|
||||
{ title: '信息', dataIndex: 'message' },
|
||||
{ title: '状态', dataIndex: 'status' },
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={24}>
|
||||
<Card title="设备基本信息">
|
||||
<Descriptions bordered>
|
||||
<Descriptions.Item label="设备名称">{deviceDetail.name}</Descriptions.Item>
|
||||
<Descriptions.Item label="设备类型">{deviceDetail.type}</Descriptions.Item>
|
||||
<Descriptions.Item label="设备状态">
|
||||
<Tag color={getStatusColor(deviceDetail.status)}>{deviceDetail.status}</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="设备型号">{deviceDetail.model}</Descriptions.Item>
|
||||
<Descriptions.Item label="序列号">{deviceDetail.serialNumber}</Descriptions.Item>
|
||||
<Descriptions.Item label="安装位置">{deviceDetail.location}</Descriptions.Item>
|
||||
<Descriptions.Item label="安装日期">{deviceDetail.installDate}</Descriptions.Item>
|
||||
<Descriptions.Item label="上次维护">{deviceDetail.lastMaintenance}</Descriptions.Item>
|
||||
<Descriptions.Item label="下次维护">{deviceDetail.nextMaintenance}</Descriptions.Item>
|
||||
<Descriptions.Item label="制造商">{deviceDetail.manufacturer}</Descriptions.Item>
|
||||
<Descriptions.Item label="规格参数">{deviceDetail.specifications}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="运行时长"
|
||||
value={45}
|
||||
suffix="天"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="告警次数"
|
||||
value={alertRecords.length}
|
||||
valueStyle={{ color: alertRecords.length > 0 ? '#cf1322' : '#3f8600' }}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="维护次数"
|
||||
value={maintenanceRecords.length}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Card title="性能监控" style={{ marginTop: 16 }}>
|
||||
<Line
|
||||
data={performanceData}
|
||||
xField="time"
|
||||
yField="value"
|
||||
seriesField="type"
|
||||
smooth
|
||||
animation={{
|
||||
appear: {
|
||||
animation: 'path-in',
|
||||
duration: 1000,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
||||
<Col span={12}>
|
||||
<Card title="维护记录">
|
||||
<Table
|
||||
dataSource={maintenanceRecords}
|
||||
columns={maintenanceColumns}
|
||||
rowKey="id"
|
||||
pagination={false}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Card title="告警记录">
|
||||
<Table
|
||||
dataSource={alertRecords}
|
||||
columns={alertColumns}
|
||||
rowKey="id"
|
||||
pagination={false}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceDetailPage;
|
||||
@@ -0,0 +1,470 @@
|
||||
import React, { useRef, useState, useEffect } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import { ProTable, ProColumns, ModalForm, ProFormText, ProFormSelect, ProFormUploadButton } from '@ant-design/pro-components';
|
||||
import { Button, Space, message, Popconfirm, Tag, Select, Modal, Dropdown, Menu, Upload, Card, Row, Col, Statistic } from 'antd';
|
||||
import { history } from 'umi';
|
||||
import { DownOutlined, UploadOutlined, DownloadOutlined, FileExcelOutlined, CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';
|
||||
import type { UploadFile } from 'antd/es/upload/interface';
|
||||
import * as XLSX from 'xlsx';
|
||||
import { Pie, Column } from '@ant-design/plots';
|
||||
import { device, saveOrUpdateDevice, deleteDevice } from '@/services/device/api';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
interface Device {
|
||||
deviceSn: string;
|
||||
deviceName: string;
|
||||
nickname: string;
|
||||
deviceType: number;
|
||||
firmwareVersion: string;
|
||||
compatibleStatus: number;
|
||||
boundStatus: number;
|
||||
createTime: string;
|
||||
loginTime: string;
|
||||
}
|
||||
|
||||
const DEVICE_TYPE = {
|
||||
DOCK: 1,
|
||||
DRONE: 2,
|
||||
REMOTE_CONTROL: 3,
|
||||
} as const;
|
||||
|
||||
const DEVICE_TYPE_OPTIONS = [
|
||||
{ label: '机场', value: DEVICE_TYPE.DOCK },
|
||||
{ label: '无人机', value: DEVICE_TYPE.DRONE },
|
||||
{ label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL },
|
||||
];
|
||||
|
||||
const COMPATIBLE_STATUS = {
|
||||
INCONSISTENT: 0,
|
||||
CONSISTENT: 1,
|
||||
} as const;
|
||||
|
||||
const DeviceList: React.FC = () => {
|
||||
const [createModalVisible, setCreateModalVisible] = useState(false);
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [currentRow, setCurrentRow] = useState<Device>();
|
||||
const [selectedGroup, setSelectedGroup] = useState<string>('all');
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
||||
const [batchGroupModalVisible, setBatchGroupModalVisible] = useState(false);
|
||||
const [batchStatusModalVisible, setBatchStatusModalVisible] = useState(false);
|
||||
const [importModalVisible, setImportModalVisible] = useState(false);
|
||||
const [importFileList, setImportFileList] = useState<UploadFile[]>([]);
|
||||
const [statistics, setStatistics] = useState({
|
||||
total: 0,
|
||||
online: 0,
|
||||
offline: 0,
|
||||
byType: {} as Record<string, number>,
|
||||
});
|
||||
const actionRef = useRef<any>();
|
||||
|
||||
// 计算统计数据
|
||||
const calculateStatistics = (data: Device[]) => {
|
||||
const stats = {
|
||||
total: data.length,
|
||||
online: data.filter(item => item.boundStatus === 1).length,
|
||||
offline: data.filter(item => item.boundStatus === 0).length,
|
||||
byType: {} as Record<string, number>,
|
||||
};
|
||||
|
||||
// 按类型统计
|
||||
data.forEach(item => {
|
||||
const typeName = DEVICE_TYPE_OPTIONS.find(opt => opt.value === item.deviceType)?.label || '未知';
|
||||
stats.byType[typeName] = (stats.byType[typeName] || 0) + 1;
|
||||
});
|
||||
|
||||
return stats;
|
||||
};
|
||||
|
||||
const handleAdd = async (values: any) => {
|
||||
try {
|
||||
const response = await saveOrUpdateDevice({
|
||||
...values,
|
||||
deviceType: Number(values.deviceType),
|
||||
});
|
||||
if (response.resp_code === 0) {
|
||||
message.success('新增成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
message.error(response.resp_msg || '新增失败');
|
||||
return false;
|
||||
} catch (error) {
|
||||
message.error('新增失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = async (values: any) => {
|
||||
try {
|
||||
const response = await saveOrUpdateDevice({
|
||||
...values,
|
||||
deviceType: Number(values.deviceType),
|
||||
});
|
||||
if (response.resp_code === 0) {
|
||||
message.success('编辑成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
message.error(response.resp_msg || '编辑失败');
|
||||
return false;
|
||||
} catch (error) {
|
||||
message.error('编辑失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (deviceSn: string) => {
|
||||
try {
|
||||
const response = await deleteDevice(deviceSn);
|
||||
if (response.resp_code === 0) {
|
||||
message.success('删除成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
} else {
|
||||
message.error(response.resp_msg || '删除失败');
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleBatchDelete = async () => {
|
||||
if (selectedRowKeys.length === 0) {
|
||||
message.warning('请选择要删除的设备');
|
||||
return;
|
||||
}
|
||||
Modal.confirm({
|
||||
title: '批量删除',
|
||||
content: `确定要删除选中的 ${selectedRowKeys.length} 个设备吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
const promises = selectedRowKeys.map(key => deleteDevice(key));
|
||||
await Promise.all(promises);
|
||||
message.success('批量删除成功');
|
||||
setSelectedRowKeys([]);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('批量删除失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const columns: ProColumns<Device>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
},
|
||||
{
|
||||
title: '设备序列号',
|
||||
dataIndex: 'deviceSn',
|
||||
copyable: true,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
title: '设备名称',
|
||||
dataIndex: 'deviceName',
|
||||
},
|
||||
{
|
||||
title: '昵称',
|
||||
dataIndex: 'nickname',
|
||||
},
|
||||
{
|
||||
title: '设备类型',
|
||||
dataIndex: 'deviceType',
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
[DEVICE_TYPE.DOCK]: { text: '机场' },
|
||||
[DEVICE_TYPE.DRONE]: { text: '无人机' },
|
||||
[DEVICE_TYPE.REMOTE_CONTROL]: { text: '遥控器' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '固件版本',
|
||||
dataIndex: 'firmwareVersion',
|
||||
},
|
||||
{
|
||||
title: '固件状态',
|
||||
dataIndex: 'compatibleStatus',
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
[COMPATIBLE_STATUS.CONSISTENT]: { text: '一致', status: 'Success' },
|
||||
[COMPATIBLE_STATUS.INCONSISTENT]: { text: '不一致', status: 'Error' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '绑定状态',
|
||||
dataIndex: 'boundStatus',
|
||||
render: (_, record) => (
|
||||
<Tag color={record.boundStatus === 1 ? 'green' : 'red'}>
|
||||
{record.boundStatus === 1 ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
|
||||
{record.boundStatus === 1 ? '已绑定' : '未绑定'}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '最后登录',
|
||||
dataIndex: 'loginTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
valueType: 'option',
|
||||
render: (_, record) => [
|
||||
<a
|
||||
key="edit"
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setEditModalVisible(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</a>,
|
||||
<Popconfirm
|
||||
key="delete"
|
||||
title="确定要删除这个设备吗?"
|
||||
onConfirm={() => handleDelete(record.deviceSn)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>,
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
{/* 统计卡片 */}
|
||||
<Row gutter={16} style={{ marginBottom: 24 }}>
|
||||
<Col span={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="设备总数"
|
||||
value={statistics.total}
|
||||
suffix="台"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="在线设备"
|
||||
value={statistics.online}
|
||||
suffix="台"
|
||||
valueStyle={{ color: '#3f8600' }}
|
||||
prefix={<CheckCircleOutlined />}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="离线设备"
|
||||
value={statistics.offline}
|
||||
suffix="台"
|
||||
valueStyle={{ color: '#cf1322' }}
|
||||
prefix={<CloseCircleOutlined />}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="设备类型数"
|
||||
value={Object.keys(statistics.byType).length}
|
||||
suffix="种"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<ProTable<Device>
|
||||
headerTitle="设备管理"
|
||||
actionRef={actionRef}
|
||||
rowKey="deviceSn"
|
||||
search={{
|
||||
labelWidth: 120,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
key="button"
|
||||
icon={<DownloadOutlined />}
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
// 导出功能待实现
|
||||
message.info('导出功能开发中');
|
||||
}}
|
||||
>
|
||||
导出
|
||||
</Button>,
|
||||
<Button
|
||||
key="button"
|
||||
icon={<UploadOutlined />}
|
||||
onClick={() => {
|
||||
setImportModalVisible(true);
|
||||
}}
|
||||
>
|
||||
导入
|
||||
</Button>,
|
||||
<Button
|
||||
key="button"
|
||||
icon={<FileExcelOutlined />}
|
||||
onClick={() => {
|
||||
// 下载模板功能待实现
|
||||
message.info('下载模板功能开发中');
|
||||
}}
|
||||
>
|
||||
下载模板
|
||||
</Button>,
|
||||
<Button
|
||||
key="button"
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
setCreateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
新增
|
||||
</Button>,
|
||||
]}
|
||||
request={async (params) => {
|
||||
const response = await device({
|
||||
page: params.current,
|
||||
limit: params.pageSize,
|
||||
searchKey: params.searchKey,
|
||||
searchValue: params.searchValue,
|
||||
});
|
||||
|
||||
if (response.resp_code === 0) {
|
||||
const data = response.data || [];
|
||||
setStatistics(calculateStatistics(data));
|
||||
return {
|
||||
data,
|
||||
success: true,
|
||||
total: response.count || 0,
|
||||
};
|
||||
}
|
||||
return {
|
||||
data: [],
|
||||
success: false,
|
||||
total: 0,
|
||||
};
|
||||
}}
|
||||
columns={columns}
|
||||
rowSelection={{
|
||||
selectedRowKeys,
|
||||
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
||||
}}
|
||||
/>
|
||||
|
||||
<ModalForm
|
||||
title="新增设备"
|
||||
width="400px"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={setCreateModalVisible}
|
||||
onFinish={handleAdd}
|
||||
>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入设备序列号' }]}
|
||||
label="设备序列号"
|
||||
name="deviceSn"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入设备名称' }]}
|
||||
label="设备名称"
|
||||
name="deviceName"
|
||||
/>
|
||||
<ProFormText
|
||||
label="昵称"
|
||||
name="nickname"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '请选择设备类型' }]}
|
||||
label="设备类型"
|
||||
name="deviceType"
|
||||
options={DEVICE_TYPE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
label="固件版本"
|
||||
name="firmwareVersion"
|
||||
/>
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title="编辑设备"
|
||||
width="400px"
|
||||
visible={editModalVisible}
|
||||
onVisibleChange={setEditModalVisible}
|
||||
onFinish={handleEdit}
|
||||
initialValues={currentRow}
|
||||
>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入设备序列号' }]}
|
||||
label="设备序列号"
|
||||
name="deviceSn"
|
||||
disabled
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入设备名称' }]}
|
||||
label="设备名称"
|
||||
name="deviceName"
|
||||
/>
|
||||
<ProFormText
|
||||
label="昵称"
|
||||
name="nickname"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '请选择设备类型' }]}
|
||||
label="设备类型"
|
||||
name="deviceType"
|
||||
options={DEVICE_TYPE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
label="固件版本"
|
||||
name="firmwareVersion"
|
||||
/>
|
||||
</ModalForm>
|
||||
|
||||
<Modal
|
||||
title="导入设备"
|
||||
visible={importModalVisible}
|
||||
onCancel={() => setImportModalVisible(false)}
|
||||
footer={null}
|
||||
>
|
||||
<Upload
|
||||
fileList={importFileList}
|
||||
onChange={({ fileList }) => setImportFileList(fileList)}
|
||||
beforeUpload={() => false}
|
||||
>
|
||||
<Button icon={<UploadOutlined />}>选择文件</Button>
|
||||
</Upload>
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
// 导入功能待实现
|
||||
message.info('导入功能开发中');
|
||||
setImportModalVisible(false);
|
||||
}}
|
||||
>
|
||||
开始导入
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceList;
|
||||
@@ -0,0 +1,299 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import { ProTable, ProColumns, ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-components';
|
||||
import { Button, Space, message, Popconfirm, Tag, Card, Row, Col, Statistic } from 'antd';
|
||||
import { Pie } from '@ant-design/plots';
|
||||
import { device } from '@/services/device/api';
|
||||
|
||||
interface Device {
|
||||
deviceSn: string;
|
||||
deviceName: string;
|
||||
deviceType: number;
|
||||
boundStatus: number;
|
||||
createTime: string;
|
||||
loginTime: string;
|
||||
}
|
||||
|
||||
interface DeviceGroup {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
deviceCount: number;
|
||||
createTime: string;
|
||||
}
|
||||
|
||||
const DEVICE_TYPE = {
|
||||
DOCK: 1,
|
||||
DRONE: 2,
|
||||
REMOTE_CONTROL: 3,
|
||||
} as const;
|
||||
|
||||
const DEVICE_TYPE_OPTIONS = [
|
||||
{ label: '机场', value: DEVICE_TYPE.DOCK },
|
||||
{ label: '无人机', value: DEVICE_TYPE.DRONE },
|
||||
{ label: '遥控器', value: DEVICE_TYPE.REMOTE_CONTROL },
|
||||
];
|
||||
|
||||
const DeviceGroup: React.FC = () => {
|
||||
const [createModalVisible, setCreateModalVisible] = useState(false);
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [currentRow, setCurrentRow] = useState<DeviceGroup>();
|
||||
const [deviceList, setDeviceList] = useState<Device[]>([]);
|
||||
const [statistics, setStatistics] = useState({
|
||||
totalGroups: 0,
|
||||
totalDevices: 0,
|
||||
byType: {} as Record<string, number>,
|
||||
});
|
||||
const actionRef = useRef<any>();
|
||||
|
||||
// 获取设备列表
|
||||
const fetchDeviceList = async () => {
|
||||
try {
|
||||
const response = await device({
|
||||
page: 1,
|
||||
limit: 1000,
|
||||
});
|
||||
if (response.resp_code === 0) {
|
||||
const data = response.data || [];
|
||||
setDeviceList(data);
|
||||
|
||||
// 计算统计数据
|
||||
const stats = {
|
||||
totalGroups: 0, // 待实现
|
||||
totalDevices: data.length,
|
||||
byType: {} as Record<string, number>,
|
||||
};
|
||||
|
||||
// 按类型统计
|
||||
data.forEach((item: Device) => {
|
||||
const typeName = DEVICE_TYPE_OPTIONS.find(opt => opt.value === item.deviceType)?.label || '未知';
|
||||
stats.byType[typeName] = (stats.byType[typeName] || 0) + 1;
|
||||
});
|
||||
|
||||
setStatistics(stats);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAdd = async (values: any) => {
|
||||
try {
|
||||
// 待实现:调用创建分组API
|
||||
message.success('新增成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
message.error('新增失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = async (values: any) => {
|
||||
try {
|
||||
// 待实现:调用更新分组API
|
||||
message.success('编辑成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
message.error('编辑失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
try {
|
||||
// 待实现:调用删除分组API
|
||||
message.success('删除成功');
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const columns: ProColumns<DeviceGroup>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
},
|
||||
{
|
||||
title: '分组名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'description',
|
||||
},
|
||||
{
|
||||
title: '设备数量',
|
||||
dataIndex: 'deviceCount',
|
||||
sorter: (a, b) => a.deviceCount - b.deviceCount,
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
valueType: 'option',
|
||||
render: (_, record) => [
|
||||
<a
|
||||
key="edit"
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setEditModalVisible(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</a>,
|
||||
<Popconfirm
|
||||
key="delete"
|
||||
title="确定要删除这个分组吗?"
|
||||
onConfirm={() => handleDelete(record.id)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>,
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
// 准备图表数据
|
||||
const typeChartData = Object.entries(statistics.byType).map(([type, count]) => ({
|
||||
type,
|
||||
value: count,
|
||||
}));
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
{/* 统计卡片 */}
|
||||
<Row gutter={16} style={{ marginBottom: 24 }}>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="分组总数"
|
||||
value={statistics.totalGroups}
|
||||
suffix="个"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="设备总数"
|
||||
value={statistics.totalDevices}
|
||||
suffix="台"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="设备类型数"
|
||||
value={Object.keys(statistics.byType).length}
|
||||
suffix="种"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 设备类型分布图 */}
|
||||
<Row gutter={16} style={{ marginBottom: 24 }}>
|
||||
<Col span={24}>
|
||||
<Card title="设备类型分布">
|
||||
<Pie
|
||||
data={typeChartData}
|
||||
angleField="value"
|
||||
colorField="type"
|
||||
radius={0.8}
|
||||
label={{
|
||||
type: 'outer',
|
||||
content: '{name} {percentage}',
|
||||
}}
|
||||
interactions={[
|
||||
{
|
||||
type: 'element-active',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<ProTable<DeviceGroup>
|
||||
headerTitle="设备分组"
|
||||
actionRef={actionRef}
|
||||
rowKey="id"
|
||||
search={{
|
||||
labelWidth: 120,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
key="button"
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
setCreateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
新增分组
|
||||
</Button>,
|
||||
]}
|
||||
request={async (params) => {
|
||||
// 待实现:调用获取分组列表API
|
||||
return {
|
||||
data: [],
|
||||
success: true,
|
||||
total: 0,
|
||||
};
|
||||
}}
|
||||
columns={columns}
|
||||
/>
|
||||
|
||||
<ModalForm
|
||||
title="新增分组"
|
||||
width="400px"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={setCreateModalVisible}
|
||||
onFinish={handleAdd}
|
||||
>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入分组名称' }]}
|
||||
label="分组名称"
|
||||
name="name"
|
||||
/>
|
||||
<ProFormText
|
||||
label="描述"
|
||||
name="description"
|
||||
/>
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title="编辑分组"
|
||||
width="400px"
|
||||
visible={editModalVisible}
|
||||
onVisibleChange={setEditModalVisible}
|
||||
onFinish={handleEdit}
|
||||
initialValues={currentRow}
|
||||
>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '请输入分组名称' }]}
|
||||
label="分组名称"
|
||||
name="name"
|
||||
/>
|
||||
<ProFormText
|
||||
label="描述"
|
||||
name="description"
|
||||
/>
|
||||
</ModalForm>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceGroup;
|
||||
@@ -0,0 +1,275 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import { ProTable, ProColumns, ModalForm, ProFormText, ProFormSelect, ProFormDatePicker } from '@ant-design/pro-components';
|
||||
import { Button, Space, message, Popconfirm, Tag } from 'antd';
|
||||
|
||||
interface MaintenanceTask {
|
||||
id: string;
|
||||
deviceName: string;
|
||||
taskType: string;
|
||||
status: string;
|
||||
priority: string;
|
||||
assignee: string;
|
||||
startTime: string;
|
||||
endTime?: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
const TASK_TYPE_OPTIONS = [
|
||||
{ label: '日常巡检', value: '日常巡检' },
|
||||
{ label: '故障维修', value: '故障维修' },
|
||||
{ label: '设备保养', value: '设备保养' },
|
||||
{ label: '系统升级', value: '系统升级' },
|
||||
];
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ label: '待处理', value: '待处理' },
|
||||
{ label: '进行中', value: '进行中' },
|
||||
{ label: '已完成', value: '已完成' },
|
||||
{ label: '已取消', value: '已取消' },
|
||||
];
|
||||
|
||||
const PRIORITY_OPTIONS = [
|
||||
{ label: '高', value: '高' },
|
||||
{ label: '中', value: '中' },
|
||||
{ label: '低', value: '低' },
|
||||
];
|
||||
|
||||
const initialMockData: MaintenanceTask[] = [
|
||||
{
|
||||
id: '1',
|
||||
deviceName: '设备A',
|
||||
taskType: '日常巡检',
|
||||
status: '待处理',
|
||||
priority: '高',
|
||||
assignee: '张三',
|
||||
startTime: '2024-03-20 10:00:00',
|
||||
description: '定期设备巡检',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
deviceName: '设备B',
|
||||
taskType: '故障维修',
|
||||
status: '进行中',
|
||||
priority: '高',
|
||||
assignee: '李四',
|
||||
startTime: '2024-03-19 14:30:00',
|
||||
description: '设备异常报警处理',
|
||||
},
|
||||
];
|
||||
|
||||
const MaintenanceList: React.FC = () => {
|
||||
const [data, setData] = useState<MaintenanceTask[]>(initialMockData);
|
||||
const [createModalVisible, setCreateModalVisible] = useState(false);
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [currentRow, setCurrentRow] = useState<MaintenanceTask | undefined>();
|
||||
const actionRef = useRef<any>();
|
||||
|
||||
const handleAdd = async (values: MaintenanceTask) => {
|
||||
setData([...data, { ...values, id: Date.now().toString() }]);
|
||||
message.success('新增成功');
|
||||
return true;
|
||||
};
|
||||
|
||||
const handleEdit = async (values: MaintenanceTask) => {
|
||||
setData(data.map((item) => (item.id === values.id ? { ...item, ...values } : item)));
|
||||
message.success('编辑成功');
|
||||
return true;
|
||||
};
|
||||
|
||||
const handleDelete = async (record: MaintenanceTask) => {
|
||||
setData(data.filter((item) => item.id !== record.id));
|
||||
message.success('删除成功');
|
||||
};
|
||||
|
||||
const getStatusColor = (status: string) => {
|
||||
const colorMap: { [key: string]: string } = {
|
||||
'待处理': 'orange',
|
||||
'进行中': 'blue',
|
||||
'已完成': 'green',
|
||||
'已取消': 'red',
|
||||
};
|
||||
return colorMap[status] || 'default';
|
||||
};
|
||||
|
||||
const getPriorityColor = (priority: string) => {
|
||||
const colorMap: { [key: string]: string } = {
|
||||
'高': 'red',
|
||||
'中': 'orange',
|
||||
'低': 'green',
|
||||
};
|
||||
return colorMap[priority] || 'default';
|
||||
};
|
||||
|
||||
const columns: ProColumns<MaintenanceTask>[] = [
|
||||
{ title: '设备名称', dataIndex: 'deviceName' },
|
||||
{ title: '任务类型', dataIndex: 'taskType' },
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
render: (_, record) => (
|
||||
<Tag color={getStatusColor(record.status)}>{record.status}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '优先级',
|
||||
dataIndex: 'priority',
|
||||
render: (_, record) => (
|
||||
<Tag color={getPriorityColor(record.priority)}>{record.priority}</Tag>
|
||||
),
|
||||
},
|
||||
{ title: '负责人', dataIndex: 'assignee' },
|
||||
{ title: '开始时间', dataIndex: 'startTime' },
|
||||
{ title: '结束时间', dataIndex: 'endTime' },
|
||||
{ title: '描述', dataIndex: 'description', ellipsis: true },
|
||||
{
|
||||
title: '操作',
|
||||
valueType: 'option',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<a
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setEditModalVisible(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</a>
|
||||
<Popconfirm title="确定要删除吗?" onConfirm={() => handleDelete(record)}>
|
||||
<a style={{ color: 'red' }}>删除</a>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<ProTable<MaintenanceTask>
|
||||
headerTitle="运维任务列表"
|
||||
rowKey="id"
|
||||
search={false}
|
||||
dataSource={data}
|
||||
columns={columns}
|
||||
actionRef={actionRef}
|
||||
toolBarRender={() => [
|
||||
<Button type="primary" key="add" onClick={() => setCreateModalVisible(true)}>
|
||||
新增任务
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
{/* 新增任务弹窗 */}
|
||||
<ModalForm
|
||||
title="新增运维任务"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={setCreateModalVisible}
|
||||
onFinish={async (values) => {
|
||||
await handleAdd(values as MaintenanceTask);
|
||||
setCreateModalVisible(false);
|
||||
return true;
|
||||
}}
|
||||
>
|
||||
<ProFormText
|
||||
name="deviceName"
|
||||
label="设备名称"
|
||||
rules={[{ required: true, message: '请输入设备名称' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="taskType"
|
||||
label="任务类型"
|
||||
options={TASK_TYPE_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择任务类型' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
options={STATUS_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="priority"
|
||||
label="优先级"
|
||||
options={PRIORITY_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择优先级' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="assignee"
|
||||
label="负责人"
|
||||
rules={[{ required: true, message: '请输入负责人' }]}
|
||||
/>
|
||||
<ProFormDatePicker
|
||||
name="startTime"
|
||||
label="开始时间"
|
||||
rules={[{ required: true, message: '请选择开始时间' }]}
|
||||
/>
|
||||
<ProFormDatePicker
|
||||
name="endTime"
|
||||
label="结束时间"
|
||||
/>
|
||||
<ProFormText
|
||||
name="description"
|
||||
label="描述"
|
||||
rules={[{ required: true, message: '请输入任务描述' }]}
|
||||
/>
|
||||
</ModalForm>
|
||||
{/* 编辑任务弹窗 */}
|
||||
<ModalForm
|
||||
title="编辑运维任务"
|
||||
visible={editModalVisible}
|
||||
onVisibleChange={setEditModalVisible}
|
||||
initialValues={currentRow}
|
||||
onFinish={async (values) => {
|
||||
await handleEdit({ ...currentRow, ...values } as MaintenanceTask);
|
||||
setEditModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
return true;
|
||||
}}
|
||||
>
|
||||
<ProFormText
|
||||
name="deviceName"
|
||||
label="设备名称"
|
||||
rules={[{ required: true, message: '请输入设备名称' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="taskType"
|
||||
label="任务类型"
|
||||
options={TASK_TYPE_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择任务类型' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
options={STATUS_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="priority"
|
||||
label="优先级"
|
||||
options={PRIORITY_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择优先级' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="assignee"
|
||||
label="负责人"
|
||||
rules={[{ required: true, message: '请输入负责人' }]}
|
||||
/>
|
||||
<ProFormDatePicker
|
||||
name="startTime"
|
||||
label="开始时间"
|
||||
rules={[{ required: true, message: '请选择开始时间' }]}
|
||||
/>
|
||||
<ProFormDatePicker
|
||||
name="endTime"
|
||||
label="结束时间"
|
||||
/>
|
||||
<ProFormText
|
||||
name="description"
|
||||
label="描述"
|
||||
rules={[{ required: true, message: '请输入任务描述' }]}
|
||||
/>
|
||||
</ModalForm>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default MaintenanceList;
|
||||
@@ -0,0 +1,44 @@
|
||||
import { getDeviceList } from '../services/api';
|
||||
|
||||
export interface Device {
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
status: string;
|
||||
group?: string;
|
||||
}
|
||||
|
||||
export interface DeviceModelState {
|
||||
deviceList: Device[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
const DeviceModel = {
|
||||
namespace: 'deviceOpsDevice',
|
||||
state: {
|
||||
deviceList: [],
|
||||
total: 0,
|
||||
},
|
||||
effects: {
|
||||
*fetchDeviceList({ payload }: any, { call, put }: any): any {
|
||||
const response = yield call(getDeviceList, payload);
|
||||
yield put({
|
||||
type: 'saveDeviceList',
|
||||
payload: {
|
||||
deviceList: response?.data?.records || [],
|
||||
total: response?.data?.total || 0,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
reducers: {
|
||||
saveDeviceList(state: any, { payload }: any): any {
|
||||
return {
|
||||
...state,
|
||||
...payload,
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default DeviceModel;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
// 设备列表
|
||||
export async function getDeviceList(params?: any) {
|
||||
return request('/api/device-ops/device/list', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 新增设备
|
||||
export async function addDevice(data: any) {
|
||||
return request('/api/device-ops/device', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
// 编辑设备
|
||||
export async function updateDevice(data: any) {
|
||||
return request('/api/device-ops/device', {
|
||||
method: 'PUT',
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
// 删除设备
|
||||
export async function deleteDevice(id: string) {
|
||||
return request(`/api/device-ops/device/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import { Card, Row, Col, DatePicker, Select, Space, Statistic, message } from 'antd';
|
||||
import { Line, Column } from '@ant-design/plots';
|
||||
import moment from 'moment';
|
||||
import { CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';
|
||||
import { device } from '@/services/device/api';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
interface Device {
|
||||
deviceSn: string;
|
||||
deviceName: string;
|
||||
deviceType: number;
|
||||
boundStatus: number;
|
||||
createTime: string;
|
||||
loginTime: string;
|
||||
}
|
||||
|
||||
interface TrendData {
|
||||
date: string;
|
||||
value: number;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface DeviceGrowth {
|
||||
date: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
interface PerformanceData {
|
||||
time: string;
|
||||
value: number;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface StatisticsData {
|
||||
totalDevices: number;
|
||||
averageOnlineRate: number;
|
||||
totalGrowth: number;
|
||||
}
|
||||
|
||||
const DeviceStatistics: React.FC = () => {
|
||||
const [timeRange, setTimeRange] = useState<[moment.Moment, moment.Moment]>([
|
||||
moment().subtract(30, 'days'),
|
||||
moment(),
|
||||
]);
|
||||
const [selectedDevice, setSelectedDevice] = useState<string>('all');
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [deviceList, setDeviceList] = useState<Device[]>([]);
|
||||
const [statusTrendData, setStatusTrendData] = useState<TrendData[]>([]);
|
||||
const [deviceGrowthData, setDeviceGrowthData] = useState<DeviceGrowth[]>([]);
|
||||
const [performanceData, setPerformanceData] = useState<PerformanceData[]>([]);
|
||||
const [statistics, setStatistics] = useState<StatisticsData>({
|
||||
totalDevices: 0,
|
||||
averageOnlineRate: 0,
|
||||
totalGrowth: 0,
|
||||
});
|
||||
|
||||
// 获取设备列表
|
||||
const fetchDeviceList = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await device({
|
||||
page: 1,
|
||||
limit: 1000,
|
||||
searchKey: selectedDevice === 'all' ? undefined : 'deviceSn',
|
||||
searchValue: selectedDevice === 'all' ? undefined : selectedDevice,
|
||||
});
|
||||
|
||||
if (response.resp_code === 0) {
|
||||
const data = response.data || [];
|
||||
setDeviceList(data);
|
||||
|
||||
// 计算统计数据
|
||||
const totalDevices = data.length;
|
||||
const onlineDevices = data.filter((item: Device) => item.boundStatus === 1).length;
|
||||
const averageOnlineRate = totalDevices > 0 ? (onlineDevices / totalDevices) * 100 : 0;
|
||||
const totalGrowth = data.filter((item: Device) =>
|
||||
moment(item.createTime).isBetween(timeRange[0], timeRange[1])
|
||||
).length;
|
||||
|
||||
setStatistics({
|
||||
totalDevices,
|
||||
averageOnlineRate,
|
||||
totalGrowth,
|
||||
});
|
||||
|
||||
// 生成状态趋势数据
|
||||
const statusTrend: TrendData[] = Array.from({ length: 30 }, (_, i) => {
|
||||
const date = moment().subtract(29 - i, 'days');
|
||||
const devicesOnDay = data.filter((item: Device) =>
|
||||
moment(item.createTime).isSameOrBefore(date) &&
|
||||
(item.boundStatus === 1 || moment(item.loginTime).isSameOrAfter(date))
|
||||
);
|
||||
return {
|
||||
date: date.format('YYYY-MM-DD HH:mm:ss'),
|
||||
value: devicesOnDay.length > 0 ? (devicesOnDay.filter((d: Device) => d.boundStatus === 1).length / devicesOnDay.length) * 100 : 0,
|
||||
type: '在线率',
|
||||
};
|
||||
});
|
||||
|
||||
// 生成设备增长数据
|
||||
const growthTrend: DeviceGrowth[] = Array.from({ length: 30 }, (_, i) => {
|
||||
const date = moment().subtract(29 - i, 'days');
|
||||
return {
|
||||
date: date.format('YYYY-MM-DD HH:mm:ss'),
|
||||
count: data.filter((item: Device) =>
|
||||
moment(item.createTime).isSame(date, 'day')
|
||||
).length,
|
||||
};
|
||||
});
|
||||
|
||||
// 生成性能指标数据
|
||||
const performanceTrend: PerformanceData[] = Array.from({ length: 24 }, (_, i) => [
|
||||
{
|
||||
time: moment().subtract(23 - i, 'hours').format('YYYY-MM-DD HH:mm:ss'),
|
||||
value: Math.floor(Math.random() * 100),
|
||||
type: 'CPU使用率',
|
||||
},
|
||||
{
|
||||
time: moment().subtract(23 - i, 'hours').format('YYYY-MM-DD HH:mm:ss'),
|
||||
value: Math.floor(Math.random() * 100),
|
||||
type: '内存使用率',
|
||||
},
|
||||
{
|
||||
time: moment().subtract(23 - i, 'hours').format('YYYY-MM-DD HH:mm:ss'),
|
||||
value: Math.floor(Math.random() * 50) + 20,
|
||||
type: '温度',
|
||||
},
|
||||
]).flat();
|
||||
|
||||
setStatusTrendData(statusTrend);
|
||||
setDeviceGrowthData(growthTrend);
|
||||
setPerformanceData(performanceTrend);
|
||||
} else {
|
||||
message.error(response.resp_msg || '获取数据失败');
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取数据失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchDeviceList();
|
||||
}, [timeRange, selectedDevice]);
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={24}>
|
||||
<Card>
|
||||
<Space style={{ marginBottom: 16 }}>
|
||||
<Select
|
||||
style={{ width: 200 }}
|
||||
value={selectedDevice}
|
||||
onChange={setSelectedDevice}
|
||||
loading={loading}
|
||||
>
|
||||
<Select.Option value="all">所有设备</Select.Option>
|
||||
{deviceList.map(device => (
|
||||
<Select.Option key={device.deviceSn} value={device.deviceSn}>
|
||||
{device.deviceName}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
<RangePicker
|
||||
showTime
|
||||
value={timeRange}
|
||||
onChange={(dates) => {
|
||||
if (dates && dates[0] && dates[1]) {
|
||||
setTimeRange([dates[0], dates[1]]);
|
||||
}
|
||||
}}
|
||||
disabled={loading}
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 统计卡片 */}
|
||||
<Col span={8}>
|
||||
<Card loading={loading}>
|
||||
<Statistic
|
||||
title="设备总数"
|
||||
value={statistics.totalDevices}
|
||||
suffix="台"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card loading={loading}>
|
||||
<Statistic
|
||||
title="平均在线率"
|
||||
value={statistics.averageOnlineRate}
|
||||
precision={2}
|
||||
suffix="%"
|
||||
valueStyle={{ color: statistics.averageOnlineRate > 80 ? '#3f8600' : '#cf1322' }}
|
||||
prefix={statistics.averageOnlineRate > 80 ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Card loading={loading}>
|
||||
<Statistic
|
||||
title="设备增长"
|
||||
value={statistics.totalGrowth}
|
||||
suffix="台"
|
||||
valueStyle={{ color: statistics.totalGrowth > 0 ? '#3f8600' : '#cf1322' }}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 设备状态趋势 */}
|
||||
<Col span={24}>
|
||||
<Card title="设备状态趋势" loading={loading}>
|
||||
<Line
|
||||
data={statusTrendData}
|
||||
xField="date"
|
||||
yField="value"
|
||||
seriesField="type"
|
||||
xAxis={{
|
||||
type: 'time',
|
||||
mask: 'YYYY-MM-DD',
|
||||
}}
|
||||
yAxis={{
|
||||
label: {
|
||||
formatter: (v) => `${v}%`,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 设备增长趋势 */}
|
||||
<Col span={24}>
|
||||
<Card title="设备增长趋势" loading={loading}>
|
||||
<Column
|
||||
data={deviceGrowthData}
|
||||
xField="date"
|
||||
yField="count"
|
||||
xAxis={{
|
||||
type: 'time',
|
||||
mask: 'YYYY-MM-DD',
|
||||
}}
|
||||
yAxis={{
|
||||
label: {
|
||||
formatter: (v) => `${v}台`,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 性能指标趋势 */}
|
||||
<Col span={24}>
|
||||
<Card title="性能指标趋势" loading={loading}>
|
||||
<Line
|
||||
data={performanceData}
|
||||
xField="time"
|
||||
yField="value"
|
||||
seriesField="type"
|
||||
xAxis={{
|
||||
type: 'time',
|
||||
mask: 'HH:mm',
|
||||
}}
|
||||
yAxis={{
|
||||
label: {
|
||||
formatter: (v) => `${v}%`,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default DeviceStatistics;
|
||||
@@ -0,0 +1,48 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
// 获取设备状态趋势数据
|
||||
export async function getDeviceStatusTrend(params: {
|
||||
deviceId?: string;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}) {
|
||||
return request('/api/device-ops/statistics/status-trend', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 获取设备增长趋势数据
|
||||
export async function getDeviceGrowthTrend(params: {
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}) {
|
||||
return request('/api/device-ops/statistics/growth-trend', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 获取设备性能指标趋势数据
|
||||
export async function getDevicePerformanceTrend(params: {
|
||||
deviceId?: string;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}) {
|
||||
return request('/api/device-ops/statistics/performance-trend', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 获取设备统计数据
|
||||
export async function getDeviceStatistics(params: {
|
||||
deviceId?: string;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}) {
|
||||
return request('/api/device-ops/statistics/overview', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user