feat: 设备管理添加经纬度以及高度和租户

This commit is contained in:
2026-01-04 20:17:44 +08:00
parent fb40fce9cd
commit f88c1c9836
264 changed files with 684 additions and 14746 deletions
@@ -1,5 +1,6 @@
import React, { useEffect, useRef } from 'react';
import { ModalForm, ProForm, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
import { ModalForm, ProForm, ProFormDigit, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
import TenantSelector from '@/components/ui/TenantSelector';
export type DeviceFormValues = {
id?: number;
@@ -10,6 +11,11 @@ export type DeviceFormValues = {
firmwareVersion?: string;
remark?: string;
videoStreamUrl?: string;
tenantId?: string;
longitude?: number;
latitude?: number;
altitude?: number;
deviceIp?: string;
};
interface DeviceFormProps {
@@ -48,12 +54,25 @@ const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange
modalProps={{ destroyOnClose: true }}
initialValues={initialValues} // 同时设置 initialValues 属性
>
{/* 所属租户(必选) */}
<TenantSelector nameTenant="tenantId" labelTenant="所属租户" hideIncludeChildren rulesTenant={[{ required: true, message: '请选择租户' }]} />
<ProForm.Group>
<ProFormText name="deviceSn" label="设备序列号" rules={[{ required: true, message: '请输入设备序列号' }]} width="md" />
<ProFormText name="deviceName" label="设备名称" rules={[{ required: true, message: '请输入设备名称' }]} width="md" />
<ProFormText name="nickname" label="昵称" width="md" />
<ProFormSelect name="deviceType" label="设备类型" options={DEVICE_TYPE_OPTIONS} width="md" />
<ProFormText name="firmwareVersion" label="固件版本" width="md" />
<ProFormText
name="deviceIp"
label="设备IP地址"
width="md"
placeholder="如:192.168.1.100"
rules={[{
pattern: /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
message: '请输入有效的IP地址'
}]}
/>
<ProFormText
name="videoStreamUrl"
label="视频流地址"
@@ -68,6 +87,36 @@ const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange
placeholder="如:http://220.205.16.27:8024/rtc/v1/whip/?app=live&stream=xxx"
tooltip="用于无人机推流的地址"
/>
</ProForm.Group>
<ProForm.Group title="位置信息">
<ProFormDigit
name="longitude"
label="经度"
width="sm"
placeholder="如:116.397428"
tooltip="设备所在位置的经度,范围 -180 ~ 180"
fieldProps={{ precision: 6, step: 0.000001 }}
rules={[{ type: 'number', min: -180, max: 180, message: '经度范围应为 -180 ~ 180' }]}
/>
<ProFormDigit
name="latitude"
label="纬度"
width="sm"
placeholder="如:39.90923"
tooltip="设备所在位置的纬度,范围 -90 ~ 90"
fieldProps={{ precision: 6, step: 0.000001 }}
rules={[{ type: 'number', min: -90, max: 90, message: '纬度范围应为 -90 ~ 90' }]}
/>
<ProFormDigit
name="altitude"
label="高度(米)"
width="sm"
placeholder="如:100"
tooltip="设备所在位置的海拔高度,单位:米"
fieldProps={{ precision: 2, step: 0.01 }}
/>
</ProForm.Group>
<ProForm.Group>
<ProFormTextArea name="deviceDesc" label="备注" width="lg" />
</ProForm.Group>
</ModalForm>
@@ -43,6 +43,11 @@ const DeviceTable = forwardRef<DeviceTableRef, DeviceTableProps>(({ params, onEd
dataIndex: 'deviceType',
render: (_, record) => deviceTypeMap[record.deviceType] || record.deviceType
},
{ title: '所属租户', dataIndex: 'tenantId', width: 120 },
{ title: 'IP地址', dataIndex: 'deviceIp', width: 140 },
{ title: '经度', dataIndex: 'longitude', width: 120 },
{ title: '纬度', dataIndex: 'latitude', width: 120 },
{ title: '高度(米)', dataIndex: 'altitude', width: 100 },
{ title: '备注', dataIndex: 'deviceDesc' },
// { title: '固件版本', dataIndex: 'firmwareVersion' }, // 隐藏固件版本
// { title: '绑定状态', dataIndex: 'boundStatus', render: (_, r) => <Switch checked={r.boundStatus === 1} disabled /> }, // 隐藏绑定状态
@@ -66,7 +71,7 @@ const DeviceTable = forwardRef<DeviceTableRef, DeviceTableProps>(({ params, onEd
request={(p) => deviceApi.deviceList({ page: p.current, limit: p.pageSize, ...params })}
columns={columns}
search={false}
scroll={{ x: 1000 }}
scroll={{ x: 1540 }}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
);
@@ -64,7 +64,7 @@ const DevicePage: React.FC = () => {
return (
<PageContainer header={{ title: '设备管理' }}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => tableRef.current?.reload()} showTenant={false} onFinish={async (values) => setQuery(values)}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => tableRef.current?.reload()} showTenant={true} onFinish={async (values) => setQuery(values)}>
<ProFormText name="deviceSn" label="设备序列号" />
<ProFormText name="deviceName" label="设备名称" />
<ProFormSelect name="deviceType" label="设备类型" options={[
@@ -18,6 +18,7 @@ import {
ModelTypeMap,
} from '@/services/threeDModel';
import { ordersApi } from '@/services/orders';
import { deviceApi, DeviceItem } from '@/services/device';
interface ModelFormModalProps {
visible: boolean;
@@ -43,11 +44,14 @@ const ModelFormModal: React.FC<ModelFormModalProps> = ({
const [loading, setLoading] = React.useState(false);
const [tourismList, setTourismList] = useState<TourismOption[]>([]);
const [tourismLoading, setTourismLoading] = useState(false);
const [deviceList, setDeviceList] = useState<DeviceItem[]>([]);
const [deviceLoading, setDeviceLoading] = useState(false);
// 加载景区列表
useEffect(() => {
if (visible) {
loadTourismList();
loadDeviceList();
}
}, [visible]);
@@ -67,6 +71,18 @@ const ModelFormModal: React.FC<ModelFormModalProps> = ({
}
};
const loadDeviceList = async () => {
setDeviceLoading(true);
try {
const res = await deviceApi.deviceList({ page: 1, limit: 1000 });
setDeviceList(res.data || []);
} catch (error) {
console.error('加载设备列表失败:', error);
} finally {
setDeviceLoading(false);
}
};
// 重置表单
useEffect(() => {
if (visible) {
@@ -77,6 +93,8 @@ const ModelFormModal: React.FC<ModelFormModalProps> = ({
description: model.description,
tourismId: model.tourismId,
tourismName: model.tourismName,
deviceSn: model.deviceSn,
deviceName: model.deviceName,
sourceType: model.sourceType,
// 位置参数
offsetLongitude: model.position?.longitude || 0,
@@ -238,6 +256,30 @@ const ModelFormModal: React.FC<ModelFormModalProps> = ({
</Select>
</Form.Item>
</Col>
<Col span={12}>
<Form.Item name="deviceSn" label="关联设备">
<Select
placeholder="请选择关联设备"
allowClear
showSearch
loading={deviceLoading}
optionFilterProp="children"
onChange={(value, option: any) => {
// 同时设置设备名称
form.setFieldValue('deviceName', option?.children || '');
}}
>
{deviceList.map((item) => (
<Select.Option key={item.deviceSn} value={item.deviceSn}>
{item.deviceName || item.deviceSn}
</Select.Option>
))}
</Select>
</Form.Item>
<Form.Item name="deviceName" hidden>
<Input />
</Form.Item>
</Col>
</Row>
<Form.Item name="description" label="模型描述">
@@ -14,6 +14,7 @@ export interface DeviceItem {
deviceName?: string;
boundStatus?: number;
createTime?: string;
tenantId?: string;
}
// ========== 指令相关接口类型 ==========
@@ -43,6 +43,8 @@ export interface ThreeDModelVO {
totalSizeFormat: string;
tourismId: number;
tourismName: string;
deviceSn: string;
deviceName: string;
position: {
longitude: number;
latitude: number;
@@ -83,6 +85,8 @@ export interface ThreeDModelDTO {
description?: string;
tourismId?: number;
tourismName?: string;
deviceSn?: string;
deviceName?: string;
workspaceId?: string;
offsetLongitude?: number;
offsetLatitude?: number;