统一首页点位详情目标解析
This commit is contained in:
@@ -248,7 +248,7 @@ const resolveFacilityPoi = async () => {
|
||||
if (poiById) return poiById
|
||||
|
||||
// 搜索结果必须按稳定 ID 解析,避免同名点位被定位到错误楼层。
|
||||
if (searchContext.value.source === 'search') return null
|
||||
if (searchContext.value.source === 'search' || searchContext.value.source === 'guide-poi') return null
|
||||
|
||||
const poiByHall = await resolvePoiFromHall()
|
||||
if (poiByHall) return poiByHall
|
||||
@@ -273,7 +273,10 @@ const resolveFacilityPoi = async () => {
|
||||
}
|
||||
|
||||
const resolveRenderPoi = async () => {
|
||||
const resolveByExactId = searchContext.value.source === 'search' && Boolean(facility.value.id)
|
||||
const resolveByExactId = (
|
||||
searchContext.value.source === 'search'
|
||||
|| searchContext.value.source === 'guide-poi'
|
||||
) && Boolean(facility.value.id)
|
||||
const normalizedTarget = normalizePoiName(facility.value.name)
|
||||
if (!resolveByExactId && !normalizedTarget) return null
|
||||
|
||||
|
||||
@@ -99,11 +99,11 @@
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
v-if="selectedGuidePoiExplainHall"
|
||||
v-if="selectedGuidePoiDetailTarget"
|
||||
class="poi-card-actions"
|
||||
>
|
||||
<view class="poi-action primary" @tap="handleViewSelectedHall">
|
||||
<text class="poi-action-text">查看展厅</text>
|
||||
<view class="poi-action primary" @tap="handleViewSelectedPoiDetail">
|
||||
<text class="poi-action-text">{{ selectedGuidePoiDetailActionText }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -316,6 +316,11 @@ import {
|
||||
import {
|
||||
explainUseCase
|
||||
} from '@/usecases/explainUseCase'
|
||||
import {
|
||||
poiDetailUseCase,
|
||||
type PoiDetailSource,
|
||||
type PoiDetailTarget
|
||||
} from '@/usecases/poiDetailUseCase'
|
||||
import type {
|
||||
GuideRenderPoi
|
||||
} from '@/domain/guideModel'
|
||||
@@ -341,7 +346,6 @@ import type {
|
||||
GuideRouteResult,
|
||||
GuideRouteTarget,
|
||||
MuseumFloor,
|
||||
MuseumHall,
|
||||
MuseumPoi
|
||||
} from '@/domain/museum'
|
||||
import { getFloorSortLevel } from '@/domain/guideFloor'
|
||||
@@ -397,8 +401,19 @@ const loadingFloorId = ref('')
|
||||
const renderedFloorId = ref('')
|
||||
const failedFloorId = ref('')
|
||||
const selectedGuidePoi = ref<GuideRenderPoi | null>(null)
|
||||
const selectedGuidePoiExplainHall = ref<MuseumHall | null>(null)
|
||||
let selectedGuidePoiExplainHallRequestId = 0
|
||||
const selectedGuidePoiDetailTarget = ref<PoiDetailTarget | null>(null)
|
||||
let poiDetailResolutionRequestId = 0
|
||||
|
||||
type PoiDetailUiContext = Readonly<{
|
||||
source: PoiDetailSource
|
||||
categoryModeActive: boolean
|
||||
visiblePoiIds: string[] | null
|
||||
}>
|
||||
|
||||
let pendingPoiDetailUiContext: Readonly<{
|
||||
requestId: number
|
||||
value: PoiDetailUiContext
|
||||
}> | null = null
|
||||
|
||||
// 状态
|
||||
const currentTab = ref<GuideTopTab>(initialTopTab())
|
||||
@@ -726,9 +741,18 @@ const isGuidePoiHallLike = (poi: GuideRenderPoi | null) => Boolean(
|
||||
const selectedGuidePoiIsHall = computed(() => isGuidePoiHallLike(selectedGuidePoi.value))
|
||||
|
||||
const selectedGuidePoiCollapsedSubtitle = computed(() => (
|
||||
selectedGuidePoiExplainHall.value ? '点按展开查看展厅' : selectedGuidePoiSubtitle.value
|
||||
selectedGuidePoiDetailTarget.value?.detailType === 'hall'
|
||||
? '点按展开查看展厅'
|
||||
: selectedGuidePoiSubtitle.value
|
||||
))
|
||||
|
||||
const selectedGuidePoiDetailActionText = computed(() => {
|
||||
const detailType = selectedGuidePoiDetailTarget.value?.detailType
|
||||
if (detailType === 'hall') return '查看展厅'
|
||||
if (detailType === 'exhibit') return '查看展品'
|
||||
return '查看详情'
|
||||
})
|
||||
|
||||
const routeSimulationStepText = computed(() => {
|
||||
if (!activeRoutePreview.value) return '位置预览 · 查看位置关系'
|
||||
const hasConnector = activeRoutePreview.value.connectorPoints.length > 0
|
||||
@@ -1127,110 +1151,63 @@ const togglePoiCardCollapsed = () => {
|
||||
isPoiCardCollapsed.value = !isPoiCardCollapsed.value
|
||||
}
|
||||
|
||||
const normalizeHallMatchText = (value?: string) => (value || '')
|
||||
.trim()
|
||||
.replace(/[\s()()【】[\]_-]/g, '')
|
||||
.replace(/^展厅\d+/, '')
|
||||
.toLowerCase()
|
||||
|
||||
const resolvePoiExplainHall = async (poi: GuideRenderPoi): Promise<MuseumHall | null> => {
|
||||
const halls = await explainUseCase.listHalls()
|
||||
const matchedByPoiId = halls.find((hall) => (
|
||||
hall.poiId === poi.id
|
||||
|| hall.location?.poiId === poi.id
|
||||
))
|
||||
if (matchedByPoiId) return matchedByPoiId
|
||||
|
||||
const hallId = poi.hallId
|
||||
if (hallId) {
|
||||
const matchedById = halls.find((hall) => hall.id === hallId)
|
||||
if (matchedById) return matchedById
|
||||
}
|
||||
|
||||
const matchedByEntrance = halls.find((hall) => (
|
||||
(poi.entrances || []).some((entrance) => (
|
||||
hall.poiId === entrance.sourcePlaceId
|
||||
|| hall.poiId === entrance.id
|
||||
))
|
||||
))
|
||||
if (matchedByEntrance) return matchedByEntrance
|
||||
|
||||
const poiHallName = normalizeHallMatchText(poi.hallName || poi.name)
|
||||
return halls.find((hall) => {
|
||||
const hallName = normalizeHallMatchText(hall.name)
|
||||
return hallName && poiHallName && hallName === poiHallName
|
||||
}) || null
|
||||
}
|
||||
|
||||
watch(selectedGuidePoi, (poi) => {
|
||||
const requestId = ++selectedGuidePoiExplainHallRequestId
|
||||
selectedGuidePoiExplainHall.value = null
|
||||
if (!poi || !isGuidePoiHallLike(poi)) return
|
||||
const requestId = ++poiDetailResolutionRequestId
|
||||
selectedGuidePoiDetailTarget.value = null
|
||||
if (!poi) return
|
||||
|
||||
void resolvePoiExplainHall(poi)
|
||||
.then((hall) => {
|
||||
void poiDetailUseCase.resolve(poi)
|
||||
.then((target) => {
|
||||
if (
|
||||
requestId !== selectedGuidePoiExplainHallRequestId
|
||||
requestId !== poiDetailResolutionRequestId
|
||||
|| selectedGuidePoi.value?.id !== poi.id
|
||||
) return
|
||||
|
||||
selectedGuidePoiExplainHall.value = hall
|
||||
selectedGuidePoiDetailTarget.value = target
|
||||
})
|
||||
.catch((error) => {
|
||||
if (requestId !== selectedGuidePoiExplainHallRequestId) return
|
||||
console.warn('点位讲解展厅关联解析失败:', error)
|
||||
if (requestId !== poiDetailResolutionRequestId) return
|
||||
console.warn('点位详情目标解析失败:', error)
|
||||
})
|
||||
}, { flush: 'sync' })
|
||||
|
||||
const navigateToPoiDetail = ({
|
||||
url,
|
||||
floorId,
|
||||
failureMessage
|
||||
}: {
|
||||
url: string
|
||||
floorId: string
|
||||
failureMessage: string
|
||||
}) => {
|
||||
const returnContext = guideModelState.beginPoiDetailReturn(floorId)
|
||||
const navigateToPoiDetailTarget = (
|
||||
target: PoiDetailTarget,
|
||||
uiContext: PoiDetailUiContext
|
||||
) => {
|
||||
const returnContext = guideModelState.beginPoiDetailReturn(target.floorId)
|
||||
pendingPoiDetailUiContext = {
|
||||
requestId: returnContext.requestId,
|
||||
value: uiContext
|
||||
}
|
||||
uni.navigateTo({
|
||||
url,
|
||||
url: target.url,
|
||||
success: () => {
|
||||
guideModelState.confirmPoiDetailReturn(returnContext.requestId)
|
||||
},
|
||||
fail: () => {
|
||||
guideModelState.cancelPoiDetailReturn(returnContext.requestId)
|
||||
if (pendingPoiDetailUiContext?.requestId === returnContext.requestId) {
|
||||
pendingPoiDetailUiContext = null
|
||||
}
|
||||
uni.showToast({
|
||||
title: failureMessage,
|
||||
title: target.failureMessage,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const navigateFromSelectedPoiToDetail = (url: string) => {
|
||||
const poi = selectedGuidePoi.value
|
||||
if (!poi) return
|
||||
|
||||
// Detail pages do not own the mounted renderer. The homepage consumes this once on return.
|
||||
navigateToPoiDetail({
|
||||
url,
|
||||
floorId: poi.floorId,
|
||||
failureMessage: '讲解详情打开失败,请重试'
|
||||
const handleViewSelectedPoiDetail = () => {
|
||||
const target = selectedGuidePoiDetailTarget.value
|
||||
if (!target) return
|
||||
navigateToPoiDetailTarget(target, {
|
||||
source: 'map',
|
||||
categoryModeActive: false,
|
||||
visiblePoiIds: null
|
||||
})
|
||||
}
|
||||
|
||||
const navigateToHallExplainObjects = (hallId: string, hallName = '讲解') => {
|
||||
navigateFromSelectedPoiToDetail(
|
||||
explainGuideStopListUrl(hallId, hallName)
|
||||
)
|
||||
}
|
||||
|
||||
const handleViewSelectedHall = () => {
|
||||
const hall = selectedGuidePoiExplainHall.value
|
||||
if (!hall) return
|
||||
navigateToHallExplainObjects(hall.id, hall.name)
|
||||
}
|
||||
|
||||
const loadRouteTargets = async (keyword = '') => {
|
||||
routeTargetsLoading.value = true
|
||||
routeTargetsError.value = ''
|
||||
@@ -1579,10 +1556,20 @@ onShow(async () => {
|
||||
await nextTick()
|
||||
const detailReturnContext = guideModelState.consumePoiDetailReturn()
|
||||
if (detailReturnContext) {
|
||||
const uiContext = pendingPoiDetailUiContext?.requestId === detailReturnContext.requestId
|
||||
? pendingPoiDetailUiContext.value
|
||||
: null
|
||||
pendingPoiDetailUiContext = null
|
||||
await resetGuideModelToFloorBaseline({
|
||||
rendererReason: 'poi-detail-close',
|
||||
floorId: detailReturnContext.floorId
|
||||
})
|
||||
if (uiContext?.source === 'search') {
|
||||
homeCategoryModeActive.value = uiContext.categoryModeActive
|
||||
searchVisiblePoiIds.value = uiContext.visiblePoiIds
|
||||
? [...uiContext.visiblePoiIds]
|
||||
: null
|
||||
}
|
||||
await homeSearchPanelRef.value?.restoreResultListScroll?.()
|
||||
return
|
||||
}
|
||||
@@ -1658,38 +1645,28 @@ const handleHomeSearchResultsChange = (state: PoiCategoryResultState) => {
|
||||
}
|
||||
}
|
||||
|
||||
const createSearchDetailUrl = (poi: MuseumPoi, context: PoiSearchContext) => {
|
||||
const resultCount = homeCategoryModeActive.value
|
||||
? context.floorResultCount
|
||||
: context.resultCount
|
||||
const params = new URLSearchParams({
|
||||
source: 'search',
|
||||
searchOrigin: context.origin,
|
||||
searchKeyword: context.keyword,
|
||||
searchCategoryId: context.categoryId,
|
||||
searchFloorId: context.floorId,
|
||||
searchFloorLabel: context.floorLabel,
|
||||
resultCount: String(Math.max(1, resultCount)),
|
||||
floorResultCount: String(context.floorResultCount),
|
||||
visiblePoiIds: context.visiblePoiIds.join(','),
|
||||
listScrollTop: String(context.listScrollTop),
|
||||
id: poi.id,
|
||||
target: poi.name,
|
||||
floorId: poi.floorId,
|
||||
floorLabel: poi.floorLabel
|
||||
})
|
||||
|
||||
return `/pages/facility/detail?${params.toString()}`
|
||||
}
|
||||
|
||||
const handleHomeSearchResultTap = async (poi: MuseumPoi, context: PoiSearchContext) => {
|
||||
// The homepage keeps its renderer mounted; detail close is consumed by onShow once.
|
||||
const requestId = ++poiDetailResolutionRequestId
|
||||
const categoryModeActive = homeCategoryModeActive.value
|
||||
const visiblePoiIds = categoryModeActive
|
||||
? [...context.visiblePoiIds]
|
||||
: searchVisiblePoiIds.value
|
||||
? [...searchVisiblePoiIds.value]
|
||||
: null
|
||||
searchTargetFocusRequest.value = null
|
||||
navigateToPoiDetail({
|
||||
url: createSearchDetailUrl(poi, context),
|
||||
floorId: poi.floorId,
|
||||
failureMessage: '点位详情打开失败,请重试'
|
||||
})
|
||||
try {
|
||||
const target = await poiDetailUseCase.resolve(poi)
|
||||
if (requestId !== poiDetailResolutionRequestId) return
|
||||
navigateToPoiDetailTarget(target, {
|
||||
source: 'search',
|
||||
categoryModeActive,
|
||||
visiblePoiIds
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestId !== poiDetailResolutionRequestId) return
|
||||
console.warn('搜索点位详情目标解析失败:', error)
|
||||
uni.showToast({ title: '点位详情解析失败,请重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
const handleHomeSearchCancel = () => {
|
||||
|
||||
Reference in New Issue
Block a user