Files
web-Iot/src/components/SystemSetting/DeviceManagement.tsx

774 lines
25 KiB
TypeScript
Raw Normal View History

2026-05-25 13:06:38 +08:00
import React, { useState, useEffect } from 'react';
2026-05-08 15:53:27 +08:00
import {
Table,
Input,
Button,
Form,
Select,
Space,
Tag,
message,
Modal,
Tabs,
Card,
InputNumber,
2026-05-25 13:06:38 +08:00
Checkbox,
Tooltip,
Row,
Col,
2026-05-25 14:39:05 +08:00
App,
2026-05-26 13:44:59 +08:00
Typography,
2026-05-08 15:53:27 +08:00
} from 'antd';
2026-05-26 13:44:59 +08:00
const { Text } = Typography;
2026-05-08 15:53:27 +08:00
import {
SearchOutlined,
ReloadOutlined,
PlusOutlined,
EditOutlined,
DeleteOutlined,
2026-05-25 13:06:38 +08:00
LinkOutlined,
DisconnectOutlined,
2026-05-08 15:53:27 +08:00
} from '@ant-design/icons';
import SerialNumGenerate from "./SerialNumGenerate"
import { getPlaneDeviceList, bindDrone, unbindDrone, bindSmartDevice, unbindSmartDevice, getSiteDevice } from '@/api/device';
2026-05-25 14:39:05 +08:00
import { getOrgList } from '@/api/organization/index';
2026-05-25 15:15:05 +08:00
import { getSiteByOrgId, getStationList } from '@/api/stationManage/index';
2026-05-25 13:21:56 +08:00
import { getUser } from '@/api/user/index';
2026-05-25 13:06:38 +08:00
import { useSelector } from 'react-redux';
import { RootState } from '@/src/store';
import utils from '@/lib/utils';
2026-05-08 15:53:27 +08:00
// 模拟数据
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');
2026-05-25 14:39:05 +08:00
const { modal } = App.useApp();
2026-05-08 15:53:27 +08:00
const [form] = Form.useForm();
const [loading, setLoading] = useState(false);
const [deviceList, setDeviceList] = useState(allDeviceList);
2026-05-25 13:06:38 +08:00
// 无人机相关状态
const { userInfo } = useSelector((state: RootState) => state.user);
const [droneList, setDroneList] = useState([]);
const [bindModalVisible, setBindModalVisible] = useState(false);
const [bindForm] = Form.useForm();
const [selectedDroneKeys, setSelectedDroneKeys] = useState([]);
// 无人机分页 + 筛选
const [droneParams, setDroneParams] = useState({
pageNum: 1,
pageSize: 10,
gateway_sn: '',
status: "",
});
const [droneTotal, setDroneTotal] = useState(0);
2026-05-26 13:44:59 +08:00
// 智能装备相关状态
const [smartList, setSmartList] = useState([]);
const [selectedSmartKeys, setSelectedSmartKeys] = useState([]);
const [bindSmartModalVisible, setBindSmartModalVisible] = useState(false);
const [bindSmartForm] = Form.useForm();
const [smartParams, setSmartParams] = useState({
pageNum: 1,
pageSize: 10,
});
const [smartTotal, setSmartTotal] = useState(0);
2026-05-25 13:21:56 +08:00
// 下拉数据状态
const [orgOptions, setOrgOptions] = useState([]);
const [siteOptions, setSiteOptions] = useState([]);
const [userOptions, setUserOptions] = useState([]);
// 全局匹配用的全量数据状态
2026-05-25 15:15:05 +08:00
const [allOrgOptions, setAllOrgOptions] = useState([]);
const [allSiteOptions, setAllSiteOptions] = useState([]);
const [allUserOptions, setAllUserOptions] = useState([]);
// 获取无人机列表(带分页 + 筛选)
2026-05-25 13:06:38 +08:00
const fetchDroneList = async () => {
setLoading(true);
try {
const res = await getPlaneDeviceList(droneParams);
2026-05-25 13:21:56 +08:00
if (res.code === 200) {
setDroneList(res.rows || []);
setDroneTotal(res.total || res.rows?.length || 0);
2026-05-25 13:06:38 +08:00
}
} catch (err) {
utils.message.error('获取无人机列表失败');
} finally {
setLoading(false);
}
};
2026-05-26 13:44:59 +08:00
const fetchSmartList = async () => {
setLoading(true);
try {
const res = await getSiteDevice(smartParams);
2026-05-26 13:44:59 +08:00
if (res.code === 200) {
setSmartList(res.rows || []);
setSmartTotal(res.total || res.rows.length);
2026-05-26 13:44:59 +08:00
}
} catch (err) {
utils.message.error('获取智能装备列表失败');
} finally {
setLoading(false);
}
};
2026-05-25 13:21:56 +08:00
// 获取组织列表
const fetchOrgs = async () => {
try {
const res = await getOrgList({});
2026-05-25 13:21:56 +08:00
if (res.code === 200) {
setOrgOptions(res.rows || []);
}
} catch (err) {
console.error('获取组织列表失败', err);
}
};
// 根据组织获取场站
const fetchSites = async (orgId) => {
setSiteOptions([]);
try {
const res = await getSiteByOrgId({ id: orgId });
2026-05-25 13:21:56 +08:00
if (res.code === 200) {
setSiteOptions(res.data || []);
}
} catch (err) {
console.error('获取场站列表失败', err);
}
};
2026-05-25 15:15:05 +08:00
// 获取用户列表
2026-05-25 13:21:56 +08:00
const fetchUsers = async (siteId) => {
try {
const res = await getUser({ siteId, pageNum: 1, pageSize: 1000 });
2026-05-25 13:21:56 +08:00
if (res.code === 200) {
setUserOptions(res.rows || []);
}
} catch (err) {
console.error('获取用户列表失败', err);
}
};
// 初始化时获取全量数据用于列表匹配
2026-05-25 15:15:05 +08:00
const fetchAllDataForMapping = async () => {
try {
const [orgRes, siteRes, userRes] = await Promise.all([
2026-05-25 15:15:05 +08:00
getOrgList({ pageNum: 1, pageSize: 1000 }),
getStationList({ pageNum: 1, pageSize: 1000 }),
getUser({ pageNum: 1, pageSize: 10000 })
]);
if (orgRes.code === 200) setAllOrgOptions(orgRes.rows || []);
if (siteRes.code === 200) setAllSiteOptions(siteRes.rows || []);
if (userRes.code === 200) setAllUserOptions(userRes.rows || []);
} catch (err) {
console.error('初始化全量数据失败', err);
}
};
2026-05-25 13:06:38 +08:00
useEffect(() => {
2026-05-26 13:44:59 +08:00
if (activeTab === 'drone' || activeTab === 'smart') {
fetchAllDataForMapping();
2026-05-25 13:06:38 +08:00
}
}, [activeTab]);
useEffect(() => {
if (activeTab === 'drone') fetchDroneList();
}, [activeTab, droneParams]);
useEffect(() => {
if (activeTab === 'smart') fetchSmartList();
2026-05-26 13:44:59 +08:00
}, [activeTab, smartParams]);
2026-05-25 13:21:56 +08:00
// 打开绑定弹窗
2026-05-25 15:15:05 +08:00
const openBindModal = async () => {
2026-05-25 13:21:56 +08:00
if (selectedDroneKeys.length === 0) {
return utils.message.warning('请先在列表中选中需要绑定的无人机');
}
setBindModalVisible(true);
2026-05-25 15:15:05 +08:00
await fetchOrgs();
2026-05-25 13:21:56 +08:00
bindForm.setFieldsValue({
sns: selectedDroneKeys.join(', '),
2026-05-25 15:15:05 +08:00
orgId: undefined,
siteId: undefined,
userId: undefined,
2026-05-25 13:21:56 +08:00
});
2026-05-25 15:15:05 +08:00
setSiteOptions([]);
setUserOptions([]);
2026-05-25 13:21:56 +08:00
};
2026-05-26 13:44:59 +08:00
// 打开智能装备绑定弹窗
const openBindSmartModal = async () => {
if (selectedSmartKeys.length === 0) {
return utils.message.warning('请先在列表中选中需要绑定的智能装备');
}
setBindSmartModalVisible(true);
await fetchOrgs();
bindSmartForm.setFieldsValue({
deviceIds: selectedSmartKeys.join(', '),
orgId: undefined,
siteId: undefined,
userId: undefined,
});
setSiteOptions([]);
setUserOptions([]);
};
2026-05-25 13:06:38 +08:00
const handleBind = async (values) => {
try {
const payload = {
siteId: values.siteId,
orgId: values.orgId,
2026-05-25 14:39:05 +08:00
userId: values.userId,
2026-05-25 13:06:38 +08:00
sns: values.sns.split(',').map(s => s.trim()),
};
const res = await bindDrone(payload);
2026-05-25 14:39:05 +08:00
if (res.code === 200 && res.data == true) {
2026-05-25 13:06:38 +08:00
utils.message.success('绑定成功');
setBindModalVisible(false);
2026-05-25 15:15:05 +08:00
setSelectedDroneKeys([]);
2026-05-25 13:06:38 +08:00
bindForm.resetFields();
fetchDroneList();
} else {
utils.message.error(res.msg || '绑定失败');
}
} catch (err) {
utils.message.error('操作异常');
}
};
2026-05-26 13:44:59 +08:00
const handleBindSmart = async (values) => {
try {
const payload = {
siteId: values.siteId,
orgId: values.orgId,
userId: values.userId,
deviceIds: values.deviceIds.split(',').map(s => s.trim()),
};
const res = await bindSmartDevice(payload);
2026-05-26 13:44:59 +08:00
if (res.code === 200) {
utils.message.success('绑定成功');
setBindSmartModalVisible(false);
bindSmartForm.resetFields();
fetchSmartList();
} else {
utils.message.error(res.msg || '绑定失败');
}
} catch (err) {
utils.message.error('操作异常');
}
};
const handleUnbindSmart = (deviceIds, type) => {
const validIds = (deviceIds || []).filter(id => id);
if (validIds.length === 0) {
return utils.message.warning('未选择有效设备,无法解绑');
}
const typeText = { 1: '人员', 2: '场站', 3: '组织' }[type];
modal.confirm({
title: '确认解绑',
content: `确定要为选中的智能装备清除${typeText}绑定吗?`,
okText: '确定',
cancelText: '取消',
onOk: async () => {
try {
const res = await unbindSmartDevice({ deviceIds: validIds, type });
2026-05-26 13:44:59 +08:00
if (res.code === 200) {
utils.message.success('解绑成功');
fetchSmartList();
setSelectedSmartKeys([]);
} else {
utils.message.error(res.msg || '解绑失败');
}
} catch (err) {
utils.message.error('操作异常');
}
}
});
};
const smartColumns = [
{ title: '设备名称', width: 150, dataIndex: 'deviceAlias', key: 'name' },
{ title: '设备码', width: 280, dataIndex: 'serialNumber', key: 'sn' },
{
title: '所属组织', width: 150, key: 'orgName',
2026-05-26 13:44:59 +08:00
render: (_, record) => {
const org = allOrgOptions.find(o => (o.orgId || o.id) == record.orgId);
return org ? (org.orgName || org.name) : <Text type="secondary">未绑定</Text>;
},
},
{
title: '所属场站', width: 150, key: 'siteName',
2026-05-26 13:44:59 +08:00
render: (_, record) => {
const site = allSiteOptions.find(s => (s.siteId || s.id) == record.siteId);
return site ? (site.siteName || site.name) : <Text type="secondary">未绑定</Text>;
},
},
{
title: '负责人', width: 150, key: 'userName',
2026-05-26 13:44:59 +08:00
render: (_, record) => {
const user = allUserOptions.find(u => u.userId == record.userId);
return user ? (user.nickName || user.userName) : <Text type="secondary">未绑定</Text>;
},
},
{ title: '在线状态', width: 120, dataIndex: 'onlineStatus', key: 'online', render: s => <Tag color={s === 'ONLINE' || s === 1 ? 'green' : 'red'}>{s === 'ONLINE' || s === 1 ? '在线' : '离线'}</Tag> },
{
title: '操作', width: 280, key: 'action', fixed: 'right',
2026-05-26 13:44:59 +08:00
render: (_, record) => (
<Space>
<Tooltip title="清除人员绑定">
<Button size="small" icon={<DisconnectOutlined />} onClick={() => handleUnbindSmart([record.deviceId || record.id], 1)}>用户</Button>
</Tooltip>
<Tooltip title="清除场站绑定">
<Button size="small" icon={<DisconnectOutlined />} onClick={() => handleUnbindSmart([record.deviceId || record.id], 2)}>场站</Button>
</Tooltip>
<Tooltip title="清除组织绑定">
<Button size="small" icon={<DisconnectOutlined />} onClick={() => handleUnbindSmart([record.deviceId || record.id], 3)}>组织</Button>
</Tooltip>
</Space>
),
},
];
2026-05-25 13:06:38 +08:00
const handleUnbind = (sns, type) => {
2026-05-25 14:39:05 +08:00
const validSns = (sns || []).filter(item =>
item !== null && item !== undefined && item !== '' && item.trim() !== ''
2026-05-25 14:39:05 +08:00
);
if (validSns.length === 0) {
return utils.message.warning('未选择有效设备,无法解绑');
}
2026-05-25 13:06:38 +08:00
const typeText = { 1: '人员', 2: '场站', 3: '组织' }[type];
2026-05-25 14:39:05 +08:00
modal.confirm({
2026-05-25 13:06:38 +08:00
title: '确认解绑',
content: `确定要为选中的无人机清除${typeText}绑定吗?`,
2026-05-25 14:39:05 +08:00
okText: '确定',
cancelText: '取消',
2026-05-25 13:06:38 +08:00
onOk: async () => {
try {
const res = await unbindDrone({ sns: validSns, type });
2026-05-25 13:06:38 +08:00
if (res.code === 200) {
utils.message.success('解绑成功');
fetchDroneList();
setSelectedDroneKeys([]);
} else {
utils.message.error(res.msg || '解绑失败');
}
} catch (err) {
utils.message.error('操作异常');
}
}
});
};
const droneColumns = [
2026-05-26 13:44:59 +08:00
{ title: '设备名称', width: 150, dataIndex: 'drone_callsign', key: 'name' },
{ title: 'SN码', width: 150, dataIndex: 'device_sn', key: 'sn' },
{ title: '机场SN', width: 150, dataIndex: 'gateway_sn', key: 'gsn' },
2026-05-25 15:15:05 +08:00
{
title: '所属组织', width: 150, key: 'orgName',
2026-05-25 15:15:05 +08:00
render: (_, record) => {
2026-05-26 13:44:59 +08:00
const org = allOrgOptions.find(o => (o.orgId || o.id) == record.orgId);
return org ? (org.orgName || org.name) : <Text type="secondary">未绑定</Text>;
2026-05-25 15:15:05 +08:00
},
},
{
title: '所属场站', width: 150, key: 'siteName',
2026-05-25 15:15:05 +08:00
render: (_, record) => {
2026-05-26 13:44:59 +08:00
const site = allSiteOptions.find(s => (s.siteId || s.id) == record.siteId);
return site ? (site.siteName || site.name) : <Text type="secondary">未绑定</Text>;
2026-05-25 15:15:05 +08:00
},
},
{
title: '负责人', width: 150, key: 'userName',
2026-05-25 15:15:05 +08:00
render: (_, record) => {
const user = allUserOptions.find(u => u.userId == record.userId);
2026-05-26 13:44:59 +08:00
return user ? (user.nickName || user.userName) : <Text type="secondary">未绑定</Text>;
2026-05-25 15:15:05 +08:00
},
},
{
title: '状态', width: 150, dataIndex: 'onlineStatus', key: 'status',
render: s => <Tag color={s === 1 ? 'green' : 'default'}>{s === 1 ? '在线' : '离线'}</Tag>
2026-05-25 15:15:05 +08:00
},
2026-05-25 13:06:38 +08:00
{
title: '操作', key: 'action', fixed: 'right',
2026-05-25 13:06:38 +08:00
render: (_, record) => (
<Space>
2026-05-25 15:15:05 +08:00
<Tooltip title="人员解绑">
2026-05-25 14:39:05 +08:00
<Button size="small" icon={<DisconnectOutlined />} onClick={() => handleUnbind([record.gateway_sn], 1)}>用户</Button>
2026-05-25 13:06:38 +08:00
</Tooltip>
2026-05-25 15:15:05 +08:00
<Tooltip title="场站解绑">
2026-05-25 14:39:05 +08:00
<Button size="small" icon={<DisconnectOutlined />} onClick={() => handleUnbind([record.gateway_sn], 2)}>场站</Button>
2026-05-25 13:06:38 +08:00
</Tooltip>
2026-05-25 15:15:05 +08:00
<Tooltip title="组织解绑">
2026-05-25 14:39:05 +08:00
<Button size="small" icon={<DisconnectOutlined />} onClick={() => handleUnbind([record.gateway_sn], 3)}>组织</Button>
2026-05-25 13:06:38 +08:00
</Tooltip>
</Space>
),
},
];
2026-05-08 15:53:27 +08:00
// 根据 Tab 过滤数据
const filteredByTab = deviceList.filter(tabs.find(t => t.key === activeTab)?.filter || (() => false));
2026-05-08 15:53:27 +08:00
// 表格列定义
const columns = [
{ title: '设备编码', dataIndex: 'code', key: 'code' },
{ title: '设备名称', dataIndex: 'name', key: 'name' },
{ title: '类型', dataIndex: 'type', key: 'type' },
{
title: '在线', dataIndex: 'online', key: 'online',
2026-05-08 15:53:27 +08:00
render: (text) => (
<Tag color={text === 'ONLINE' ? 'green' : 'red'}>{text}</Tag>
),
},
{
title: '运行', dataIndex: 'status', key: 'status',
2026-05-08 15:53:27 +08:00
render: (text) => {
const colorMap = {
NORMAL: 'green',
FAULT: 'red',
WARNING: 'orange',
IDLE: 'blue',
};
return <Tag color={colorMap[text] || 'default'}>{text}</Tag>;
},
},
{
title: '操作', key: 'action',
2026-05-08 15:53:27 +08:00
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) => {
2026-05-25 14:39:05 +08:00
modal.confirm({
2026-05-08 15:53:27 +08:00
title: '确认删除',
content: `确定要删除设备 ${record.name} 吗?`,
onOk: () => {
message.success(`设备 ${record.name} 已删除`);
setDeviceList(prev => prev.filter(item => item.id !== record.id));
},
});
};
return (
2026-05-15 15:39:28 +08:00
<div style={{ padding: "8px 0px", paddingTop: 0 }}>
2026-05-08 15:53:27 +08:00
<Tabs
activeKey={activeTab}
onChange={setActiveTab}
2026-05-15 15:39:28 +08:00
style={{ marginBottom: 0 }}
2026-05-08 15:53:27 +08:00
>
<Tabs.TabPane key="all" tab="设备管理" />
2026-05-25 14:39:05 +08:00
<Tabs.TabPane key="drone" tab="无人机管理" />
2026-05-26 13:44:59 +08:00
<Tabs.TabPane key="smart" tab="智能装备" />
2026-05-08 15:53:27 +08:00
<Tabs.TabPane key="camera" tab="摄像头管理" />
<Tabs.TabPane key="serialGenerate" tab="机器人生成" />
2026-05-08 15:53:27 +08:00
</Tabs>
{activeTab === 'serialGenerate' ? (
<SerialNumGenerate />
2026-05-26 13:44:59 +08:00
) : activeTab === 'smart' ? (
<>
<div style={{ marginBottom: 16 }}>
<Space>
<Button type="primary" icon={<LinkOutlined />} onClick={openBindSmartModal}>绑定装备</Button>
<Button disabled={selectedSmartKeys.length === 0} onClick={() => handleUnbindSmart(selectedSmartKeys, 1)}>批量解绑(用户)</Button>
<Button disabled={selectedSmartKeys.length === 0} onClick={() => handleUnbindSmart(selectedSmartKeys, 2)}>批量解绑(场站)</Button>
<Button disabled={selectedSmartKeys.length === 0} onClick={() => handleUnbindSmart(selectedSmartKeys, 3)}>批量解绑(组织)</Button>
</Space>
</div>
<div style={{ height: 'calc(100vh - 220px)', overflowY: 'auto', paddingRight: '4px' }}>
2026-05-26 13:44:59 +08:00
<Table
rowSelection={{ selectedRowKeys: selectedSmartKeys, onChange: setSelectedSmartKeys }}
rowKey={(record) => record.serialNumber}
2026-05-26 13:44:59 +08:00
columns={smartColumns}
dataSource={smartList}
loading={loading}
pagination={{
current: smartParams.pageNum,
pageSize: smartParams.pageSize,
total: smartTotal,
showSizeChanger: true,
showTotal: (t) => `共 ${t} 条`,
onChange: (page, pageSize) => {
setSmartParams({ pageNum: page, pageSize });
},
}}
scroll={{ y: 'auto', x: '700px' }}
2026-05-26 13:44:59 +08:00
/>
</div>
<Modal
title="绑定智能装备"
open={bindSmartModalVisible}
onCancel={() => {
setBindSmartModalVisible(false);
setSiteOptions([]);
setUserOptions([]);
bindSmartForm.resetFields();
}}
onOk={() => bindSmartForm.submit()}
width={500}
>
<Form form={bindSmartForm} layout="vertical" onFinish={handleBindSmart}>
<Form.Item label="已选装备 ID" name="deviceIds" rules={[{ required: true, message: '请选择装备' }]}>
<Input.TextArea placeholder="例如: ID001, ID002" rows={3} disabled />
</Form.Item>
<Form.Item label="所属组织" name="orgId" rules={[{ required: true, message: '请选择组织' }]}>
<Select
placeholder="请选择组织"
onChange={(val) => {
bindSmartForm.setFieldsValue({ siteId: undefined, userId: undefined });
setSiteOptions([]);
setUserOptions([]);
fetchSites(val);
}}
>
{orgOptions.map(org => (
<Select.Option key={org.id || org.orgId} value={org.id || org.orgId}>{org.orgName || org.name}</Select.Option>
))}
</Select>
</Form.Item>
<Form.Item label="所属场站" name="siteId" >
<Select
placeholder="请先选择组织"
disabled={!siteOptions.length}
onChange={(val) => {
bindSmartForm.setFieldsValue({ userId: undefined });
setUserOptions([]);
fetchUsers(val);
}}
>
{siteOptions.map(site => (
<Select.Option key={site.id || site.siteId} value={site.id || site.siteId}>{site.siteName || site.name}</Select.Option>
))}
</Select>
</Form.Item>
<Form.Item label="负责人" name="userId" >
<Select
placeholder="请先选择场站"
disabled={!userOptions.length}
>
{userOptions.map(user => (
<Select.Option key={user.userId} value={user.userId}>{user.nickName || user.userName}</Select.Option>
))}
</Select>
</Form.Item>
</Form>
</Modal>
</>
2026-05-25 13:06:38 +08:00
) : activeTab === 'drone' ? (
<>
{/* 无人机搜索栏 */}
<div style={{ marginBottom: 16, display: 'flex', gap: 10, flexWrap: 'wrap' }}>
<Input
placeholder="机场SN"
style={{ width: 200 }}
value={droneParams.gateway_sn}
onChange={(e) => setDroneParams({ ...droneParams, gateway_sn: e.target.value })}
/>
<Select
placeholder="状态"
style={{ width: 120 }}
value={droneParams.status}
allowClear
onChange={(val) => setDroneParams({ ...droneParams, status: val })}
>
<Select.Option value="1">在线</Select.Option>
<Select.Option value="2">离线</Select.Option>
</Select>
<Button icon={<ReloadOutlined />} onClick={() => setDroneParams({ pageNum: 1, pageSize: 10, gateway_sn: '', status: '' })}>重置</Button>
<Button type="primary" icon={<LinkOutlined />} onClick={openBindModal}>绑定无人机</Button>
<Button disabled={selectedDroneKeys.length === 0} onClick={() => handleUnbind(selectedDroneKeys, 1)}>批量解绑(用户)</Button>
<Button disabled={selectedDroneKeys.length === 0} onClick={() => handleUnbind(selectedDroneKeys, 2)}>批量解绑(场站)</Button>
<Button disabled={selectedDroneKeys.length === 0} onClick={() => handleUnbind(selectedDroneKeys, 3)}>批量解绑(组)</Button>
2026-05-25 13:06:38 +08:00
</div>
<div style={{ height: 'calc(100vh - 220px)', overflowY: 'auto', paddingRight: '4px' }}>
2026-05-25 14:39:05 +08:00
<Table
rowSelection={{ selectedRowKeys: selectedDroneKeys, onChange: setSelectedDroneKeys }}
2026-05-25 14:39:05 +08:00
rowKey="gateway_sn"
columns={droneColumns}
dataSource={droneList}
loading={loading}
pagination={{
current: droneParams.pageNum,
pageSize: droneParams.pageSize,
total: droneTotal,
2026-05-25 14:39:05 +08:00
showSizeChanger: true,
showTotal: t => `共 ${t} 条`,
onChange: (page, pageSize) => {
setDroneParams({ ...droneParams, pageNum: page, pageSize });
},
2026-05-25 14:39:05 +08:00
}}
scroll={{ y: 'auto', x: '700px' }}
2026-05-25 14:39:05 +08:00
/>
</div>
2026-05-25 13:06:38 +08:00
<Modal
title="绑定无人机"
open={bindModalVisible}
2026-05-25 13:21:56 +08:00
onCancel={() => {
setBindModalVisible(false);
setSiteOptions([]);
setUserOptions([]);
bindForm.resetFields();
2026-05-25 13:21:56 +08:00
}}
2026-05-25 13:06:38 +08:00
onOk={() => bindForm.submit()}
width={500}
>
2026-05-25 13:21:56 +08:00
<Form form={bindForm} layout="vertical" onFinish={handleBind}>
<Form.Item label="已选无人机 SN" name="sns" rules={[{ required: true, message: '请输入 SN' }]}>
<Input.TextArea placeholder="例如: SN001, SN002" rows={3} disabled />
</Form.Item>
<Form.Item label="所属组织" name="orgId" rules={[{ required: true, message: '请选择组织' }]}>
<Select
allowClear
placeholder="请选择组织"
onChange={(val) => {
bindForm.setFieldsValue({ siteId: undefined, userId: undefined });
setSiteOptions([]);
setUserOptions([]);
fetchSites(val);
}}
>
{orgOptions.map(org => (
<Select.Option key={`org-${org.id}`} value={org.id}>
2026-05-25 13:27:52 +08:00
{org.name || org.orgName || '未命名组织'}
</Select.Option>
2026-05-25 13:21:56 +08:00
))}
</Select>
</Form.Item>
2026-05-25 14:39:05 +08:00
<Form.Item label="所属场站" name="siteId" >
2026-05-25 13:21:56 +08:00
<Select
2026-05-25 13:27:52 +08:00
placeholder="请先选择组织"
2026-05-25 13:21:56 +08:00
disabled={!siteOptions.length}
onChange={(val) => {
bindForm.setFieldsValue({ userId: undefined });
setUserOptions([]);
fetchUsers(val);
}}
>
{siteOptions.map(site => (
<Select.Option key={`site-${site.id}`} value={site.id}>
2026-05-25 13:27:52 +08:00
{site.name || site.siteName || '未命名场站'}
</Select.Option>
2026-05-25 13:21:56 +08:00
))}
</Select>
2026-05-25 13:06:38 +08:00
</Form.Item>
2026-05-25 14:39:05 +08:00
<Form.Item label="负责人" name="userId" >
2026-05-25 13:21:56 +08:00
<Select
placeholder="请先选择场站"
disabled={!userOptions.length}
>
{userOptions.map(user => (
<Select.Option key={`user-${user.userId}`} value={user.userId}>
2026-05-25 13:27:52 +08:00
{user.nickName || user.userName || user.realName || '未知用户'}
</Select.Option>
2026-05-25 13:21:56 +08:00
))}
</Select>
2026-05-25 13:06:38 +08:00
</Form.Item>
</Form>
</Modal>
2026-05-25 13:06:38 +08:00
</>
) : (
<>
<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>
2026-05-08 15:53:27 +08:00
);
}