diff --git a/src/api/device.ts b/src/api/device.ts index 4fdc48a..33bc6be 100644 --- a/src/api/device.ts +++ b/src/api/device.ts @@ -165,6 +165,33 @@ export function unbindDrone(data) { }) } +// 获取所有智能装备列表 +export function getSmartDeviceList(params) { + return request({ + url: '/iot/device/list', + method: 'get', + params + }) +} + +// 绑定智能装备 +export function bindSmartDevice(data) { + return request({ + url: '/iot/device/bind', + method: 'post', + data + }) +} + +// 解绑智能装备 +export function unbindSmartDevice(data) { + return request({ + url: '/iot/device/unbind', + method: 'post', + data + }) +} + // 直播心跳 export function postLiveHeartbeat(data) { @@ -177,3 +204,4 @@ export function postLiveHeartbeat(data) { + diff --git a/src/components/SystemSetting/DeviceManagement.tsx b/src/components/SystemSetting/DeviceManagement.tsx index 1c44e8e..472573b 100644 --- a/src/components/SystemSetting/DeviceManagement.tsx +++ b/src/components/SystemSetting/DeviceManagement.tsx @@ -17,7 +17,10 @@ import { Row, Col, App, + Typography, } from 'antd'; + +const { Text } = Typography; import { SearchOutlined, ReloadOutlined, @@ -28,7 +31,7 @@ import { DisconnectOutlined, } from '@ant-design/icons'; import SerialNumGenerate from "./SerialNumGenerate" -import { getPlaneDeviceList, bindDrone, unbindDrone } from '@/api/device'; +import { getPlaneDeviceList, bindDrone, unbindDrone, getSmartDeviceList, bindSmartDevice, unbindSmartDevice } from '@/api/device'; import { getOrgList } from '@/api/organization/index'; import { getSiteByOrgId, getStationList } from '@/api/stationManage/index'; import { getUser } from '@/api/user/index'; @@ -77,6 +80,18 @@ export default function DeviceManagementPage() { const [bindForm] = Form.useForm(); const [selectedDroneKeys, setSelectedDroneKeys] = useState([]); + // 智能装备相关状态 + 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); + + // 下拉数据状态 const [orgOptions, setOrgOptions] = useState([]); const [siteOptions, setSiteOptions] = useState([]); @@ -101,6 +116,22 @@ export default function DeviceManagementPage() { } }; + const fetchSmartList = async () => { + setLoading(true); + try { + const res: any = await getSmartDeviceList(smartParams); + if (res.code === 200) { + setSmartList(res.rows || []); + setSmartTotal(res.total || res.rows.length); // 👈 关键:把总数存起来 + + } + } catch (err) { + utils.message.error('获取智能装备列表失败'); + } finally { + setLoading(false); + } + }; + // 获取组织列表 const fetchOrgs = async () => { try { @@ -156,12 +187,12 @@ export default function DeviceManagementPage() { }; useEffect(() => { - if (activeTab === 'drone') { - fetchDroneList(); - fetchAllDataForMapping(); // 进入无人机管理时获取全量匹配数据 + if (activeTab === 'drone' || activeTab === 'smart') { + fetchAllDataForMapping(); + if (activeTab === 'drone') fetchDroneList(); + if (activeTab === 'smart') fetchSmartList(); } - }, [activeTab]); - + }, [activeTab, smartParams]); // 打开绑定弹窗 const openBindModal = async () => { if (selectedDroneKeys.length === 0) { @@ -182,6 +213,25 @@ export default function DeviceManagementPage() { setUserOptions([]); }; + // 打开智能装备绑定弹窗 + 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([]); + }; + const handleBind = async (values) => { try { const payload = { @@ -205,6 +255,110 @@ export default function DeviceManagementPage() { } }; + 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: any = await bindSmartDevice(payload); + 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: any = await unbindSmartDevice({ deviceIds: validIds, type }); + 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', + render: (_, record) => { + const org = allOrgOptions.find(o => (o.orgId || o.id) == record.orgId); + return org ? (org.orgName || org.name) : 未绑定; + }, + }, + { + title: '所属场站', + width: 150, + key: 'siteName', + render: (_, record) => { + const site = allSiteOptions.find(s => (s.siteId || s.id) == record.siteId); + return site ? (site.siteName || site.name) : 未绑定; + }, + }, + { + title: '负责人', + width: 150, + key: 'userName', + render: (_, record) => { + const user = allUserOptions.find(u => u.userId == record.userId); + return user ? (user.nickName || user.userName) : 未绑定; + }, + }, + { title: '在线状态', width: 120, dataIndex: 'onlineStatus', key: 'online', render: s => {s === 'ONLINE' || s === 1 ? '在线' : '离线'} }, + { + title: '操作', + width: 280, + key: 'action', + fixed: 'right', + render: (_, record) => ( + + + + + + + + + + + + ), + }, + ]; + const handleUnbind = (sns, type) => { // ✅ 关键:过滤掉空、null、undefined、纯空格的项 @@ -246,18 +400,16 @@ export default function DeviceManagementPage() { }; const droneColumns = [ - { - title: '设备名称', width: 150, dataIndex: 'drone_callsign', key: 'name' - }, - //{ title: 'SN码', dataIndex: 'device_sn', key: 'sn' }, - //{ title: '网关SN', dataIndex: 'gateway_sn', key: 'gsn' }, + { 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' }, { title: '所属组织', key: 'orgName', width: 150, render: (_, record) => { - const org = allOrgOptions.find(o => o.id == record.orgId); - return (org?.orgName || org?.name || "未绑定"); + const org = allOrgOptions.find(o => (o.orgId || o.id) == record.orgId); + return org ? (org.orgName || org.name) : 未绑定; }, }, { @@ -265,8 +417,8 @@ export default function DeviceManagementPage() { key: 'siteName', width: 150, render: (_, record) => { - const site = allSiteOptions.find(s => s.id == record.siteId); - return (site?.siteName || site?.name || "未绑定"); + const site = allSiteOptions.find(s => (s.siteId || s.id) == record.siteId); + return site ? (site.siteName || site.name) : 未绑定; }, }, { @@ -275,7 +427,7 @@ export default function DeviceManagementPage() { width: 150, render: (_, record) => { const user = allUserOptions.find(u => u.userId == record.userId); - return (user?.nickName || user?.userName || "未绑定") + return user ? (user.nickName || user.userName) : 未绑定; }, }, { @@ -396,15 +548,121 @@ export default function DeviceManagementPage() { > + + - {/* ====================== 判断显示内容 ====================== */} {activeTab === 'serialGenerate' ? ( + ) : activeTab === 'smart' ? ( + <> +
+ + + + + + +
+ +
+ record.deviceId || record.id} + 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' + }} + /> + + + { + setBindSmartModalVisible(false); + setSiteOptions([]); + setUserOptions([]); + bindSmartForm.resetFields(); + }} + onOk={() => bindSmartForm.submit()} + width={500} + > +
+ + + + + + + + + + + + + + + + +
+ ) : activeTab === 'drone' ? ( <>