fix: 统一馆内三维模型返回初始状态
This commit is contained in:
85
src/composables/useGuideModelState.ts
Normal file
85
src/composables/useGuideModelState.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { readonly, ref } from 'vue'
|
||||
|
||||
export type GuideModelInitialState = Readonly<{
|
||||
mode: '3d'
|
||||
indoorView: 'overview' | 'floor' | 'multi'
|
||||
layerMode: 'single' | 'multi'
|
||||
defaultActiveFloorId: string
|
||||
loadedFloorId: string
|
||||
selectedPoiId: null
|
||||
activeFocusPoiId: null
|
||||
targetFocusRequest: null
|
||||
pendingTargetFocus: null
|
||||
visiblePoiIds: null
|
||||
temporaryFocus: false
|
||||
poiInfoLabelVisible: false
|
||||
routePreviewActive: false
|
||||
navigationSimulationActive: false
|
||||
autoFloorSwitchActive: boolean
|
||||
}>
|
||||
|
||||
// The object is frozen so callers cannot accidentally turn a captured baseline into live state.
|
||||
export const GUIDE_MODEL_INITIAL_STATE: GuideModelInitialState = Object.freeze({
|
||||
mode: '3d',
|
||||
indoorView: 'overview',
|
||||
layerMode: 'single',
|
||||
defaultActiveFloorId: '',
|
||||
loadedFloorId: '',
|
||||
selectedPoiId: null,
|
||||
activeFocusPoiId: null,
|
||||
targetFocusRequest: null,
|
||||
pendingTargetFocus: null,
|
||||
visiblePoiIds: null,
|
||||
temporaryFocus: false,
|
||||
poiInfoLabelVisible: false,
|
||||
routePreviewActive: false,
|
||||
navigationSimulationActive: false,
|
||||
autoFloorSwitchActive: true
|
||||
})
|
||||
|
||||
const initialState = ref<GuideModelInitialState>(GUIDE_MODEL_INITIAL_STATE)
|
||||
const pendingModelResetAfterPoiDetail = ref(false)
|
||||
const requestGeneration = ref(0)
|
||||
|
||||
export const useGuideModelState = () => {
|
||||
const initializeModel = (floorId: string) => {
|
||||
if (initialState.value.defaultActiveFloorId) return initialState.value
|
||||
initialState.value = Object.freeze({
|
||||
...GUIDE_MODEL_INITIAL_STATE,
|
||||
defaultActiveFloorId: floorId,
|
||||
loadedFloorId: floorId
|
||||
})
|
||||
return initialState.value
|
||||
}
|
||||
|
||||
const beginPoiDetailReturn = () => {
|
||||
pendingModelResetAfterPoiDetail.value = true
|
||||
}
|
||||
|
||||
const cancelPoiDetailReturn = () => {
|
||||
pendingModelResetAfterPoiDetail.value = false
|
||||
}
|
||||
|
||||
const consumePoiDetailReturn = () => {
|
||||
if (!pendingModelResetAfterPoiDetail.value) return false
|
||||
pendingModelResetAfterPoiDetail.value = false
|
||||
return true
|
||||
}
|
||||
|
||||
// All async focus/floor operations compare this generation before committing.
|
||||
const invalidatePendingRequests = () => {
|
||||
requestGeneration.value += 1
|
||||
return requestGeneration.value
|
||||
}
|
||||
|
||||
return {
|
||||
initialState: readonly(initialState),
|
||||
pendingModelResetAfterPoiDetail: readonly(pendingModelResetAfterPoiDetail),
|
||||
requestGeneration: readonly(requestGeneration),
|
||||
initializeModel,
|
||||
beginPoiDetailReturn,
|
||||
cancelPoiDetailReturn,
|
||||
consumePoiDetailReturn,
|
||||
invalidatePendingRequests
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user