用户在胶片1上拖拽一个图像,切换到胶片2时,这个图像也会显示在胶片2上。
// 所有 DcmCell 实例共享同一个渲染引擎
const engineId = 'myRenderingEngineForPrint';
let engine: RenderingEngine | null = cornerstone.getRenderingEngines()?.find(en => en.id === engineId) || null;
// 当前的 viewport ID 生成方式
const viewportId = useMemo(() => `stackViewport-${imageId}-${uuidv4()}`, []);
问题:
imageId 可能为 null 或相同值uuidv4() 只在组件挂载时生成一次,但由于依赖数组为空 [],无法保证真正的唯一性// 使用胶片ID + 格子索引 + UUID 确保唯一性
const viewportId = useMemo(() =>
`stackViewport-${currentFilm.id}-${indexOfCell}-${uuidv4()}`,
[currentFilm.id, indexOfCell]
);
// 方案A: 每个胶片使用独立的渲染引擎
const engineId = `renderingEngine-${currentFilm.id}`;
// 方案B: 改进现有引擎的 viewport 清理机制
// 在组件卸载时确保完全清理 viewport
// 移除 currentImageId 从依赖数组,避免无限循环
useEffect(() => {
// ...
}, [imageId, stackViewport]);