地块环境监测 - 环境监测 模块已成功升级!
localStorage 读取 smart_agriculture_ai_iot_devicestype === '环境监测站' 且 bindingStatus === '未绑定' 的设备bindingStatus = '已绑定'bindingSystem = '地块环境监测-环境监测'| 字段 | 修改前 | 修改后 |
|---|---|---|
| 设备名称 | ❌ 手动输入 | ✅ 从选择的设备自动获取 |
| 选择设备 | ❌ 本地设备类型库 | ✅ AI数据中心物联设备 |
| 选择地块 | ✅ 保持不变 | ✅ 保持不变 |
| 安装位置 | ✅ 保持不变 | ✅ 保持不变 |
interface IoTDevice {
id: string;
code: string;
name: string;
type: string;
deviceTypeId?: string;
manufacturer: string;
model: string;
location: string;
fieldId: string;
fieldName: string;
protocol: string;
status: string;
bindingStatus: '未绑定' | '已绑定';
bindingSystem?: string;
batteryLevel?: number;
signalStrength?: number;
sensors: Array<{...}>;
}
useEffect(() => {
const loadIoTDevices = () => {
const data = localStorage.getItem('smart_agriculture_ai_iot_devices');
if (data) {
const devices: IoTDevice[] = JSON.parse(data);
// 只显示环境监测站类型且未绑定的设备
const environmentDevices = devices.filter(
d => d.type === '环境监测站' && d.bindingStatus === '未绑定'
);
setAvailableIoTDevices(environmentDevices);
}
};
loadIoTDevices();
}, [showDeviceDialog]);
// 添加新设备
const newDevice: SensorDevice = {
id: `device-${Date.now()}`,
name: iotDevice.code, // 使用设备编码
type: iotDevice.type, // 使用设备类型
location: deviceForm.location,
fieldId: deviceForm.fieldId,
fieldName: field.name,
status: 'online',
battery: iotDevice.batteryLevel || 100,
lastUpdate: new Date().toLocaleString('zh-CN'),
sensors: { ... },
};
// 更新AI数据中心的设备绑定状态
const allIoTDevices = localStorage.getItem('smart_agriculture_ai_iot_devices');
if (allIoTDevices) {
const devices: IoTDevice[] = JSON.parse(allIoTDevices);
const updatedDevices = devices.map(d =>
d.id === deviceForm.iotDeviceId
? {
...d,
bindingStatus: '已绑定',
bindingSystem: '地块环境监测-环境监测'
}
: d
);
localStorage.setItem('smart_agriculture_ai_iot_devices',
JSON.stringify(updatedDevices));
}
┌─────────────────────────────────────┐
│ 添加设备 │
├──────────��──────────────────────────┤
│ 设备名称: [_______________] │
│ 选择地块: [下拉选择地块] │
│ 选择设备: [本地设备类型库] │
│ 安装位置: [_______________] │
│ │
│ [取消] [保存] │
└─────────────────────────────────────┘
┌─────────────────────────────────────────────┐
│ 添加设备 │
│ 从物联设备数据接入中选择设备并配置 │
├─────────────────────────────────────────────┤
│ 选择设备: [WS-2024-001 - 1号气象站 │
│ (华为 HW-WS-Pro) ▼] │
│ │
│ 选择地块: [下拉选择地块] │
│ 安装位置: [_______________] │
│ │
│ [取消] [保存] │
└─────────────────────────────────────────────┘
type === '环境监测站' 的设备bindingStatus === '未绑定' 的设备localStorage 的 smart_agriculture_ai_iot_devices 中,bindingStatus = '未绑定'
smart_agriculture_ai_iot_devices 读取未绑定的环境监测站设备
smart_agriculture_ai_iot_devices 中对应设备的 bindingStatus = '已绑定'
设备编码 - 设备名称 (厂商 型号)| 功能 | 修改前 | 修改后 |
|---|---|---|
| 导出数据按钮 | ✅ 有 | ❌ 已移除 |
| 设备名称 | ✅ 手动输入 | ❌ 自动获取(去掉输入框) |
| 设备数据源 | 本地设备库 | AI数据中心物联设备 |
| 设备筛选 | 显示所有类型 | 只显示环境监测站且未绑定 |
| 设备信息 | 只有类型名称 | 编码+名称+厂商+型号 |
| 绑定状态 | 无 | 自动更新并同步 |
| 数据一致性 | 各系统独立 | 统一数据源 |
| 变更类型 | 内容 | 数量 |
|---|---|---|
| 删除 | Download图标导入 | 1行 |
| 删除 | 导出数据按钮 | 4行 |
| 删除 | handleExportData函数 | 3行 |
| 删除 | 本地设备库常量 | 7行 |
| 新增 | IoTDevice接口定义 | 23行 |
| 新增 | 物联设备加载逻辑 | 15行 |
| 修改 | 设备表单结构 | 10行 |
| 修改 | 添加设备弹窗 | 30行 |
| 修改 | 保存设备逻辑 | 25行 |
Ctrl + Shift + R 或 Ctrl + F5Cmd + Shift + R步骤1:清除浏览器缓存并刷新
步骤2:准备物联设备(如果还没有)
步骤3:测试环境监测
步骤4:验证绑定状态