智能装备绑定解绑
This commit is contained in:
@@ -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) : <Text type="secondary">未绑定</Text>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '所属场站',
|
||||
width: 150,
|
||||
key: 'siteName',
|
||||
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',
|
||||
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',
|
||||
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>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
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) : <Text type="secondary">未绑定</Text>;
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -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) : <Text type="secondary">未绑定</Text>;
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -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) : <Text type="secondary">未绑定</Text>;
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -396,15 +548,121 @@ export default function DeviceManagementPage() {
|
||||
>
|
||||
<Tabs.TabPane key="all" tab="设备管理" />
|
||||
<Tabs.TabPane key="drone" tab="无人机管理" />
|
||||
<Tabs.TabPane key="smart" tab="智能装备" />
|
||||
|
||||
|
||||
<Tabs.TabPane key="camera" tab="摄像头管理" />
|
||||
<Tabs.TabPane key="smart" tab="智能装备" />
|
||||
<Tabs.TabPane key="serialGenerate" tab="机器人生成" />
|
||||
</Tabs>
|
||||
|
||||
{/* ====================== 判断显示内容 ====================== */}
|
||||
{activeTab === 'serialGenerate' ? (
|
||||
<SerialNumGenerate />
|
||||
) : 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',
|
||||
}}>
|
||||
<Table
|
||||
rowSelection={{
|
||||
selectedRowKeys: selectedSmartKeys,
|
||||
onChange: setSelectedSmartKeys,
|
||||
}}
|
||||
rowKey={(record) => 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'
|
||||
}}
|
||||
/>
|
||||
</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>
|
||||
</>
|
||||
) : activeTab === 'drone' ? (
|
||||
<>
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
|
||||
Reference in New Issue
Block a user