绑定
This commit is contained in:
@@ -28,6 +28,9 @@ import {
|
|||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import SerialNumGenerate from "./SerialNumGenerate"
|
import SerialNumGenerate from "./SerialNumGenerate"
|
||||||
import { getPlaneDeviceList, bindDrone, unbindDrone } from '@/api/device';
|
import { getPlaneDeviceList, bindDrone, unbindDrone } from '@/api/device';
|
||||||
|
import { getOrgList } from '@/api/organization/index.tsx';
|
||||||
|
import { getSiteByOrgId } from '@/api/stationManage/index';
|
||||||
|
import { getUser } from '@/api/user/index';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { RootState } from '@/src/store';
|
import { RootState } from '@/src/store';
|
||||||
import utils from '@/lib/utils';
|
import utils from '@/lib/utils';
|
||||||
@@ -71,12 +74,17 @@ export default function DeviceManagementPage() {
|
|||||||
const [bindForm] = Form.useForm();
|
const [bindForm] = Form.useForm();
|
||||||
const [selectedDroneKeys, setSelectedDroneKeys] = useState([]);
|
const [selectedDroneKeys, setSelectedDroneKeys] = useState([]);
|
||||||
|
|
||||||
|
// 下拉数据状态
|
||||||
|
const [orgOptions, setOrgOptions] = useState([]);
|
||||||
|
const [siteOptions, setSiteOptions] = useState([]);
|
||||||
|
const [userOptions, setUserOptions] = useState([]);
|
||||||
|
|
||||||
const fetchDroneList = async () => {
|
const fetchDroneList = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const res: any = await getPlaneDeviceList();
|
const res: any = await getPlaneDeviceList();
|
||||||
if (res.code == 200) {
|
if (res.code === 200) {
|
||||||
setDroneList(res?.data?.detail || []);
|
setDroneList(res.data?.detail || res.data || []);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
utils.message.error('获取无人机列表失败');
|
utils.message.error('获取无人机列表失败');
|
||||||
@@ -85,12 +93,62 @@ export default function DeviceManagementPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 获取组织列表
|
||||||
|
const fetchOrgs = async () => {
|
||||||
|
try {
|
||||||
|
const res: any = await getOrgList({});
|
||||||
|
if (res.code === 200) {
|
||||||
|
setOrgOptions(res.rows || []);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('获取组织列表失败', err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 根据组织获取场站
|
||||||
|
const fetchSites = async (orgId) => {
|
||||||
|
setSiteOptions([]);
|
||||||
|
try {
|
||||||
|
const res: any = await getSiteByOrgId({ id: orgId });
|
||||||
|
if (res.code === 200) {
|
||||||
|
setSiteOptions(res.data || []);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('获取场站列表失败', err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 根据场站获取用户
|
||||||
|
const fetchUsers = async (siteId) => {
|
||||||
|
try {
|
||||||
|
const res: any = await getUser({ siteId, pageNum: 1, pageSize: 1000 });
|
||||||
|
if (res.code === 200) {
|
||||||
|
setUserOptions(res.rows || []);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('获取用户列表失败', err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeTab === 'drone') {
|
if (activeTab === 'drone') {
|
||||||
fetchDroneList();
|
fetchDroneList();
|
||||||
}
|
}
|
||||||
}, [activeTab]);
|
}, [activeTab]);
|
||||||
|
|
||||||
|
// 打开绑定弹窗
|
||||||
|
const openBindModal = () => {
|
||||||
|
if (selectedDroneKeys.length === 0) {
|
||||||
|
return utils.message.warning('请先在列表中选中需要绑定的无人机');
|
||||||
|
}
|
||||||
|
setBindModalVisible(true);
|
||||||
|
fetchOrgs();
|
||||||
|
bindForm.setFieldsValue({
|
||||||
|
sns: selectedDroneKeys.join(', '),
|
||||||
|
userId: userInfo?.userId
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleBind = async (values) => {
|
const handleBind = async (values) => {
|
||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
@@ -265,7 +323,7 @@ export default function DeviceManagementPage() {
|
|||||||
<>
|
<>
|
||||||
<div style={{ marginBottom: 16 }}>
|
<div style={{ marginBottom: 16 }}>
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="primary" icon={<LinkOutlined />} onClick={() => setBindModalVisible(true)}>绑定无人机</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, 1)}>批量解绑(人)</Button>
|
||||||
<Button disabled={selectedDroneKeys.length === 0} onClick={() => handleUnbind(selectedDroneKeys, 2)}>批量解绑(场)</Button>
|
<Button disabled={selectedDroneKeys.length === 0} onClick={() => handleUnbind(selectedDroneKeys, 2)}>批量解绑(场)</Button>
|
||||||
<Button disabled={selectedDroneKeys.length === 0} onClick={() => handleUnbind(selectedDroneKeys, 3)}>批量解绑(组)</Button>
|
<Button disabled={selectedDroneKeys.length === 0} onClick={() => handleUnbind(selectedDroneKeys, 3)}>批量解绑(组)</Button>
|
||||||
@@ -287,28 +345,61 @@ export default function DeviceManagementPage() {
|
|||||||
<Modal
|
<Modal
|
||||||
title="绑定无人机"
|
title="绑定无人机"
|
||||||
open={bindModalVisible}
|
open={bindModalVisible}
|
||||||
onCancel={() => setBindModalVisible(false)}
|
onCancel={() => {
|
||||||
|
setBindModalVisible(false);
|
||||||
|
setSiteOptions([]);
|
||||||
|
setUserOptions([]);
|
||||||
|
}}
|
||||||
onOk={() => bindForm.submit()}
|
onOk={() => bindForm.submit()}
|
||||||
width={500}
|
width={500}
|
||||||
>
|
>
|
||||||
<Form form={bindForm} layout="vertical" onFinish={handleBind} initialValues={{ userId: userInfo?.userId }}>
|
<Form form={bindForm} layout="vertical" onFinish={handleBind}>
|
||||||
<Form.Item label="无人机 SN (多个用逗号隔开)" name="sns" rules={[{ required: true, message: '请输入 SN' }]}>
|
<Form.Item label="已选无人机 SN" name="sns" rules={[{ required: true, message: '请输入 SN' }]}>
|
||||||
<Input.TextArea placeholder="例如: SN001, SN002" rows={3} />
|
<Input.TextArea placeholder="例如: SN001, SN002" rows={3} disabled />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Row gutter={16}>
|
|
||||||
<Col span={12}>
|
<Form.Item label="所属组织" name="orgId" rules={[{ required: true, message: '请选择组织' }]}>
|
||||||
<Form.Item label="场站 ID (siteId)" name="siteId" rules={[{ required: true, message: '请输入场站 ID' }]}>
|
<Select
|
||||||
<InputNumber style={{ width: '100%' }} />
|
allowClear
|
||||||
|
placeholder="请选择组织"
|
||||||
|
onChange={(val) => {
|
||||||
|
bindForm.setFieldsValue({ siteId: undefined, userId: undefined });
|
||||||
|
setSiteOptions([]);
|
||||||
|
setUserOptions([]);
|
||||||
|
fetchSites(val);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{orgOptions.map(org => (
|
||||||
|
<Select.Option key={org.id} value={org.id}>{org.orgName}</Select.Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
|
||||||
<Col span={12}>
|
<Form.Item label="所属场站" name="siteId" rules={[{ required: true, message: '请选择场站' }]}>
|
||||||
<Form.Item label="组织 ID (orgId)" name="orgId" rules={[{ required: true, message: '请输入组织 ID' }]}>
|
<Select
|
||||||
<InputNumber style={{ width: '100%' }} />
|
placeholder="请先选择场站"
|
||||||
|
disabled={!siteOptions.length}
|
||||||
|
onChange={(val) => {
|
||||||
|
bindForm.setFieldsValue({ userId: undefined });
|
||||||
|
setUserOptions([]);
|
||||||
|
fetchUsers(val);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{siteOptions.map(site => (
|
||||||
|
<Select.Option key={site.id} value={site.id}>{site.siteName}</Select.Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
|
||||||
</Row>
|
<Form.Item label="负责人" name="userId" rules={[{ required: true, message: '请选择负责人' }]}>
|
||||||
<Form.Item label="用户 ID (userId)" name="userId">
|
<Select
|
||||||
<InputNumber style={{ width: '100%' }} />
|
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.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|||||||
Reference in New Issue
Block a user