修复代码错误;修复属性查询无时间轴情况下也能查询的问题;修复工具栏定位错误的问题
This commit is contained in:
@@ -67,6 +67,9 @@ const SCADADeviceList: React.FC<SCADADeviceListProps> = ({
|
||||
const [selectedStatus, setSelectedStatus] = useState<string>("all");
|
||||
const [isExpanded, setIsExpanded] = useState<boolean>(true);
|
||||
const [internalSelection, setInternalSelection] = useState<string[]>([]);
|
||||
const [pendingSelection, setPendingSelection] = useState<string[] | null>(
|
||||
null
|
||||
);
|
||||
|
||||
const activeSelection = selectedDeviceIds ?? internalSelection;
|
||||
|
||||
@@ -76,6 +79,14 @@ const SCADADeviceList: React.FC<SCADADeviceListProps> = ({
|
||||
}
|
||||
}, [selectedDeviceIds]);
|
||||
|
||||
// 添加 useEffect 来延迟调用 onSelectionChange,避免在渲染时触发父组件的 setState
|
||||
useEffect(() => {
|
||||
if (pendingSelection !== null) {
|
||||
onSelectionChange?.(pendingSelection);
|
||||
setPendingSelection(null);
|
||||
}
|
||||
}, [pendingSelection, onSelectionChange]);
|
||||
|
||||
// 获取设备类型列表
|
||||
const deviceTypes = useMemo(() => {
|
||||
const types = Array.from(new Set(devices.map((device) => device.type)));
|
||||
@@ -154,7 +165,7 @@ const SCADADeviceList: React.FC<SCADADeviceListProps> = ({
|
||||
? []
|
||||
: [device.id];
|
||||
|
||||
onSelectionChange?.(nextSelection);
|
||||
setPendingSelection(nextSelection); // 设置待处理的 selection,延迟调用
|
||||
return nextSelection;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user