|
|
|
@ -42,6 +42,7 @@ function SystemSettings() { |
|
|
|
// 实时数据记录状态 |
|
|
|
const [realtimeDataEnabled, setRealtimeDataEnabled] = useState(false) |
|
|
|
const [alarmDataEnabled, setAlarmDataEnabled] = useState(false) |
|
|
|
const [distanceDrafts, setDistanceDrafts] = useState({}) |
|
|
|
|
|
|
|
// 算法设置 Modal 状态 |
|
|
|
const [algorithmModalVisible, setAlgorithmModalVisible] = useState(false) |
|
|
|
@ -178,6 +179,29 @@ function SystemSettings() { |
|
|
|
setActiveCorrectionDistance |
|
|
|
]) |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
setDistanceDrafts((prevDrafts) => { |
|
|
|
const nextDrafts = {} |
|
|
|
let changed = false |
|
|
|
|
|
|
|
correctionProfiles.forEach((profile) => { |
|
|
|
const draftValue = prevDrafts[profile.distance] |
|
|
|
nextDrafts[profile.distance] = |
|
|
|
draftValue === undefined ? String(profile.distance) : draftValue |
|
|
|
|
|
|
|
if (nextDrafts[profile.distance] !== prevDrafts[profile.distance]) { |
|
|
|
changed = true |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
if (Object.keys(prevDrafts).length !== correctionProfiles.length) { |
|
|
|
changed = true |
|
|
|
} |
|
|
|
|
|
|
|
return changed ? nextDrafts : prevDrafts |
|
|
|
}) |
|
|
|
}, [correctionProfiles]) |
|
|
|
|
|
|
|
// 新增:写入实时数据到CSV文件 |
|
|
|
const writeRealtimeDataToCSV = useCallback( |
|
|
|
async (data) => { |
|
|
|
@ -760,6 +784,12 @@ function SystemSettings() { |
|
|
|
activeCorrectionDistance === distance ? normalizedDistance : activeCorrectionDistance |
|
|
|
|
|
|
|
persistCorrectionConfig(nextProfiles, nextActiveDistance) |
|
|
|
setDistanceDrafts((prev) => { |
|
|
|
const next = { ...prev } |
|
|
|
delete next[distance] |
|
|
|
next[normalizedDistance] = String(normalizedDistance) |
|
|
|
return next |
|
|
|
}) |
|
|
|
message.success(`已更新 ${normalizedDistance} 米距离配置`) |
|
|
|
return |
|
|
|
} |
|
|
|
@ -802,14 +832,44 @@ function SystemSettings() { |
|
|
|
persistCorrectionConfig(nextConfig.profiles, nextConfig.activeDistance) |
|
|
|
setActiveCorrectionByDistance(nextConfig.activeDistance) |
|
|
|
|
|
|
|
if (nextConfig.activeDistance === DEFAULT_CORRECTION_DISTANCE && distance === activeCorrectionDistance) { |
|
|
|
message.success(`已删除 ${distance} 米配置,当前已切换到 ${DEFAULT_CORRECTION_DISTANCE} 米`) |
|
|
|
if (distance === activeCorrectionDistance && nextConfig.activeDistance !== distance) { |
|
|
|
message.success(`已删除 ${distance} 米配置,当前已切换到 ${nextConfig.activeDistance} 米`) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
message.success(`已删除 ${distance} 米修正系数`) |
|
|
|
} |
|
|
|
|
|
|
|
const handleDistanceDraftChange = (distance, value) => { |
|
|
|
setDistanceDrafts((prev) => ({ |
|
|
|
...prev, |
|
|
|
[distance]: value == null ? '' : String(value) |
|
|
|
})) |
|
|
|
} |
|
|
|
|
|
|
|
const commitDistanceDraft = (distance) => { |
|
|
|
const draftValue = distanceDrafts[distance] |
|
|
|
const normalizedDistance = Number(draftValue) |
|
|
|
|
|
|
|
if (!Number.isInteger(normalizedDistance) || normalizedDistance <= 0) { |
|
|
|
setDistanceDrafts((prev) => ({ |
|
|
|
...prev, |
|
|
|
[distance]: String(distance) |
|
|
|
})) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if (normalizedDistance === distance) { |
|
|
|
setDistanceDrafts((prev) => ({ |
|
|
|
...prev, |
|
|
|
[distance]: String(distance) |
|
|
|
})) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
handleCorrectionProfileChange(distance, 'distance', normalizedDistance) |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
|
<Flex vertical gap={4} className={styles.container}> |
|
|
|
<div className={styles.header}> |
|
|
|
@ -1087,10 +1147,11 @@ function SystemSettings() { |
|
|
|
<div className={styles.correctionCardList}> |
|
|
|
{correctionProfiles.map((profile) => { |
|
|
|
const isActive = profile.distance === activeCorrectionDistance |
|
|
|
const distanceDraft = distanceDrafts[profile.distance] |
|
|
|
|
|
|
|
return ( |
|
|
|
<div |
|
|
|
key={profile.distance} |
|
|
|
key={`correction-profile-${profile.distance}`} |
|
|
|
className={`${styles.correctionCard} ${isActive ? styles.correctionCardActive : ''}`} |
|
|
|
> |
|
|
|
<div className={styles.correctionCardHeader}> |
|
|
|
@ -1128,10 +1189,10 @@ function SystemSettings() { |
|
|
|
<InputNumber |
|
|
|
min={1} |
|
|
|
precision={0} |
|
|
|
value={profile.distance} |
|
|
|
onChange={(nextValue) => |
|
|
|
handleCorrectionProfileChange(profile.distance, 'distance', nextValue) |
|
|
|
} |
|
|
|
value={distanceDraft === undefined || distanceDraft === '' ? null : Number(distanceDraft)} |
|
|
|
onChange={(nextValue) => handleDistanceDraftChange(profile.distance, nextValue)} |
|
|
|
onBlur={() => commitDistanceDraft(profile.distance)} |
|
|
|
onPressEnter={() => commitDistanceDraft(profile.distance)} |
|
|
|
className={styles.correctionDistanceInput} |
|
|
|
/> |
|
|
|
</div> |
|
|
|
|