fix(scada): avoid history refetch on map zoom
This commit is contained in:
@@ -307,9 +307,15 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
|
||||
|
||||
const normalizedRange = useMemo(() => ensureValidRange(from, to), [from, to]);
|
||||
|
||||
const hasDevices = deviceIds.length > 0;
|
||||
// Parent map updates can pass a new array with identical IDs. Keep the
|
||||
// request dependency tied to the IDs themselves, not the array identity.
|
||||
const deviceIdsKey = JSON.stringify(deviceIds);
|
||||
const requestedDeviceIds = useMemo(
|
||||
() => JSON.parse(deviceIdsKey) as string[],
|
||||
[deviceIdsKey],
|
||||
);
|
||||
const hasDevices = requestedDeviceIds.length > 0;
|
||||
const hasData = timeSeries.length > 0;
|
||||
const deviceIdsKey = useMemo(() => deviceIds.join(","), [deviceIds]);
|
||||
|
||||
const dataset = useMemo(
|
||||
() => buildDataset(timeSeries, deviceIds, fractionDigits, showCleaning),
|
||||
@@ -348,7 +354,7 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
|
||||
setError(null);
|
||||
try {
|
||||
const { from: rangeFrom, to: rangeTo } = normalizedRange;
|
||||
const result = await customFetcher(deviceIds, {
|
||||
const result = await customFetcher(requestedDeviceIds, {
|
||||
from: rangeFrom.toDate(),
|
||||
to: rangeTo.toDate(),
|
||||
});
|
||||
@@ -360,7 +366,7 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
|
||||
setLoadingState("error");
|
||||
}
|
||||
},
|
||||
[deviceIds, customFetcher, hasDevices, normalizedRange],
|
||||
[requestedDeviceIds, customFetcher, hasDevices, normalizedRange],
|
||||
);
|
||||
|
||||
// 处理数据清洗
|
||||
@@ -447,7 +453,7 @@ const SCADADataPanel: React.FC<SCADADataPanelProps> = ({
|
||||
setTimeSeries([]);
|
||||
setHistorySeries([]);
|
||||
}
|
||||
}, [deviceIdsKey, handleFetch, hasDevices]);
|
||||
}, [handleFetch, hasDevices]);
|
||||
|
||||
// 当设备数量变化时,调整数据源选择
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user