提交H5业务闭环修复代码
This commit is contained in:
@@ -68,6 +68,35 @@ const toSearchText = (poi: MuseumPoi) => [
|
||||
.join(' ')
|
||||
.toLowerCase()
|
||||
|
||||
const normalizePoiLookupText = (value: string) => value
|
||||
.trim()
|
||||
.replace(/[\s()()【】[\]_-]/g, '')
|
||||
.toLowerCase()
|
||||
|
||||
const extractNameFromNavPoiId = (id: string) => {
|
||||
const normalized = id.trim()
|
||||
if (!normalized.startsWith('poi_')) return ''
|
||||
|
||||
const segments = normalized.split('_')
|
||||
if (segments.length < 3) return ''
|
||||
|
||||
return segments.slice(2).join('_')
|
||||
}
|
||||
|
||||
const findPoiByNavIdNameFallback = (pois: MuseumPoi[], id: string) => {
|
||||
const targetName = normalizePoiLookupText(extractNameFromNavPoiId(id))
|
||||
if (!targetName) return null
|
||||
|
||||
return pois.find((poi) => {
|
||||
const name = normalizePoiLookupText(poi.name)
|
||||
const hallName = normalizePoiLookupText(poi.hallName || '')
|
||||
return name === targetName
|
||||
|| hallName === targetName
|
||||
|| (name && (name.includes(targetName) || targetName.includes(name)))
|
||||
|| (hallName && (hallName.includes(targetName) || targetName.includes(hallName)))
|
||||
}) || null
|
||||
}
|
||||
|
||||
const toLocationPreview = (poi: MuseumPoi): GuideLocationPreview => ({
|
||||
poiId: poi.id,
|
||||
name: poi.name,
|
||||
@@ -148,7 +177,7 @@ export class StaticGuideRepository implements GuideRepository {
|
||||
|
||||
async getPoiById(id: string) {
|
||||
const pois = await this.listPois()
|
||||
return pois.find((poi) => poi.id === id) || null
|
||||
return pois.find((poi) => poi.id === id) || findPoiByNavIdNameFallback(pois, id)
|
||||
}
|
||||
|
||||
async searchPois(keyword = '') {
|
||||
@@ -226,6 +255,7 @@ export class SgsSdkGuideRepository implements GuideRepository {
|
||||
private floorsCache: MuseumFloor[] | null = null
|
||||
private poiCache: MuseumPoi[] | null = null
|
||||
private floorAliases: Map<string, string> | null = null
|
||||
private readonly staticFallback = new StaticGuideRepository()
|
||||
|
||||
constructor(private readonly provider: SgsSdkApiProvider = defaultSgsSdkApiProvider) {}
|
||||
|
||||
@@ -299,7 +329,9 @@ export class SgsSdkGuideRepository implements GuideRepository {
|
||||
|
||||
async getPoiById(id: string) {
|
||||
const pois = await this.listPois()
|
||||
return pois.find((poi) => poi.id === id) || null
|
||||
return pois.find((poi) => poi.id === id)
|
||||
|| findPoiByNavIdNameFallback(pois, id)
|
||||
|| this.staticFallback.getPoiById(id)
|
||||
}
|
||||
|
||||
async searchPois(keyword = '') {
|
||||
|
||||
Reference in New Issue
Block a user