From 8e187d6d4f112c80c788c4465c6af4b8079eb121 Mon Sep 17 00:00:00 2001 From: lyf <2514544224@qq.com> Date: Sun, 12 Jul 2026 22:31:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=82=B9=E4=BD=8D=E7=B2=BE?= =?UTF-8?q?=E7=A1=AE=E5=8C=B9=E9=85=8D=E5=B9=B6=E8=B0=83=E6=95=B4=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/index.vue | 2 +- src/repositories/GuideRepository.ts | 28 +++++++++++++++------------- tests/unit/GuideRepository.spec.ts | 28 ++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 576fc54..50a639e 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -383,7 +383,7 @@ const topTabFromHash = () => { const launchOverlayMinDisplayMs = 700 const launchOverlayGuideTimeoutMs = 12000 const launchOverlayNonGuideTimeoutMs = 900 -const launchOverlayDefaultText = '正在进入自然导览' +const launchOverlayDefaultText = '正在进入智能导览' const shouldShowLaunchOverlay = () => { if (typeof window === 'undefined') return false diff --git a/src/repositories/GuideRepository.ts b/src/repositories/GuideRepository.ts index 3dc2afd..03ee407 100644 --- a/src/repositories/GuideRepository.ts +++ b/src/repositories/GuideRepository.ts @@ -133,13 +133,9 @@ const dedupePoisById = (pois: MuseumPoi[]) => { const getPoiSpaceIdentity = (poi: MuseumPoi) => poi.sourceSpaceId || poi.spaceId || '' -const getPoiLookupIdentities = (id: string) => { - const normalizedId = id.trim() - return new Set([ - normalizedId, - normalizedId.replace(/^(?:hall|space)-/, '') - ].filter(Boolean)) -} +const getPoiSourceLookupIdentity = (id: string) => ( + id.trim().replace(/^(?:hall|space)-/, '') +) const mergePoiCategories = (...categoryGroups: MuseumCategory[][]) => { const seenIds = new Set() @@ -553,12 +549,18 @@ export class SgsSdkGuideRepository implements GuideRepository { async getPoiById(id: string) { const pois = await this.searchPois() - const lookupIdentities = getPoiLookupIdentities(id) - return pois.find((poi) => ( - lookupIdentities.has(poi.id) - || lookupIdentities.has(poi.spaceId || '') - || lookupIdentities.has(poi.sourceSpaceId || '') - )) + const normalizedId = id.trim() + const exactPoi = pois.find((poi) => poi.id === normalizedId) + if (exactPoi) return exactPoi + + const sourceIdentity = getPoiSourceLookupIdentity(normalizedId) + const sourcePoi = sourceIdentity + ? pois.find((poi) => ( + poi.spaceId === sourceIdentity + || poi.sourceSpaceId === sourceIdentity + )) + : undefined + return sourcePoi || findPoiByNavIdNameFallback(pois, id) } diff --git a/tests/unit/GuideRepository.spec.ts b/tests/unit/GuideRepository.spec.ts index 230aaab..0268f18 100644 --- a/tests/unit/GuideRepository.spec.ts +++ b/tests/unit/GuideRepository.spec.ts @@ -167,6 +167,34 @@ describe('SgsSdkGuideRepository 点位搜索', () => { expect(renderPois.some((poi) => poi.id === fallbackTheater?.id)).toBe(true) }) + it('精确空间 ID 与普通点位 ID 同号时不会定位到错误点位', async () => { + vi.spyOn(console, 'warn').mockImplementation(() => undefined) + const provider = createProvider({ + getFloorPois: vi.fn().mockResolvedValue([{ + ...floorPoi, + id: '42', + name: '普通卫生间' + }]), + getFloorSpaces: vi.fn().mockResolvedValue([{ + id: '42', + name: '公共空间', + type: 'public_area', + floorId: '101', + boundaryWkt: 'POLYGON((0 0, 8 0, 8 8, 0 8, 0 0))' + }]) + }) + const repository = new SgsSdkGuideRepository(provider) + + await expect(repository.getPoiById('space-42')).resolves.toMatchObject({ + id: 'space-42', + name: '公共空间' + }) + await expect(repository.getPoiById('42')).resolves.toMatchObject({ + id: '42', + name: '普通卫生间' + }) + }) + it('相同模型对象名不会删除不同稳定 ID 和坐标的普通点位', async () => { const provider = createProvider({ getFloorSpaces: vi.fn().mockResolvedValue([]),