chore: solidify guide P1 snapshot
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
export const NAV_ASSET_BASE_URL = '/static/nav-assets/app_nav_assets_v2_clean_20260609_075339'
|
||||
|
||||
export const NAV_ROUTE_GRAPH_READY = false
|
||||
|
||||
export const NAV_ROUTE_UNAVAILABLE_MESSAGE = '正式路线数据尚未接入,可先查看馆内三维位置'
|
||||
|
||||
export interface NavFloorOption {
|
||||
@@ -55,9 +53,9 @@ const searchableCategories = new Set([
|
||||
'operation_experience'
|
||||
])
|
||||
|
||||
let poiCache: CleanNavPoi[] | null = null
|
||||
|
||||
const normalizeBaseUrl = (baseUrl: string) => baseUrl.replace(/\/+$/, '')
|
||||
const poiCache = new Map<string, CleanNavPoi[]>()
|
||||
const poiRequestCache = new Map<string, Promise<CleanNavPoi[]>>()
|
||||
|
||||
export const navAssetUrl = (relativePath: string, baseUrl = NAV_ASSET_BASE_URL) => (
|
||||
`${normalizeBaseUrl(baseUrl)}/${relativePath.replace(/^\/+/, '')}`
|
||||
@@ -106,15 +104,29 @@ const requestJson = <T>(url: string): Promise<T> => new Promise((resolve, reject
|
||||
})
|
||||
|
||||
export const loadCleanNavPois = async (baseUrl = NAV_ASSET_BASE_URL) => {
|
||||
if (poiCache) return poiCache
|
||||
const cacheKey = normalizeBaseUrl(baseUrl)
|
||||
const cachedPois = poiCache.get(cacheKey)
|
||||
if (cachedPois) return cachedPois
|
||||
|
||||
const data = await requestJson<CleanPoiIndex>(navAssetUrl('data/poi_all.json', baseUrl))
|
||||
if (data.status !== 'pass') {
|
||||
throw new Error('导览 POI 数据状态不是 pass')
|
||||
}
|
||||
const pendingPois = poiRequestCache.get(cacheKey)
|
||||
if (pendingPois) return pendingPois
|
||||
|
||||
poiCache = data.pois.filter((poi) => searchableCategories.has(poi.primaryCategory))
|
||||
return poiCache
|
||||
const request = requestJson<CleanPoiIndex>(navAssetUrl('data/poi_all.json', cacheKey))
|
||||
.then((data) => {
|
||||
if (data.status !== 'pass') {
|
||||
throw new Error('导览 POI 数据状态不是 pass')
|
||||
}
|
||||
|
||||
const pois = data.pois.filter((poi) => searchableCategories.has(poi.primaryCategory))
|
||||
poiCache.set(cacheKey, pois)
|
||||
return pois
|
||||
})
|
||||
.finally(() => {
|
||||
poiRequestCache.delete(cacheKey)
|
||||
})
|
||||
|
||||
poiRequestCache.set(cacheKey, request)
|
||||
return request
|
||||
}
|
||||
|
||||
export const loadCleanNavPoiById = async (id: string, baseUrl = NAV_ASSET_BASE_URL) => {
|
||||
|
||||
Reference in New Issue
Block a user