import React, { useEffect } from "react"; import { Card, Input, Slider, InputNumber, Switch, Select, Row, Col, Button, message, Space, Typography, Spin, Alert, } from "antd"; import { SettingOutlined, SaveOutlined, DatabaseOutlined, ClockCircleOutlined, BellOutlined, FilterOutlined, CloudUploadOutlined, SyncOutlined, } from "@ant-design/icons"; import useAdvancedSettings from "../hooks/useAdvancedSettings"; const { Option } = Select; const { Title, Text } = Typography; const AdvancedSettings = ({ onLogout }) => { // 使用高级配置 Hook const { settings, loading, isConnected, isReady, fetchAllSettings, saveAllSettings, resetSettings, updateLocalSettings, } = useAdvancedSettings(); // 只在首次 isReady 变为 true 时自动拉取配置 const hasFetchedRef = React.useRef(false); useEffect(() => { if (isReady && !hasFetchedRef.current) { fetchAllSettings(); hasFetchedRef.current = true; } }, [isReady, fetchAllSettings]); // 从 settings 中提取配置 const deviceId = settings.deviceId; const fps = settings.dataFps; const enableOfflineAlert = settings.alertConfig?.enable ?? false; const offlineThreshold = settings.alertConfig?.intervalSec ?? 60; const enableFiltering = settings.filterConfig?.enable ?? true; const filterMethod = settings.filterConfig?.method ?? 'median'; const windowSize = settings.filterConfig?.size ?? 5; const filterThreshold = settings.filterConfig?.threshold ?? 0.1; const flowThreshold = settings.filterConfig?.imgThreshold ?? 10.0; const enableMqtt = settings.mqttConfig?.enable ?? true; const brokerAddress = settings.mqttConfig?.mqtt?.broker ?? ''; const mqttPort = settings.mqttConfig?.mqtt?.port ?? 1883; const mqttTopic = settings.mqttConfig?.mqtt?.topic ?? ''; const mqttClientId = settings.mqttConfig?.mqtt?.client_id ?? ''; const mqttUsername = settings.mqttConfig?.mqtt?.username ?? ''; const mqttPassword = settings.mqttConfig?.mqtt?.password ?? ''; // 更新本地状态的辅助函数 const setDeviceId = (value) => updateLocalSettings({ deviceId: value }); const setFps = (value) => updateLocalSettings({ dataFps: value }); const setEnableOfflineAlert = (value) => updateLocalSettings({ alertConfig: { enable: value, intervalSec: settings.alertConfig?.intervalSec ?? 60 }, }); const setOfflineThreshold = (value) => updateLocalSettings({ alertConfig: { enable: settings.alertConfig?.enable ?? false, intervalSec: value }, }); const setEnableFiltering = (value) => updateLocalSettings({ filterConfig: { ...settings.filterConfig, enable: value }, }); const setFilterMethod = (value) => updateLocalSettings({ filterConfig: { ...settings.filterConfig, method: value }, }); const setWindowSize = (value) => updateLocalSettings({ filterConfig: { ...settings.filterConfig, size: value }, }); const setFilterThreshold = (value) => updateLocalSettings({ filterConfig: { ...settings.filterConfig, threshold: -Math.abs(value) }, }); const setFlowThreshold = (value) => updateLocalSettings({ filterConfig: { ...settings.filterConfig, imgThreshold: value }, }); const setEnableMqtt = (value) => updateLocalSettings({ mqttConfig: { enable: value, mqtt: settings.mqttConfig?.mqtt ?? { broker: '', port: 1883, topic: '', username: '', password: '', client_id: '' } }, }); const setBrokerAddress = (value) => updateLocalSettings({ mqttConfig: { ...settings.mqttConfig, mqtt: { ...(settings.mqttConfig?.mqtt ?? {}), broker: value }, }, }); const setMqttPort = (value) => updateLocalSettings({ mqttConfig: { ...settings.mqttConfig, mqtt: { ...(settings.mqttConfig?.mqtt ?? {}), port: value }, }, }); const setMqttTopic = (value) => updateLocalSettings({ mqttConfig: { ...settings.mqttConfig, mqtt: { ...(settings.mqttConfig?.mqtt ?? {}), topic: value }, }, }); const setMqttClientId = (value) => updateLocalSettings({ mqttConfig: { ...settings.mqttConfig, mqtt: { ...(settings.mqttConfig?.mqtt ?? {}), client_id: value }, }, }); const setMqttUsername = (value) => updateLocalSettings({ mqttConfig: { ...settings.mqttConfig, mqtt: { ...(settings.mqttConfig?.mqtt ?? {}), username: value }, }, }); const setMqttPassword = (value) => updateLocalSettings({ mqttConfig: { ...settings.mqttConfig, mqtt: { ...(settings.mqttConfig?.mqtt ?? {}), password: value }, }, }); const handleSave = () => { saveAllSettings(); }; const handleReset = () => { fetchAllSettings(); }; return (
{/* WebSocket 连接状态提示 */} {!isConnected && ( )} <SettingOutlined /> 高级参数配置 针对下位机运行的参数配置,修改后请及时保存(慎用) 基础设备信息 } style={{ marginBottom: 12, borderRadius: 12, paddingLeft: 24, paddingRight: 24, }} >
设备编码
setDeviceId(e.target.value)} placeholder="请输入设备编码" size="large" style={{ borderRadius: 8 }} />
数据帧率 (FPS) } style={{ marginBottom: 12, borderRadius: 12, paddingLeft: 24, paddingRight: 24, }} >
数据帧率
有效范围 1~30 Hz
异常监控与报警 } style={{ marginBottom: 12, borderRadius: 12, paddingLeft: 24, paddingRight: 24, }} >
启用离线超时告警
超过此时长未接收到新数据则触发报警
超时阈值
数据滤波与异常记录 } style={{ marginBottom: 12, borderRadius: 12, paddingLeft: 24, paddingRight: 24, }} >
滤波配置
启用数据滤波算法
滤波方法
窗口大小
滤波阈值
波动阈值
数据上报 (MQTT)
} style={{ borderRadius: 12, paddingLeft: 24, paddingRight: 24, }} >
Broker Address
setBrokerAddress(e.target.value)} placeholder="例如: 218.3.126.49" size="large" disabled={!enableMqtt} style={{ borderRadius: 8 }} />
Port
setMqttPort(e.target.value)} placeholder="1883" size="large" disabled={!enableMqtt} style={{ borderRadius: 8 }} />
Topic
setMqttTopic(e.target.value)} placeholder="例如: wybb/z/mqtt179" size="large" disabled={!enableMqtt} style={{ borderRadius: 8 }} />
Client ID
setMqttClientId(e.target.value)} placeholder="wybb_z1_123" size="large" disabled={!enableMqtt} style={{ borderRadius: 8 }} />
Username
setMqttUsername(e.target.value)} placeholder="用户名" size="large" disabled={!enableMqtt} style={{ borderRadius: 8 }} />
Password
setMqttPassword(e.target.value)} placeholder="密码" size="large" disabled={!enableMqtt} style={{ borderRadius: 8 }} />
); }; export default AdvancedSettings;