修复室内导览楼层切换事务一致性

This commit is contained in:
lyf
2026-06-30 20:46:14 +08:00
parent 2376923915
commit f13d53d536
3 changed files with 249 additions and 165 deletions

View File

@@ -445,6 +445,7 @@ const activeFloorId = computed(() => {
return normalizedFloor?.id || normalizedFloorId
})
const activeFloorScrollIntoView = ref('')
const pendingFloorId = ref('')
let suppressFloorAutoScrollUntil = 0
const syncActiveFloorScroll = () => {
@@ -523,15 +524,31 @@ const handleModeChange = (mode: '2d' | '3d') => {
emit('modeChange', mode)
}
const isStaleFloorSwitchError = (error: unknown) => (
error instanceof Error && error.message === 'STALE_MODEL_LOAD'
)
const handleFloorChange = (floor: { id: string; label: string }) => {
const floorId = floor.id || props.normalizeFloorId(floor.label)
if (!floorId || pendingFloorId.value === floorId) return
pendingFloorId.value = floorId
suppressFloorAutoScrollUntil = Date.now() + 650
activeFloorScrollIntoView.value = ''
indoorRendererRef.value?.disableAutoSwitchTemporarily?.(10000)
void indoorRendererRef.value?.switchFloor?.(floorId)
emit('indoorViewChange', 'floor')
emit('layerModeChange', 'single')
emit('floorChange', floor.label)
Promise.resolve(indoorRendererRef.value?.switchFloor?.(floorId))
.catch((error) => {
if (isStaleFloorSwitchError(error)) return
console.error('楼层切换失败:', error)
})
.finally(() => {
if (pendingFloorId.value === floorId) {
pendingFloorId.value = ''
}
})
}
const handleLayerModeChange = (mode: LayerDisplayMode) => {
@@ -539,10 +556,22 @@ const handleLayerModeChange = (mode: LayerDisplayMode) => {
indoorRendererRef.value?.disableAutoSwitchTemporarily?.(10000)
if (mode === 'multi') {
pendingFloorId.value = ''
void indoorRendererRef.value?.showMultiFloor?.()
emit('indoorViewChange', 'multi')
} else {
void indoorRendererRef.value?.switchFloor?.(activeFloorId.value)
const floorId = activeFloorId.value
pendingFloorId.value = floorId
Promise.resolve(indoorRendererRef.value?.switchFloor?.(floorId))
.catch((error) => {
if (isStaleFloorSwitchError(error)) return
console.error('楼层切换失败:', error)
})
.finally(() => {
if (pendingFloorId.value === floorId) {
pendingFloorId.value = ''
}
})
emit('indoorViewChange', 'floor')
}
@@ -593,8 +622,7 @@ const handleMoreTap = () => {
}
const handleThreeFloorChange = (floorId: string) => {
const floor = indoorFloors.value.find((item) => item.id === floorId)
emit('floorChange', floor?.label || floorId)
emit('floorChange', floorId)
emit('indoorViewChange', 'floor')
emit('layerModeChange', 'single')
}