修复点位楼层跳转并优化模型加载缓存

This commit is contained in:
lyf
2026-07-02 16:42:38 +08:00
parent 7cda427de9
commit 9b1f855515
8 changed files with 750 additions and 41 deletions

View File

@@ -104,6 +104,7 @@ const normalizeGuideFloorId = (labelOrId: string) =>
|| guideUseCase.normalizeFloorId(labelOrId)
const activeMode = ref<'2d' | '3d'>('3d')
const activeFloor = ref('1F')
const requestedTargetFloorId = ref('')
const targetFocusRequest = ref<TargetPoiFocusRequestViewModel | null>(null)
const targetFocusRequestId = ref(0)
const isDetailPanelVisible = ref(true)
@@ -200,6 +201,14 @@ const normalizePoiName = (value: string) => value
.replace(/[\s()【】[\]_-]/g, '')
.toLowerCase()
const decodeRouteText = (value: unknown) => (
typeof value === 'string' ? decodeURIComponent(value) : ''
)
const isPoiOnRequestedFloor = (poi: Pick<MuseumPoi | GuideRenderPoi, 'floorId'>) => (
!requestedTargetFloorId.value || poi.floorId === requestedTargetFloorId.value
)
const resolvePoiFromHall = async () => {
if (!facility.value.id) return null
@@ -221,14 +230,19 @@ const resolveFacilityPoi = async () => {
if (!normalizedTarget) return null
const candidates = await guideUseCase.searchPois(facility.value.name)
return candidates.find((candidate) => {
const floorMatchedCandidates = requestedTargetFloorId.value
? candidates.filter(isPoiOnRequestedFloor)
: candidates
const candidatesToMatch = floorMatchedCandidates.length ? floorMatchedCandidates : candidates
return candidatesToMatch.find((candidate) => {
const candidateName = normalizePoiName(candidate.name)
const candidateHallName = normalizePoiName(candidate.hallName || '')
return candidateName === normalizedTarget
|| candidateHallName === normalizedTarget
|| candidateName.includes(normalizedTarget)
|| normalizedTarget.includes(candidateName)
}) || candidates[0] || null
}) || candidatesToMatch[0] || null
}
const resolveRenderPoiByName = async () => {
@@ -236,7 +250,11 @@ const resolveRenderPoiByName = async () => {
if (!normalizedTarget) return null
const modelPackage = await indoorModelSource.loadPackage()
for (const floor of modelPackage.floors) {
const floorsToSearch = requestedTargetFloorId.value
? modelPackage.floors.filter((floor) => floor.floorId === requestedTargetFloorId.value)
: modelPackage.floors
for (const floor of floorsToSearch) {
const floorId = floor.floorId
const pois = await indoorModelSource.loadFloorPois(floorId).catch(() => [])
const matchedPoi = pois.find((poi) => {
@@ -279,11 +297,24 @@ onLoad(async (options: any) => {
await loadGuideFloors()
if (options.id) {
facility.value.id = options.id
facility.value.id = decodeRouteText(options.id)
}
if (options.target) {
facility.value.name = decodeURIComponent(options.target)
facility.value.name = decodeRouteText(options.target)
}
if (options.floorId) {
requestedTargetFloorId.value = normalizeGuideFloorId(decodeRouteText(options.floorId))
if (requestedTargetFloorId.value) {
activeFloor.value = requestedTargetFloorId.value
}
}
if (options.floorLabel && requestedTargetFloorId.value) {
const floorLabel = decodeRouteText(options.floorLabel)
facility.value.location = `${floorLabel} · 位置预览`
facility.value.tags = [floorLabel, '三维位置', '位置预览']
}
if (!facility.value.id && !normalizePoiName(facility.value.name)) return
@@ -291,13 +322,6 @@ onLoad(async (options: any) => {
try {
const routeReadinessMessage = guideUseCase.getRouteReadinessSnapshot().message
// 详情页以位置预览为主,优先使用模型点位,避免旧内容兜底覆盖真实三维点位。
const renderPoi = await tryResolveRenderPoiByName()
if (renderPoi) {
applyRenderPoiToFacility(renderPoi, routeReadinessMessage)
return
}
const poi = await tryResolveFacilityPoi()
if (poi) {
facility.value = toFacilityDetailViewModel(
@@ -305,6 +329,12 @@ onLoad(async (options: any) => {
routeReadinessMessage
)
focusFacilityPoi(poi)
return
}
const renderPoi = await tryResolveRenderPoiByName()
if (renderPoi) {
applyRenderPoiToFacility(renderPoi, routeReadinessMessage)
}
} catch (error) {
console.error('加载设施位置详情失败:', error)