feat: wire guide data source and POI focus UI
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,10 +2,6 @@
|
||||
|
||||
这些 JSON 是早期演示数据,当前导览模块不再以这里作为数据源。
|
||||
|
||||
当前室内导览、设施搜索、位置预览统一从:
|
||||
当前室内导览、设施搜索、位置预览统一通过 Provider / Adapter / Repository / UseCase 数据边界读取 `static/nav-assets/app_nav_assets_v2_clean_20260611_093623`,页面和展示组件不要直接依赖静态包 JSON 文件。
|
||||
|
||||
`/static/nav-assets/app_nav_assets_v2_clean_20260609_075339/app_nav_manifest.json`
|
||||
|
||||
以及同目录下的 `data/poi_all.json`、`data/poi_by_floor/*.json` 读取。
|
||||
|
||||
如需继续改造历史页面,请优先接入 `src/services/navAssets.ts`,不要新增对本目录 JSON 的业务依赖。
|
||||
如需继续改造历史页面,请优先接入 `GuideRepository`、`MuseumContentRepository`、`ExplainRepository` 或对应 use case,不要新增对本目录 JSON 的业务依赖。
|
||||
|
||||
@@ -206,15 +206,11 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import type {
|
||||
ExplainExhibitViewModel
|
||||
} from '@/view-models/explainViewModels'
|
||||
|
||||
export interface Exhibit {
|
||||
id: string
|
||||
name: string
|
||||
artist?: string
|
||||
hall?: string
|
||||
floor?: string
|
||||
image?: string
|
||||
hasAudio?: boolean
|
||||
export interface Exhibit extends ExplainExhibitViewModel {
|
||||
audioUrl?: string
|
||||
}
|
||||
|
||||
@@ -225,6 +221,16 @@ interface SearchResult {
|
||||
type: 'exhibit' | 'hall' | 'facility'
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
exhibits?: Exhibit[]
|
||||
hotSearches?: string[]
|
||||
initialSearchHistory?: string[]
|
||||
}>(), {
|
||||
exhibits: () => [],
|
||||
hotSearches: () => ['恐龙化石', '银杏', '海洋生物', '霸王龙', '古植物', '矿石标本', '恐龙', '化石'],
|
||||
initialSearchHistory: () => ['霸王龙', '化石', '恐龙']
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
exhibitClick: [exhibit: Exhibit]
|
||||
audioClick: [exhibit: Exhibit]
|
||||
@@ -259,46 +265,31 @@ let touchStartY = 0
|
||||
let touchCurrentY = 0
|
||||
|
||||
// 热门搜索
|
||||
const hotSearches = ['恐龙化石', '银杏', '海洋生物', '霸王龙', '古植物', '矿石标本', '恐龙', '化石']
|
||||
const hotSearches = computed(() => props.hotSearches)
|
||||
|
||||
// 搜索历史
|
||||
const searchHistory = ref<string[]>(['霸王龙', '化石', '恐龙'])
|
||||
const searchHistory = ref<string[]>([...props.initialSearchHistory])
|
||||
|
||||
// 搜索数据
|
||||
const allData: SearchResult[] = [
|
||||
{ id: '1', name: '霸王龙化石骨架', desc: '恐龙厅 · 2F', type: 'exhibit' },
|
||||
{ id: '2', name: '银杏化石', desc: '演化厅 · B1', type: 'exhibit' },
|
||||
{ id: '3', name: '三叶虫化石', desc: '演化厅 · B1', type: 'exhibit' },
|
||||
{ id: '4', name: '腕龙骨骼', desc: '恐龙厅 · 2F', type: 'exhibit' },
|
||||
{ id: '5', name: '猛犸象象牙', desc: '人类厅 · 3F', type: 'exhibit' },
|
||||
{ id: 'h1', name: '恐龙厅', desc: '2F · 25件展品', type: 'hall' },
|
||||
{ id: 'h2', name: '演化厅', desc: 'B1 · 30件展品', type: 'hall' },
|
||||
{ id: 'h3', name: '生物厅', desc: '3F · 18件展品', type: 'hall' },
|
||||
{ id: 'f1', name: '洗手间', desc: '1F', type: 'facility' },
|
||||
{ id: 'f2', name: '咖啡厅', desc: '1F', type: 'facility' },
|
||||
]
|
||||
const allData = computed<SearchResult[]>(() => props.exhibits.map((exhibit) => ({
|
||||
id: exhibit.id,
|
||||
name: exhibit.name,
|
||||
desc: exhibit.hall || exhibit.floor || '展项内容',
|
||||
type: 'exhibit'
|
||||
})))
|
||||
|
||||
// 搜索结果计算
|
||||
const searchResults = computed(() => {
|
||||
if (!searchInputValue.value.trim()) return []
|
||||
const kw = searchInputValue.value.toLowerCase()
|
||||
return allData.filter(item =>
|
||||
item.name.toLowerCase().includes(kw) ||
|
||||
return allData.value.filter(item =>
|
||||
item.name.toLowerCase().includes(kw) ||
|
||||
item.desc.toLowerCase().includes(kw)
|
||||
)
|
||||
})
|
||||
|
||||
// 展品列表
|
||||
const exhibits = ref<Exhibit[]>([
|
||||
{ id: '1', name: '银杏化石', hall: '演化厅 B1', hasAudio: true, audioUrl: '' },
|
||||
{ id: '2', name: '三叶虫化石', hall: '演化厅 B1', hasAudio: true, audioUrl: '' },
|
||||
{ id: '3', name: '腕龙骨骼', hall: '恐龙厅 2F', hasAudio: true, audioUrl: '' },
|
||||
{ id: '4', name: '始祖鸟标本', hall: '演化厅 B1', hasAudio: false, audioUrl: '' },
|
||||
{ id: '5', name: '猛犸象象牙', hall: '人类厅 3F', hasAudio: true, audioUrl: '' },
|
||||
{ id: '6', name: '珊瑚礁标本', hall: '生物厅 3F', hasAudio: false, audioUrl: '' },
|
||||
{ id: '7', name: '剑龙化石', hall: '恐龙厅 2F', hasAudio: true, audioUrl: '' },
|
||||
{ id: '8', name: '鹦鹉螺化石', hall: '演化厅 B1', hasAudio: true, audioUrl: '' }
|
||||
])
|
||||
const exhibits = computed(() => props.exhibits)
|
||||
|
||||
// 过滤展品
|
||||
const filteredExhibits = computed(() => {
|
||||
@@ -306,7 +297,7 @@ const filteredExhibits = computed(() => {
|
||||
return exhibits.value
|
||||
}
|
||||
const keyword = searchKeyword.value.toLowerCase()
|
||||
return exhibits.value.filter(exhibit =>
|
||||
return exhibits.value.filter(exhibit =>
|
||||
exhibit.name.toLowerCase().includes(keyword) ||
|
||||
(exhibit.hall && exhibit.hall.toLowerCase().includes(keyword))
|
||||
)
|
||||
|
||||
@@ -30,16 +30,9 @@ const emit = defineEmits<{
|
||||
change: [floorId: string]
|
||||
}>()
|
||||
|
||||
const currentFloor = ref(props.current || '1F')
|
||||
const currentFloor = ref(props.current || props.floors?.[0]?.id || '')
|
||||
|
||||
const defaultFloors: Floor[] = [
|
||||
{ id: '3F', label: '3F' },
|
||||
{ id: '2F', label: '2F' },
|
||||
{ id: '1F', label: '1F' },
|
||||
{ id: 'B1', label: 'B1' }
|
||||
]
|
||||
|
||||
const floors = props.floors || defaultFloors
|
||||
const floors = props.floors || []
|
||||
|
||||
const handleFloorClick = (floor: Floor) => {
|
||||
if (floor.disabled) return
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { computed, ref, onMounted } from 'vue'
|
||||
|
||||
const isH5 = typeof window !== 'undefined'
|
||||
|
||||
@@ -94,6 +94,19 @@ interface Polygon {
|
||||
zIndex: number
|
||||
}
|
||||
|
||||
interface MapFloor {
|
||||
id: string
|
||||
label: string
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
activeFloor?: string
|
||||
floors?: MapFloor[]
|
||||
}>(), {
|
||||
activeFloor: '1F',
|
||||
floors: () => [] as MapFloor[]
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
markerClick: [markerId: number]
|
||||
floorChange: [floor: string]
|
||||
@@ -111,15 +124,10 @@ const mapCenter = ref<MapCenter>({
|
||||
const mapScale = ref(17)
|
||||
|
||||
// 当前楼层
|
||||
const currentFloor = ref('1F')
|
||||
const currentFloor = ref(props.activeFloor)
|
||||
|
||||
// 楼层列表
|
||||
const floors = [
|
||||
{ id: '3F', label: '3F' },
|
||||
{ id: '2F', label: '2F' },
|
||||
{ id: '1F', label: '1F' },
|
||||
{ id: 'B1', label: 'B1' }
|
||||
]
|
||||
const floors = computed(() => props.floors)
|
||||
|
||||
// 博物馆建筑围栏(多边形)
|
||||
// 深圳自然博物馆实际建筑轮廓坐标
|
||||
|
||||
@@ -50,56 +50,23 @@ import * as THREE from 'three'
|
||||
import { GLTFLoader, type GLTF } from 'three/addons/loaders/GLTFLoader.js'
|
||||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
|
||||
import FloorSwitcher from './FloorSwitcher.vue'
|
||||
import { NAV_ASSET_BASE_URL } from '@/services/navAssets'
|
||||
import type {
|
||||
GuideModelFloorAsset,
|
||||
GuideModelRenderPackage,
|
||||
GuideModelSource,
|
||||
GuideRenderPoi
|
||||
} from '@/domain/guideModel'
|
||||
|
||||
type ViewMode = 'overview' | 'floor'
|
||||
|
||||
interface ManifestFloorModel {
|
||||
floorId: string
|
||||
order: number
|
||||
asset: string
|
||||
}
|
||||
|
||||
interface CleanNavManifest {
|
||||
status: string
|
||||
assets: {
|
||||
overviewModel: {
|
||||
asset: string
|
||||
}
|
||||
floorModels: ManifestFloorModel[]
|
||||
}
|
||||
data: {
|
||||
floorIndex: string
|
||||
}
|
||||
}
|
||||
|
||||
interface FloorIndexItem {
|
||||
floorId: string
|
||||
order: number
|
||||
modelAsset: string
|
||||
poiDataAsset: string
|
||||
poiCount: number
|
||||
}
|
||||
|
||||
interface FloorIndexData {
|
||||
status: string
|
||||
floors: FloorIndexItem[]
|
||||
}
|
||||
type FloorIndexItem = GuideModelFloorAsset
|
||||
|
||||
interface FloorOption {
|
||||
id: string
|
||||
label: string
|
||||
}
|
||||
|
||||
interface CleanPoi {
|
||||
id: string
|
||||
name: string
|
||||
floorId: string
|
||||
primaryCategory: string
|
||||
primaryCategoryZh: string
|
||||
iconType: string
|
||||
positionGltf?: [number, number, number]
|
||||
}
|
||||
type RenderPoi = GuideRenderPoi
|
||||
|
||||
interface TargetPoiFocusRequest {
|
||||
requestId: number | string
|
||||
@@ -119,23 +86,18 @@ interface TargetPoiFocusResult {
|
||||
message?: string
|
||||
}
|
||||
|
||||
interface FloorPoiData {
|
||||
status: string
|
||||
floorId: string
|
||||
pois: CleanPoi[]
|
||||
}
|
||||
|
||||
type ContainerRef = HTMLElement | { $el?: HTMLElement } | null
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
assetBaseUrl?: string
|
||||
modelSource: GuideModelSource
|
||||
initialFloorId?: string
|
||||
initialView?: ViewMode
|
||||
showControls?: boolean
|
||||
showPoi?: boolean
|
||||
targetFocus?: TargetPoiFocusRequest | null
|
||||
}>(), {
|
||||
assetBaseUrl: NAV_ASSET_BASE_URL,
|
||||
assetBaseUrl: '',
|
||||
initialFloorId: 'L1',
|
||||
initialView: 'overview',
|
||||
showControls: true,
|
||||
@@ -145,7 +107,7 @@ const props = withDefaults(defineProps<{
|
||||
|
||||
const emit = defineEmits<{
|
||||
floorChange: [floorId: string]
|
||||
poiClick: [poi: CleanPoi]
|
||||
poiClick: [poi: RenderPoi]
|
||||
targetFocus: [result: TargetPoiFocusResult]
|
||||
}>()
|
||||
|
||||
@@ -156,9 +118,10 @@ const loadingProgress = ref(0)
|
||||
const loadingMessage = ref('正在读取室内导览资源...')
|
||||
const activeView = ref<ViewMode>(props.initialView)
|
||||
const currentFloor = ref(props.initialFloorId)
|
||||
const selectedPOI = ref<CleanPoi | null>(null)
|
||||
const selectedPOI = ref<RenderPoi | null>(null)
|
||||
const activeFocusPoiId = ref('')
|
||||
const floorIndex = ref<FloorIndexItem[]>([])
|
||||
const renderPackage = ref<GuideModelRenderPackage | null>(null)
|
||||
|
||||
const floors = computed<FloorOption[]>(() => (
|
||||
[...floorIndex.value]
|
||||
@@ -170,7 +133,6 @@ const floors = computed<FloorOption[]>(() => (
|
||||
))
|
||||
const shouldRenderPoiMarkers = computed(() => props.showPoi || props.showControls || Boolean(props.targetFocus))
|
||||
|
||||
let manifest: CleanNavManifest | null = null
|
||||
let scene: THREE.Scene | null = null
|
||||
let camera: THREE.PerspectiveCamera | null = null
|
||||
let renderer: THREE.WebGLRenderer | null = null
|
||||
@@ -178,16 +140,13 @@ let controls: OrbitControls | null = null
|
||||
let loader: GLTFLoader | null = null
|
||||
let activeModel: THREE.Object3D | null = null
|
||||
let poiGroup: THREE.Group | null = null
|
||||
let activeFocusLabelSprite: THREE.Sprite | null = null
|
||||
let animationId = 0
|
||||
let resizeObserver: ResizeObserver | null = null
|
||||
let isDisposed = false
|
||||
let pendingTargetFocus: TargetPoiFocusRequest | null = null
|
||||
let targetFocusQueue: Promise<unknown> = Promise.resolve()
|
||||
|
||||
const normalizeBaseUrl = (baseUrl: string) => baseUrl.replace(/\/+$/, '')
|
||||
|
||||
const assetUrl = (relativePath: string) => `${normalizeBaseUrl(props.assetBaseUrl)}/${relativePath.replace(/^\/+/, '')}`
|
||||
|
||||
const getContainerElement = () => {
|
||||
const container = containerRef.value
|
||||
if (!container) return null
|
||||
@@ -202,27 +161,15 @@ const getContainerElement = () => {
|
||||
return element instanceof HTMLElement ? element : null
|
||||
}
|
||||
|
||||
const formatFloorLabel = (floorId: string) => {
|
||||
if (floorId === 'L-2') return 'B2'
|
||||
if (floorId === 'L-1') return 'B1'
|
||||
if (floorId === 'L1.5') return '1.5F'
|
||||
if (floorId.startsWith('L')) return `${floorId.slice(1)}F`
|
||||
return floorId
|
||||
}
|
||||
const formatFloorLabel = (floorId: string) => (
|
||||
floorIndex.value.find((floor) => floor.floorId === floorId)?.label || floorId
|
||||
)
|
||||
|
||||
const setProgress = (progress: number, message: string) => {
|
||||
loadingProgress.value = Math.min(100, Math.max(0, progress))
|
||||
loadingMessage.value = message
|
||||
}
|
||||
|
||||
const fetchJson = async <T,>(url: string): Promise<T> => {
|
||||
const response = await fetch(url)
|
||||
if (!response.ok) {
|
||||
throw new Error(`资源读取失败: ${response.status} ${url}`)
|
||||
}
|
||||
return response.json() as Promise<T>
|
||||
}
|
||||
|
||||
const waitForContainer = async () => {
|
||||
await nextTick()
|
||||
|
||||
@@ -274,7 +221,7 @@ const initThree = async () => {
|
||||
|
||||
loader = new GLTFLoader()
|
||||
poiGroup = new THREE.Group()
|
||||
poiGroup.name = 'CleanPackagePOI'
|
||||
poiGroup.name = 'GuideModelPOI'
|
||||
scene.add(poiGroup)
|
||||
|
||||
const ambientLight = new THREE.AmbientLight(0xffffff, 1.6)
|
||||
@@ -340,6 +287,7 @@ const clearSceneData = () => {
|
||||
}
|
||||
|
||||
activeModel = null
|
||||
disposeFocusLabel()
|
||||
selectedPOI.value = null
|
||||
|
||||
if (poiGroup) {
|
||||
@@ -405,15 +353,16 @@ const fitCameraToObject = (object: THREE.Object3D) => {
|
||||
}
|
||||
|
||||
const loadOverview = async () => {
|
||||
if (!manifest || !scene) return
|
||||
const packageData = renderPackage.value
|
||||
if (!packageData || !scene) return
|
||||
|
||||
activeView.value = 'overview'
|
||||
clearSceneData()
|
||||
setProgress(18, '正在加载全馆三维模型...')
|
||||
|
||||
const gltf = await loadModel(assetUrl(manifest.assets.overviewModel.asset), '正在加载全馆三维模型')
|
||||
const gltf = await loadModel(packageData.overviewModelUrl, '正在加载全馆三维模型')
|
||||
activeModel = gltf.scene
|
||||
activeModel.name = 'CleanOverviewModel'
|
||||
activeModel.name = 'GuideOverviewModel'
|
||||
prepareModel(activeModel)
|
||||
scene.add(activeModel)
|
||||
fitCameraToObject(activeModel)
|
||||
@@ -428,9 +377,9 @@ const loadFloor = async (floorId: string) => {
|
||||
clearSceneData()
|
||||
setProgress(18, `正在加载 ${formatFloorLabel(floor.floorId)} 模型...`)
|
||||
|
||||
const gltf = await loadModel(assetUrl(floor.modelAsset), `正在加载 ${formatFloorLabel(floor.floorId)} 模型`)
|
||||
const gltf = await loadModel(floor.modelUrl, `正在加载 ${formatFloorLabel(floor.floorId)} 模型`)
|
||||
activeModel = gltf.scene
|
||||
activeModel.name = `CleanFloorModel_${floor.floorId}`
|
||||
activeModel.name = `GuideFloorModel_${floor.floorId}`
|
||||
prepareModel(activeModel)
|
||||
scene.add(activeModel)
|
||||
fitCameraToObject(activeModel)
|
||||
@@ -440,7 +389,7 @@ const loadFloor = async (floorId: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const createPoiMaterial = (poi: CleanPoi) => {
|
||||
const createPoiMaterial = (poi: RenderPoi) => {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = 96
|
||||
canvas.height = 96
|
||||
@@ -476,6 +425,69 @@ const createPoiMaterial = (poi: CleanPoi) => {
|
||||
})
|
||||
}
|
||||
|
||||
const createPoiLabelSprite = (poi: RenderPoi, markerSize: number) => {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = 512
|
||||
canvas.height = 144
|
||||
const context = canvas.getContext('2d')
|
||||
const label = poi.name.length > 14 ? `${poi.name.slice(0, 14)}…` : poi.name
|
||||
|
||||
if (context) {
|
||||
context.clearRect(0, 0, canvas.width, canvas.height)
|
||||
context.fillStyle = 'rgba(0, 0, 0, 0.82)'
|
||||
context.beginPath()
|
||||
context.roundRect(36, 18, 440, 82, 30)
|
||||
context.fill()
|
||||
|
||||
context.beginPath()
|
||||
context.moveTo(238, 100)
|
||||
context.lineTo(274, 100)
|
||||
context.lineTo(256, 124)
|
||||
context.closePath()
|
||||
context.fill()
|
||||
|
||||
context.font = '600 38px sans-serif'
|
||||
context.textAlign = 'center'
|
||||
context.textBaseline = 'middle'
|
||||
context.fillStyle = '#ffffff'
|
||||
context.fillText(label, 256, 59, 390)
|
||||
}
|
||||
|
||||
const texture = new THREE.CanvasTexture(canvas)
|
||||
texture.colorSpace = THREE.SRGBColorSpace
|
||||
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
|
||||
map: texture,
|
||||
transparent: true,
|
||||
depthTest: false,
|
||||
depthWrite: false
|
||||
}))
|
||||
sprite.userData.isPoiLabel = true
|
||||
sprite.renderOrder = 30
|
||||
sprite.scale.set(markerSize * 4.8, markerSize * 1.35, 1)
|
||||
|
||||
return sprite
|
||||
}
|
||||
|
||||
const disposeFocusLabel = () => {
|
||||
if (!activeFocusLabelSprite) return
|
||||
|
||||
activeFocusLabelSprite.parent?.remove(activeFocusLabelSprite)
|
||||
disposeObject(activeFocusLabelSprite)
|
||||
activeFocusLabelSprite = null
|
||||
}
|
||||
|
||||
const showFocusPoiLabel = (poi: RenderPoi) => {
|
||||
if (!poiGroup || !poi.positionGltf) return
|
||||
|
||||
disposeFocusLabel()
|
||||
|
||||
const markerSize = getPoiMarkerSize()
|
||||
const [x, y, z] = poi.positionGltf
|
||||
activeFocusLabelSprite = createPoiLabelSprite(poi, markerSize)
|
||||
activeFocusLabelSprite.position.set(x, y + markerSize * 2.35, z)
|
||||
poiGroup.add(activeFocusLabelSprite)
|
||||
}
|
||||
|
||||
const getPoiColor = (category: string) => {
|
||||
const colorMap: Record<string, string> = {
|
||||
touring_poi: '#2f6fed',
|
||||
@@ -509,8 +521,8 @@ const updatePoiMarkerFocus = () => {
|
||||
if (!poiGroup) return
|
||||
|
||||
poiGroup.children.forEach((child) => {
|
||||
if (child instanceof THREE.Sprite) {
|
||||
const poi = child.userData.poi as CleanPoi | undefined
|
||||
if (child instanceof THREE.Sprite && !child.userData.isPoiLabel) {
|
||||
const poi = child.userData.poi as RenderPoi | undefined
|
||||
setPoiSpriteFocusStyle(child, Boolean(poi && poi.id === activeFocusPoiId.value))
|
||||
}
|
||||
})
|
||||
@@ -518,15 +530,15 @@ const updatePoiMarkerFocus = () => {
|
||||
|
||||
const findPoiSprite = (poiId: string) => (
|
||||
poiGroup?.children.find((child): child is THREE.Sprite => (
|
||||
child instanceof THREE.Sprite && (child.userData.poi as CleanPoi | undefined)?.id === poiId
|
||||
child instanceof THREE.Sprite && (child.userData.poi as RenderPoi | undefined)?.id === poiId
|
||||
))
|
||||
)
|
||||
|
||||
const findLoadedPoi = (poiId: string) => (
|
||||
findPoiSprite(poiId)?.userData.poi as CleanPoi | undefined
|
||||
findPoiSprite(poiId)?.userData.poi as RenderPoi | undefined
|
||||
)
|
||||
|
||||
const createPoiFromFocusRequest = (request: TargetPoiFocusRequest): CleanPoi | null => {
|
||||
const createPoiFromFocusRequest = (request: TargetPoiFocusRequest): RenderPoi | null => {
|
||||
if (!request.positionGltf) return null
|
||||
|
||||
return {
|
||||
@@ -561,8 +573,7 @@ const addFocusMarkerFromRequest = (request: TargetPoiFocusRequest) => {
|
||||
const loadFloorPOIs = async (floor: FloorIndexItem) => {
|
||||
if (!poiGroup) return
|
||||
|
||||
const data = await fetchJson<FloorPoiData>(assetUrl(floor.poiDataAsset))
|
||||
const validPois = data.pois.filter((poi) => Array.isArray(poi.positionGltf) && poi.positionGltf.length === 3)
|
||||
const validPois = await props.modelSource.loadFloorPois(floor.floorId)
|
||||
const markerSize = getPoiMarkerSize()
|
||||
|
||||
validPois.forEach((poi) => {
|
||||
@@ -588,8 +599,10 @@ const handlePointerDown = (event: PointerEvent) => {
|
||||
raycaster.setFromCamera(pointer, camera)
|
||||
const hits = raycaster.intersectObjects(poiGroup.children, false)
|
||||
|
||||
if (hits[0]?.object.userData.poi) {
|
||||
selectedPOI.value = hits[0].object.userData.poi as CleanPoi
|
||||
const hit = hits.find((item) => !item.object.userData.isPoiLabel && item.object.userData.poi)
|
||||
|
||||
if (hit?.object.userData.poi) {
|
||||
selectedPOI.value = hit.object.userData.poi as RenderPoi
|
||||
activeFocusPoiId.value = selectedPOI.value.id
|
||||
updatePoiMarkerFocus()
|
||||
emit('poiClick', selectedPOI.value)
|
||||
@@ -614,6 +627,7 @@ const clearTargetFocus = () => {
|
||||
pendingTargetFocus = null
|
||||
activeFocusPoiId.value = ''
|
||||
selectedPOI.value = null
|
||||
disposeFocusLabel()
|
||||
updatePoiMarkerFocus()
|
||||
}
|
||||
|
||||
@@ -623,7 +637,7 @@ const isSceneReadyForTargetFocus = () => (
|
||||
&& !loadError.value
|
||||
)
|
||||
|
||||
const focusCameraOnPoi = (poi: CleanPoi) => {
|
||||
const focusCameraOnPoi = (poi: RenderPoi) => {
|
||||
if (!camera || !controls || !poi.positionGltf) return
|
||||
|
||||
const [x, y, z] = poi.positionGltf
|
||||
@@ -675,6 +689,7 @@ const focusTargetPoi = async (request: TargetPoiFocusRequest) => {
|
||||
|
||||
if (!poi?.positionGltf) {
|
||||
selectedPOI.value = null
|
||||
disposeFocusLabel()
|
||||
updatePoiMarkerFocus()
|
||||
emitTargetFocus(request, 'missing', '目标暂无三维坐标')
|
||||
return false
|
||||
@@ -682,6 +697,7 @@ const focusTargetPoi = async (request: TargetPoiFocusRequest) => {
|
||||
|
||||
selectedPOI.value = poi
|
||||
updatePoiMarkerFocus()
|
||||
showFocusPoiLabel(poi)
|
||||
focusCameraOnPoi(poi)
|
||||
emitTargetFocus(request, 'focused')
|
||||
return true
|
||||
@@ -718,17 +734,13 @@ const queueTargetFocus = (request: TargetPoiFocusRequest | null) => {
|
||||
})
|
||||
}
|
||||
|
||||
const loadCleanPackage = async () => {
|
||||
const loadModelPackage = async () => {
|
||||
setProgress(8, '正在读取室内导览资源...')
|
||||
manifest = await fetchJson<CleanNavManifest>(assetUrl('app_nav_manifest.json'))
|
||||
|
||||
if (manifest.status !== 'pass') {
|
||||
throw new Error('室内导览资源包状态不是 pass')
|
||||
}
|
||||
const packageData = await props.modelSource.loadPackage()
|
||||
renderPackage.value = packageData
|
||||
|
||||
setProgress(14, '正在读取楼层索引...')
|
||||
const floorData = await fetchJson<FloorIndexData>(assetUrl(manifest.data.floorIndex))
|
||||
floorIndex.value = [...floorData.floors].sort((a, b) => a.order - b.order)
|
||||
floorIndex.value = [...packageData.floors].sort((a, b) => a.order - b.order)
|
||||
|
||||
if (!floorIndex.value.some((floor) => floor.floorId === currentFloor.value)) {
|
||||
currentFloor.value = floorIndex.value.find((floor) => floor.floorId === 'L1')?.floorId || floorIndex.value[0]?.floorId || 'L1'
|
||||
@@ -752,13 +764,13 @@ const init3DScene = async () => {
|
||||
setProgress(0, '正在初始化三维场景...')
|
||||
|
||||
await initThree()
|
||||
await loadCleanPackage()
|
||||
await loadModelPackage()
|
||||
|
||||
setProgress(100, '室内三维模型加载完成')
|
||||
isLoading.value = false
|
||||
queueTargetFocus(pendingTargetFocus || props.targetFocus || null)
|
||||
} catch (error) {
|
||||
console.error('室内 3D clean package 加载失败:', error)
|
||||
console.error('室内 3D 模型资源加载失败:', error)
|
||||
loadError.value = true
|
||||
isLoading.value = false
|
||||
setProgress(0, error instanceof Error ? error.message : '请检查模型资源或网络状态后重试')
|
||||
@@ -840,11 +852,12 @@ defineExpose({
|
||||
clearNavigation: () => {
|
||||
activeFocusPoiId.value = ''
|
||||
selectedPOI.value = null
|
||||
disposeFocusLabel()
|
||||
updatePoiMarkerFocus()
|
||||
}
|
||||
})
|
||||
|
||||
watch(() => props.assetBaseUrl, () => {
|
||||
watch(() => props.modelSource, () => {
|
||||
init3DScene()
|
||||
})
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
<template v-if="mapType === 'indoor'">
|
||||
<!-- #ifdef H5 -->
|
||||
<ThreeMap
|
||||
v-if="indoorModelSource"
|
||||
ref="threeMapRef"
|
||||
class="indoor-three-map"
|
||||
:asset-base-url="indoorAssetBaseUrl"
|
||||
:model-source="indoorModelSource"
|
||||
:initial-floor-id="activeFloorId"
|
||||
:initial-view="indoorInitialView"
|
||||
:show-controls="false"
|
||||
@@ -23,7 +25,11 @@
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
<view v-else class="outdoor-map-bg">
|
||||
<TencentMap class="outdoor-map" />
|
||||
<TencentMap
|
||||
class="outdoor-map"
|
||||
:active-floor="activeFloor"
|
||||
:floors="props.floors"
|
||||
/>
|
||||
</view>
|
||||
<view v-if="dimmed" class="dim-layer"></view>
|
||||
</view>
|
||||
@@ -105,7 +111,7 @@
|
||||
|
||||
<view v-if="showFloor" class="floor-switcher" :style="floorSwitcherStyle">
|
||||
<view
|
||||
v-for="floor in floors"
|
||||
v-for="floor in floorLabels"
|
||||
:key="floor"
|
||||
class="floor-item"
|
||||
:class="{ active: activeFloor === floor }"
|
||||
@@ -136,11 +142,14 @@ import TencentMap from '@/components/map/TencentMap.vue'
|
||||
// #ifdef H5
|
||||
import ThreeMap from '@/components/map/ThreeMap.vue'
|
||||
// #endif
|
||||
import {
|
||||
NAV_ASSET_BASE_URL,
|
||||
NAV_FLOOR_OPTIONS,
|
||||
navFloorIdFromLabel
|
||||
} from '@/services/navAssets'
|
||||
import type {
|
||||
GuideModelSource
|
||||
} from '@/domain/guideModel'
|
||||
|
||||
interface GuideFloorOption {
|
||||
id: string
|
||||
label: string
|
||||
}
|
||||
|
||||
interface TargetPoiFocusRequest {
|
||||
requestId: number | string
|
||||
@@ -183,6 +192,9 @@ const props = withDefaults(defineProps<{
|
||||
mapType?: 'indoor' | 'outdoor'
|
||||
outdoorVariant?: 'home' | 'entrance'
|
||||
indoorAssetBaseUrl?: string
|
||||
indoorModelSource?: GuideModelSource
|
||||
floors?: GuideFloorOption[]
|
||||
normalizeFloorId?: (labelOrId: string) => string
|
||||
dimmed?: boolean
|
||||
targetFocusRequest?: TargetPoiFocusRequest | null
|
||||
}>(), {
|
||||
@@ -205,7 +217,10 @@ const props = withDefaults(defineProps<{
|
||||
modeStatusTone: 'solid',
|
||||
mapType: 'indoor',
|
||||
outdoorVariant: 'home',
|
||||
indoorAssetBaseUrl: NAV_ASSET_BASE_URL,
|
||||
indoorAssetBaseUrl: '',
|
||||
indoorModelSource: undefined,
|
||||
floors: () => [] as GuideFloorOption[],
|
||||
normalizeFloorId: (labelOrId: string) => labelOrId,
|
||||
dimmed: false,
|
||||
targetFocusRequest: null
|
||||
})
|
||||
@@ -223,9 +238,11 @@ const threeMapRef = ref<{
|
||||
switchFloor?: (floorId: string) => Promise<void> | void
|
||||
showOverview?: () => Promise<void> | void
|
||||
} | null>(null)
|
||||
const floors = NAV_FLOOR_OPTIONS.map((floor) => floor.label)
|
||||
|
||||
const activeFloorId = computed(() => navFloorIdFromLabel(props.activeFloor))
|
||||
const floorLabels = computed(() => props.floors.map((floor) => floor.label))
|
||||
const indoorModelSource = computed(() => props.indoorModelSource)
|
||||
|
||||
const activeFloorId = computed(() => props.normalizeFloorId(props.activeFloor))
|
||||
|
||||
const searchFieldStyle = computed(() => ({
|
||||
top: props.searchTop
|
||||
@@ -258,7 +275,7 @@ const handleModeChange = (mode: '2d' | '3d') => {
|
||||
}
|
||||
|
||||
const handleFloorChange = (floor: string) => {
|
||||
const floorId = navFloorIdFromLabel(floor)
|
||||
const floorId = props.normalizeFloorId(floor)
|
||||
void threeMapRef.value?.switchFloor?.(floorId)
|
||||
emit('indoorViewChange', 'floor')
|
||||
emit('floorChange', floor)
|
||||
@@ -507,10 +524,11 @@ const handleTargetFocus = (result: TargetPoiFocusResult) => {
|
||||
position: absolute;
|
||||
right: 16px;
|
||||
width: 46px;
|
||||
height: 218px;
|
||||
height: auto;
|
||||
max-height: calc(100vh - 260px);
|
||||
padding: 1px;
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
overflow: visible;
|
||||
background: rgba(255, 255, 255, 0.84);
|
||||
border: 1px solid #dde5df;
|
||||
border-radius: 10px;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<text class="action-text">查看室外地图</text>
|
||||
</view>
|
||||
<view class="action-btn primary" @tap="handleShowTargetLocation">
|
||||
<text class="action-text">查看目标位置</text>
|
||||
<text class="action-text">重新定位目标</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -107,14 +107,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, nextTick, onMounted } from 'vue'
|
||||
import {
|
||||
formatNavFloorLabel,
|
||||
searchCleanNavPois,
|
||||
type CleanNavPoi
|
||||
} from '@/services/navAssets'
|
||||
import { ref, computed, watch, nextTick } from 'vue'
|
||||
|
||||
interface SearchResult {
|
||||
export interface SearchResult {
|
||||
id: string
|
||||
name: string
|
||||
desc: string
|
||||
@@ -126,9 +121,11 @@ const props = withDefaults(defineProps<{
|
||||
placeholder?: string
|
||||
/** 嵌入模式:隐藏背景遮罩和取消按钮,直接嵌入父容器 */
|
||||
embedded?: boolean
|
||||
results?: SearchResult[]
|
||||
}>(), {
|
||||
placeholder: '搜索展品、展厅、设施...',
|
||||
embedded: false
|
||||
embedded: false,
|
||||
results: () => []
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -144,14 +141,7 @@ const hotSearches = ref(['卫生间', '电梯', '服务台', '无障碍', '入
|
||||
|
||||
const searchHistory = ref<string[]>([])
|
||||
|
||||
const allData = ref<SearchResult[]>([])
|
||||
|
||||
const toSearchResult = (poi: CleanNavPoi): SearchResult => ({
|
||||
id: poi.id,
|
||||
name: poi.name,
|
||||
desc: `${formatNavFloorLabel(poi.floorId)} · ${poi.primaryCategoryZh}`,
|
||||
type: poi.primaryCategory === 'touring_poi' ? 'hall' : 'facility'
|
||||
})
|
||||
const allData = computed(() => props.results)
|
||||
|
||||
// 搜索结果计算
|
||||
const allResults = computed(() => {
|
||||
@@ -218,20 +208,6 @@ const getResultIcon = (type: string): string => {
|
||||
return icons[type] || '📍'
|
||||
}
|
||||
|
||||
const loadCleanResults = async () => {
|
||||
try {
|
||||
const pois = await searchCleanNavPois()
|
||||
allData.value = pois.slice(0, 120).map(toSearchResult)
|
||||
} catch (error) {
|
||||
console.error('加载 clean POI 搜索数据失败:', error)
|
||||
allData.value = []
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadCleanResults()
|
||||
})
|
||||
|
||||
// 打开时聚焦输入框
|
||||
watch(() => props.isOpen, async (newVal) => {
|
||||
if (newVal) {
|
||||
|
||||
60
src/data/adapters/navAssetsAdapter.ts
Normal file
60
src/data/adapters/navAssetsAdapter.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import type {
|
||||
MuseumCategory,
|
||||
MuseumPoi
|
||||
} from '@/domain/museum'
|
||||
import type {
|
||||
StaticNavPoiCategoryPayload,
|
||||
StaticNavPoiPayload
|
||||
} from '@/data/providers/staticNavAssetsProvider'
|
||||
|
||||
const floorIdPattern = /^L(-?\d+(?:\.\d+)?)$/
|
||||
|
||||
export const formatNavFloorLabel = (floorId: string) => {
|
||||
const match = floorId.match(floorIdPattern)
|
||||
if (!match) return floorId
|
||||
|
||||
const value = Number(match[1])
|
||||
if (Number.isNaN(value)) return floorId
|
||||
|
||||
return value < 0 ? `B${Math.abs(value)}` : `${value}F`
|
||||
}
|
||||
|
||||
export const navFloorIdFromLabel = (labelOrId: string) => {
|
||||
if (floorIdPattern.test(labelOrId)) return labelOrId
|
||||
|
||||
const basementMatch = labelOrId.match(/^B(\d+(?:\.\d+)?)$/i)
|
||||
if (basementMatch) return `L-${basementMatch[1]}`
|
||||
|
||||
const floorMatch = labelOrId.match(/^(\d+(?:\.\d+)?)F$/i)
|
||||
if (floorMatch) return `L${floorMatch[1]}`
|
||||
|
||||
return labelOrId
|
||||
}
|
||||
|
||||
const toCategory = (category: StaticNavPoiCategoryPayload): MuseumCategory => ({
|
||||
id: category.topCategory,
|
||||
label: category.topCategoryZh,
|
||||
iconType: category.iconType
|
||||
})
|
||||
|
||||
const isPoiAccessible = (poi: StaticNavPoiPayload) => (
|
||||
poi.primaryCategory === 'accessibility_special_service'
|
||||
|| poi.categories?.some((category) => category.topCategory === 'accessibility_special_service') === true
|
||||
)
|
||||
|
||||
export const toMuseumPoi = (poi: StaticNavPoiPayload): MuseumPoi => ({
|
||||
id: poi.id,
|
||||
name: poi.name,
|
||||
floorId: poi.floorId,
|
||||
floorLabel: formatNavFloorLabel(poi.floorId),
|
||||
primaryCategory: {
|
||||
id: poi.primaryCategory,
|
||||
label: poi.primaryCategoryZh,
|
||||
iconType: poi.iconType
|
||||
},
|
||||
categories: (poi.categories || []).map(toCategory),
|
||||
positionGltf: poi.positionGltf,
|
||||
sourceConfidence: poi.sourceConfidence,
|
||||
navigationReadiness: poi.navigationReadiness,
|
||||
accessible: isPoiAccessible(poi)
|
||||
})
|
||||
123
src/data/providers/staticMuseumContentProvider.ts
Normal file
123
src/data/providers/staticMuseumContentProvider.ts
Normal file
@@ -0,0 +1,123 @@
|
||||
import type {
|
||||
MuseumExhibit,
|
||||
MuseumHall
|
||||
} from '@/domain/museum'
|
||||
|
||||
export interface MuseumContentProvider {
|
||||
listExhibits(): Promise<MuseumExhibit[]>
|
||||
listHalls(): Promise<MuseumHall[]>
|
||||
}
|
||||
|
||||
const transitionalHalls: MuseumHall[] = [
|
||||
{
|
||||
id: 'hall-evolution',
|
||||
name: '演化厅',
|
||||
floorId: 'L-1',
|
||||
floorLabel: 'B1',
|
||||
description: '自然演化主题内容。当前为内容仓储过渡数据,待 CMS/API 接入后替换。',
|
||||
image: '/static/hall-placeholder.jpg',
|
||||
exhibitCount: 3,
|
||||
area: '待补充'
|
||||
},
|
||||
{
|
||||
id: 'hall-dinosaur',
|
||||
name: '恐龙厅',
|
||||
floorId: 'L2',
|
||||
floorLabel: '2F',
|
||||
description: '恐龙与古生物主题内容。当前为内容仓储过渡数据,待 CMS/API 接入后替换。',
|
||||
image: '/static/hall-placeholder.jpg',
|
||||
exhibitCount: 2,
|
||||
area: '待补充'
|
||||
},
|
||||
{
|
||||
id: 'hall-biology',
|
||||
name: '生物厅',
|
||||
floorId: 'L3',
|
||||
floorLabel: '3F',
|
||||
description: '生物多样性主题内容。当前为内容仓储过渡数据,待 CMS/API 接入后替换。',
|
||||
image: '/static/hall-placeholder.jpg',
|
||||
exhibitCount: 2,
|
||||
area: '待补充'
|
||||
}
|
||||
]
|
||||
|
||||
const transitionalExhibits: MuseumExhibit[] = [
|
||||
{
|
||||
id: 'exhibit-ginkgo-fossil',
|
||||
name: '银杏化石',
|
||||
hallId: 'hall-evolution',
|
||||
hallName: '演化厅',
|
||||
floorId: 'L-1',
|
||||
floorLabel: 'B1',
|
||||
image: '/static/exhibit-placeholder.jpg',
|
||||
description: '银杏化石内容待由正式内容库补充。当前仅用于讲解业务架构迁移。',
|
||||
tags: ['化石', '古植物']
|
||||
},
|
||||
{
|
||||
id: 'exhibit-trilobite-fossil',
|
||||
name: '三叶虫化石',
|
||||
hallId: 'hall-evolution',
|
||||
hallName: '演化厅',
|
||||
floorId: 'L-1',
|
||||
floorLabel: 'B1',
|
||||
image: '/static/exhibit-placeholder.jpg',
|
||||
description: '三叶虫化石内容待由正式内容库补充。当前仅用于讲解业务架构迁移。',
|
||||
tags: ['化石', '古生物']
|
||||
},
|
||||
{
|
||||
id: 'exhibit-brachiosaurus',
|
||||
name: '腕龙骨骼',
|
||||
hallId: 'hall-dinosaur',
|
||||
hallName: '恐龙厅',
|
||||
floorId: 'L2',
|
||||
floorLabel: '2F',
|
||||
image: '/static/exhibit-placeholder.jpg',
|
||||
description: '腕龙骨骼内容待由正式内容库补充。当前仅用于讲解业务架构迁移。',
|
||||
tags: ['恐龙', '骨骼']
|
||||
},
|
||||
{
|
||||
id: 'exhibit-archaeopteryx',
|
||||
name: '始祖鸟标本',
|
||||
hallId: 'hall-evolution',
|
||||
hallName: '演化厅',
|
||||
floorId: 'L-1',
|
||||
floorLabel: 'B1',
|
||||
image: '/static/exhibit-placeholder.jpg',
|
||||
description: '始祖鸟标本内容待由正式内容库补充。当前仅用于讲解业务架构迁移。',
|
||||
tags: ['演化', '标本']
|
||||
},
|
||||
{
|
||||
id: 'exhibit-mammoth-tusk',
|
||||
name: '猛犸象象牙',
|
||||
hallId: 'hall-biology',
|
||||
hallName: '生物厅',
|
||||
floorId: 'L3',
|
||||
floorLabel: '3F',
|
||||
image: '/static/exhibit-placeholder.jpg',
|
||||
description: '猛犸象象牙内容待由正式内容库补充。当前仅用于讲解业务架构迁移。',
|
||||
tags: ['古生物', '标本']
|
||||
},
|
||||
{
|
||||
id: 'exhibit-coral-reef',
|
||||
name: '珊瑚礁标本',
|
||||
hallId: 'hall-biology',
|
||||
hallName: '生物厅',
|
||||
floorId: 'L3',
|
||||
floorLabel: '3F',
|
||||
image: '/static/exhibit-placeholder.jpg',
|
||||
description: '珊瑚礁标本内容待由正式内容库补充。当前仅用于讲解业务架构迁移。',
|
||||
tags: ['海洋生物', '标本']
|
||||
}
|
||||
]
|
||||
|
||||
export class StaticMuseumContentProvider implements MuseumContentProvider {
|
||||
async listExhibits() {
|
||||
return transitionalExhibits
|
||||
}
|
||||
|
||||
async listHalls() {
|
||||
return transitionalHalls
|
||||
}
|
||||
}
|
||||
|
||||
export const staticMuseumContentProvider = new StaticMuseumContentProvider()
|
||||
214
src/data/providers/staticNavAssetsProvider.ts
Normal file
214
src/data/providers/staticNavAssetsProvider.ts
Normal file
@@ -0,0 +1,214 @@
|
||||
import {
|
||||
NAV_ASSET_BASE_URL
|
||||
} from '@/domain/guideReadiness'
|
||||
|
||||
export interface StaticNavPoiCategoryPayload {
|
||||
topCategory: string
|
||||
topCategoryZh: string
|
||||
subcategory: string
|
||||
iconType: string
|
||||
reason?: string
|
||||
}
|
||||
|
||||
export interface StaticNavPoiPayload {
|
||||
id: string
|
||||
name: string
|
||||
floorId: string
|
||||
primaryCategory: string
|
||||
primaryCategoryZh: string
|
||||
categories?: StaticNavPoiCategoryPayload[]
|
||||
iconType?: string
|
||||
positionGltf?: [number, number, number]
|
||||
navigationReadiness?: string
|
||||
sourceConfidence?: string
|
||||
}
|
||||
|
||||
export interface StaticNavManifestFloorModelPayload {
|
||||
floorId: string
|
||||
order: number
|
||||
asset: string
|
||||
}
|
||||
|
||||
export interface StaticNavManifestPayload {
|
||||
status: string
|
||||
assets: {
|
||||
overviewModel: {
|
||||
asset: string
|
||||
}
|
||||
floorModels: StaticNavManifestFloorModelPayload[]
|
||||
}
|
||||
data: {
|
||||
floorIndex: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface StaticNavFloorIndexItemPayload {
|
||||
floorId: string
|
||||
order: number
|
||||
modelAsset: string
|
||||
poiDataAsset: string
|
||||
poiCount: number
|
||||
}
|
||||
|
||||
export interface StaticNavFloorIndexPayload {
|
||||
status: string
|
||||
floors: StaticNavFloorIndexItemPayload[]
|
||||
}
|
||||
|
||||
interface StaticFloorPoiPayload {
|
||||
status: string
|
||||
floorId: string
|
||||
pois: StaticNavPoiPayload[]
|
||||
}
|
||||
|
||||
interface StaticPoiIndexPayload {
|
||||
status: string
|
||||
pois: StaticNavPoiPayload[]
|
||||
}
|
||||
|
||||
const normalizeBaseUrl = (baseUrl: string) => baseUrl.replace(/\/+$/, '')
|
||||
|
||||
const parseJsonPayload = <T>(payload: unknown): T => {
|
||||
if (typeof payload === 'string') {
|
||||
return JSON.parse(payload) as T
|
||||
}
|
||||
|
||||
return payload as T
|
||||
}
|
||||
|
||||
const requestJson = <T>(url: string): Promise<T> => new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url,
|
||||
method: 'GET',
|
||||
success: (response) => {
|
||||
const statusCode = Number(response.statusCode || 0)
|
||||
if (statusCode < 200 || statusCode >= 300) {
|
||||
reject(new Error(`导览资源读取失败: ${statusCode} ${url}`))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
resolve(parseJsonPayload<T>(response.data))
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
},
|
||||
fail: reject
|
||||
})
|
||||
})
|
||||
|
||||
export interface StaticNavAssetsProvider {
|
||||
readonly baseUrl: string
|
||||
assetUrl(relativePath: string): string
|
||||
loadManifest(): Promise<StaticNavManifestPayload>
|
||||
loadFloorIndex(): Promise<StaticNavFloorIndexPayload>
|
||||
loadPoiIndex(): Promise<StaticNavPoiPayload[]>
|
||||
loadFloorPois(relativePath: string): Promise<StaticNavPoiPayload[]>
|
||||
}
|
||||
|
||||
export const createStaticNavAssetsProvider = (
|
||||
baseUrl = NAV_ASSET_BASE_URL
|
||||
): StaticNavAssetsProvider => {
|
||||
const normalizedBaseUrl = normalizeBaseUrl(baseUrl)
|
||||
let poiCache: StaticNavPoiPayload[] | null = null
|
||||
let poiRequest: Promise<StaticNavPoiPayload[]> | null = null
|
||||
let manifestCache: StaticNavManifestPayload | null = null
|
||||
let manifestRequest: Promise<StaticNavManifestPayload> | null = null
|
||||
let floorIndexCache: StaticNavFloorIndexPayload | null = null
|
||||
let floorIndexRequest: Promise<StaticNavFloorIndexPayload> | null = null
|
||||
const floorPoiCache = new Map<string, StaticNavPoiPayload[]>()
|
||||
const floorPoiRequests = new Map<string, Promise<StaticNavPoiPayload[]>>()
|
||||
|
||||
const provider: StaticNavAssetsProvider = {
|
||||
baseUrl: normalizedBaseUrl,
|
||||
assetUrl(relativePath: string) {
|
||||
return `${normalizedBaseUrl}/${relativePath.replace(/^\/+/, '')}`
|
||||
},
|
||||
async loadManifest() {
|
||||
if (manifestCache) return manifestCache
|
||||
if (manifestRequest) return manifestRequest
|
||||
|
||||
manifestRequest = requestJson<StaticNavManifestPayload>(provider.assetUrl('app_nav_manifest.json'))
|
||||
.then((data) => {
|
||||
if (data.status !== 'pass') {
|
||||
throw new Error('室内导览资源包状态不是 pass')
|
||||
}
|
||||
|
||||
manifestCache = data
|
||||
return manifestCache
|
||||
})
|
||||
.finally(() => {
|
||||
manifestRequest = null
|
||||
})
|
||||
|
||||
return manifestRequest
|
||||
},
|
||||
async loadFloorIndex() {
|
||||
if (floorIndexCache) return floorIndexCache
|
||||
if (floorIndexRequest) return floorIndexRequest
|
||||
|
||||
floorIndexRequest = provider.loadManifest()
|
||||
.then((manifest) => requestJson<StaticNavFloorIndexPayload>(provider.assetUrl(manifest.data.floorIndex)))
|
||||
.then((data) => {
|
||||
if (data.status !== 'pass') {
|
||||
throw new Error('导览楼层索引状态不是 pass')
|
||||
}
|
||||
|
||||
floorIndexCache = data
|
||||
return floorIndexCache
|
||||
})
|
||||
.finally(() => {
|
||||
floorIndexRequest = null
|
||||
})
|
||||
|
||||
return floorIndexRequest
|
||||
},
|
||||
async loadPoiIndex() {
|
||||
if (poiCache) return poiCache
|
||||
if (poiRequest) return poiRequest
|
||||
|
||||
poiRequest = requestJson<StaticPoiIndexPayload>(provider.assetUrl('data/poi_all.json'))
|
||||
.then((data) => {
|
||||
if (data.status !== 'pass') {
|
||||
throw new Error('导览 POI 数据状态不是 pass')
|
||||
}
|
||||
|
||||
poiCache = data.pois
|
||||
return poiCache
|
||||
})
|
||||
.finally(() => {
|
||||
poiRequest = null
|
||||
})
|
||||
|
||||
return poiRequest
|
||||
},
|
||||
async loadFloorPois(relativePath: string) {
|
||||
const cacheKey = relativePath.replace(/^\/+/, '')
|
||||
const cached = floorPoiCache.get(cacheKey)
|
||||
if (cached) return cached
|
||||
|
||||
const pending = floorPoiRequests.get(cacheKey)
|
||||
if (pending) return pending
|
||||
|
||||
const request = requestJson<StaticFloorPoiPayload>(provider.assetUrl(cacheKey))
|
||||
.then((data) => {
|
||||
if (data.status !== 'pass') {
|
||||
throw new Error('导览楼层 POI 数据状态不是 pass')
|
||||
}
|
||||
|
||||
floorPoiCache.set(cacheKey, data.pois)
|
||||
return data.pois
|
||||
})
|
||||
.finally(() => {
|
||||
floorPoiRequests.delete(cacheKey)
|
||||
})
|
||||
|
||||
floorPoiRequests.set(cacheKey, request)
|
||||
return request
|
||||
}
|
||||
}
|
||||
|
||||
return provider
|
||||
}
|
||||
|
||||
export const defaultStaticNavAssetsProvider = createStaticNavAssetsProvider()
|
||||
26
src/domain/guideModel.ts
Normal file
26
src/domain/guideModel.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export interface GuideRenderPoi {
|
||||
id: string
|
||||
name: string
|
||||
floorId: string
|
||||
primaryCategory: string
|
||||
primaryCategoryZh: string
|
||||
iconType: string
|
||||
positionGltf?: [number, number, number]
|
||||
}
|
||||
|
||||
export interface GuideModelFloorAsset {
|
||||
floorId: string
|
||||
label: string
|
||||
order: number
|
||||
modelUrl: string
|
||||
}
|
||||
|
||||
export interface GuideModelRenderPackage {
|
||||
overviewModelUrl: string
|
||||
floors: GuideModelFloorAsset[]
|
||||
}
|
||||
|
||||
export interface GuideModelSource {
|
||||
loadPackage(): Promise<GuideModelRenderPackage>
|
||||
loadFloorPois(floorId: string): Promise<GuideRenderPoi[]>
|
||||
}
|
||||
11
src/domain/guideReadiness.ts
Normal file
11
src/domain/guideReadiness.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export const NAV_ROUTE_GRAPH_READY = false
|
||||
|
||||
export const NAV_ROUTE_UNAVAILABLE_MESSAGE = '正式路线数据尚未接入,可先查看馆内三维位置'
|
||||
|
||||
export const NAV_ROUTE_READINESS = {
|
||||
ready: NAV_ROUTE_GRAPH_READY,
|
||||
message: NAV_ROUTE_UNAVAILABLE_MESSAGE,
|
||||
requiredData: ['route_graph', 'nav_data']
|
||||
} as const
|
||||
|
||||
export const NAV_ASSET_BASE_URL = '/static/nav-assets/app_nav_assets_v2_clean_20260611_093623'
|
||||
123
src/domain/museum.ts
Normal file
123
src/domain/museum.ts
Normal file
@@ -0,0 +1,123 @@
|
||||
export interface MuseumFloor {
|
||||
id: string
|
||||
label: string
|
||||
order: number
|
||||
}
|
||||
|
||||
export interface MuseumCategory {
|
||||
id: string
|
||||
label: string
|
||||
iconType?: string
|
||||
}
|
||||
|
||||
export interface MuseumPoi {
|
||||
id: string
|
||||
name: string
|
||||
floorId: string
|
||||
floorLabel: string
|
||||
primaryCategory: MuseumCategory
|
||||
categories: MuseumCategory[]
|
||||
positionGltf?: [number, number, number]
|
||||
sourceConfidence?: string
|
||||
navigationReadiness?: string
|
||||
accessible: boolean
|
||||
}
|
||||
|
||||
export interface MuseumHall {
|
||||
id: string
|
||||
name: string
|
||||
floorId?: string
|
||||
floorLabel?: string
|
||||
description?: string
|
||||
image?: string
|
||||
exhibitCount?: number
|
||||
area?: string
|
||||
poiId?: string
|
||||
}
|
||||
|
||||
export interface MuseumExhibit {
|
||||
id: string
|
||||
name: string
|
||||
hallId?: string
|
||||
hallName?: string
|
||||
floorId?: string
|
||||
floorLabel?: string
|
||||
image?: string
|
||||
description?: string
|
||||
poiId?: string
|
||||
artist?: string
|
||||
year?: string
|
||||
material?: string
|
||||
size?: string
|
||||
tags?: string[]
|
||||
}
|
||||
|
||||
export interface GuideLocationPreview {
|
||||
poiId: string
|
||||
name: string
|
||||
floorId: string
|
||||
floorLabel: string
|
||||
primaryCategoryZh?: string
|
||||
positionGltf?: [number, number, number]
|
||||
}
|
||||
|
||||
export interface GuideStartLocation {
|
||||
label: string
|
||||
floor?: string
|
||||
source?: string
|
||||
}
|
||||
|
||||
export interface GuidePreviewStep {
|
||||
id: string
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface GuideLocationPreviewPlan {
|
||||
id: string
|
||||
facilityId: string
|
||||
target: string
|
||||
summary: string
|
||||
steps: GuidePreviewStep[]
|
||||
targetLocation: GuideLocationPreview | null
|
||||
startLocation: GuideStartLocation | null
|
||||
}
|
||||
|
||||
export interface GuideRouteReadiness {
|
||||
ready: boolean
|
||||
message: string
|
||||
requiredData: string[]
|
||||
}
|
||||
|
||||
export interface MediaAsset {
|
||||
id: string
|
||||
type: 'audio' | 'image' | 'transcript'
|
||||
url?: string
|
||||
duration?: number
|
||||
language?: string
|
||||
available: boolean
|
||||
unavailableReason?: string
|
||||
}
|
||||
|
||||
export interface ExplainTrack {
|
||||
id: string
|
||||
exhibitId?: string
|
||||
hallId?: string
|
||||
title: string
|
||||
summary?: string
|
||||
mediaId?: string
|
||||
coverImage?: string
|
||||
poiId?: string
|
||||
floorId?: string
|
||||
available: boolean
|
||||
}
|
||||
|
||||
export interface SearchIndexItem {
|
||||
id: string
|
||||
name: string
|
||||
desc: string
|
||||
type: 'exhibit' | 'hall' | 'facility'
|
||||
poiId?: string
|
||||
floorId?: string
|
||||
exhibitId?: string
|
||||
hallId?: string
|
||||
}
|
||||
@@ -50,7 +50,7 @@
|
||||
<view class="action-btn-group">
|
||||
<view class="action-btn" @tap="handleNavigate">
|
||||
<text class="btn-icon">🗺️</text>
|
||||
<text class="btn-text">导航</text>
|
||||
<text class="btn-text">查看位置</text>
|
||||
</view>
|
||||
<view class="action-btn" @tap="handleCollect">
|
||||
<text class="btn-icon">{{ isCollected ? '❤️' : '🤍' }}</text>
|
||||
@@ -70,32 +70,39 @@
|
||||
import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import GuidePageFrame from '@/components/navigation/GuidePageFrame.vue'
|
||||
import {
|
||||
explainUseCase
|
||||
} from '@/usecases/explainUseCase'
|
||||
import {
|
||||
toExplainDetailViewModel,
|
||||
type ExplainDetailViewModel
|
||||
} from '@/view-models/explainViewModels'
|
||||
import {
|
||||
isGuideTopTab,
|
||||
navigateToGuideTopTab,
|
||||
type GuideTopTab
|
||||
} from '@/utils/guideTopTabs'
|
||||
|
||||
const exhibit = ref({
|
||||
id: '1',
|
||||
name: '蒙娜丽莎',
|
||||
artist: '列奥纳多·达·芬奇',
|
||||
year: '1503-1519',
|
||||
material: '木板油画',
|
||||
size: '77cm × 53cm',
|
||||
hall: '1号展厅 1F',
|
||||
const exhibit = ref<ExplainDetailViewModel>({
|
||||
id: '',
|
||||
name: '展项内容',
|
||||
hall: '展厅位置待补充',
|
||||
image: '/static/exhibit-placeholder.jpg',
|
||||
description: '《蒙娜丽莎》是意大利文艺复兴时期画家列奥纳多·达·芬奇创作的油画,现收藏于法国卢浮宫博物馆。该画作主要表现了女性的典雅和恬静的典型形象,塑造了资本主义上升时期一位城市有产阶级的妇女形象。'
|
||||
description: '该展项介绍待正式内容库补充。',
|
||||
hasAudio: false,
|
||||
audioUnavailableReason: '正式讲解音频尚未接入媒体仓储'
|
||||
})
|
||||
|
||||
const isPlaying = ref(false)
|
||||
const isCollected = ref(false)
|
||||
const activeTopTab = ref<GuideTopTab>('guide')
|
||||
|
||||
onLoad((options: any) => {
|
||||
onLoad(async (options: any) => {
|
||||
if (options.id) {
|
||||
// 根据 ID 加载展品数据
|
||||
console.log('加载展品:', options.id)
|
||||
const exhibitData = await explainUseCase.getExhibitById(options.id)
|
||||
if (exhibitData) {
|
||||
exhibit.value = toExplainDetailViewModel(exhibitData)
|
||||
}
|
||||
}
|
||||
|
||||
const tab = Array.isArray(options.tab) ? options.tab[0] : options.tab
|
||||
@@ -104,14 +111,29 @@ onLoad((options: any) => {
|
||||
}
|
||||
})
|
||||
|
||||
const handlePlayAudio = () => {
|
||||
isPlaying.value = !isPlaying.value
|
||||
console.log('播放/暂停音频')
|
||||
const handlePlayAudio = async () => {
|
||||
const selection = exhibit.value.id
|
||||
? await explainUseCase.selectAudioForExhibit(exhibit.value.id)
|
||||
: null
|
||||
|
||||
uni.showToast({
|
||||
title: selection?.unavailableMessage || exhibit.value.audioUnavailableReason || '该展项暂无讲解音频',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
const handleNavigate = () => {
|
||||
console.log('导航到展品位置')
|
||||
uni.navigateBack()
|
||||
if (!exhibit.value.poiId) {
|
||||
uni.showToast({
|
||||
title: '该展项暂无三维位置数据',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
uni.navigateTo({
|
||||
url: `/pages/route/detail?facilityId=${encodeURIComponent(exhibit.value.poiId)}&target=${encodeURIComponent(exhibit.value.name)}&state=preview`
|
||||
})
|
||||
}
|
||||
|
||||
const handleCollect = () => {
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
floor-top="208px"
|
||||
tools-top="450px"
|
||||
:tools="['回正', '2D']"
|
||||
:indoor-model-source="indoorModelSource"
|
||||
:floors="guideFloors"
|
||||
:normalize-floor-id="normalizeGuideFloorId"
|
||||
@search-tap="handleSearchTap"
|
||||
@mode-change="handleModeChange"
|
||||
@floor-change="handleFloorChange"
|
||||
@@ -115,16 +118,19 @@ import { onLoad } from '@dcloudio/uni-app'
|
||||
import GuidePageFrame from '@/components/navigation/GuidePageFrame.vue'
|
||||
import GuideMapShell from '@/components/navigation/GuideMapShell.vue'
|
||||
import {
|
||||
NAV_FLOOR_OPTIONS,
|
||||
NAV_ROUTE_UNAVAILABLE_MESSAGE,
|
||||
formatNavFloorLabel,
|
||||
isPoiAccessible,
|
||||
loadCleanNavPoiById
|
||||
} from '@/services/navAssets'
|
||||
guideUseCase
|
||||
} from '@/usecases/guideUseCase'
|
||||
import {
|
||||
toFacilityDetailViewModel,
|
||||
type FacilityDetailViewModel
|
||||
} from '@/view-models/guideViewModels'
|
||||
import {
|
||||
navigateToGuideTopTab,
|
||||
type GuideTopTab
|
||||
} from '@/utils/guideTopTabs'
|
||||
import type {
|
||||
MuseumFloor
|
||||
} from '@/domain/museum'
|
||||
|
||||
interface ConfirmedStart {
|
||||
label: string
|
||||
@@ -132,19 +138,23 @@ interface ConfirmedStart {
|
||||
source: 'facility-detail'
|
||||
}
|
||||
|
||||
const facility = ref({
|
||||
const indoorModelSource = guideUseCase.getModelSource()
|
||||
const guideFloors = ref<MuseumFloor[]>([])
|
||||
const normalizeGuideFloorId = (labelOrId: string) => guideUseCase.normalizeFloorId(labelOrId)
|
||||
|
||||
const facility = ref<FacilityDetailViewModel>({
|
||||
id: '',
|
||||
name: '目标位置',
|
||||
status: '可预览',
|
||||
location: 'clean 导览数据点位',
|
||||
traffic: NAV_ROUTE_UNAVAILABLE_MESSAGE,
|
||||
traffic: guideUseCase.getRouteReadiness().message,
|
||||
tags: ['三维位置', 'clean 数据']
|
||||
})
|
||||
const isStartPanelOpen = ref(false)
|
||||
const selectedStartFloor = ref('1F')
|
||||
const selectedStartArea = ref('服务台附近')
|
||||
const confirmedStart = ref<ConfirmedStart | null>(null)
|
||||
const startFloors = NAV_FLOOR_OPTIONS.map((floor) => floor.label)
|
||||
const startFloors = computed(() => guideFloors.value.map((floor) => floor.label))
|
||||
const startAreas = ['主入口', '服务台附近', '停车场入口']
|
||||
|
||||
const pendingStartLabel = computed(() => `${selectedStartFloor.value} ${selectedStartArea.value}`)
|
||||
@@ -165,7 +175,23 @@ const syncDraftStartSelection = () => {
|
||||
selectedStartArea.value = resolveConfirmedStartArea()
|
||||
}
|
||||
|
||||
const loadGuideFloors = async () => {
|
||||
try {
|
||||
const floors = await guideUseCase.getFloors()
|
||||
guideFloors.value = floors
|
||||
selectedStartFloor.value = floors.find((floor) => floor.label === selectedStartFloor.value)?.label
|
||||
|| floors.find((floor) => floor.id === 'L1')?.label
|
||||
|| floors[0]?.label
|
||||
|| selectedStartFloor.value
|
||||
} catch (error) {
|
||||
console.error('加载导览楼层失败:', error)
|
||||
guideFloors.value = []
|
||||
}
|
||||
}
|
||||
|
||||
onLoad(async (options: any) => {
|
||||
void loadGuideFloors()
|
||||
|
||||
if (options.id) {
|
||||
facility.value.id = options.id
|
||||
}
|
||||
@@ -177,22 +203,13 @@ onLoad(async (options: any) => {
|
||||
if (!facility.value.id) return
|
||||
|
||||
try {
|
||||
const poi = await loadCleanNavPoiById(facility.value.id)
|
||||
const poi = await guideUseCase.getPoiById(facility.value.id)
|
||||
if (!poi) return
|
||||
|
||||
const floor = formatNavFloorLabel(poi.floorId)
|
||||
facility.value = {
|
||||
id: poi.id,
|
||||
name: poi.name,
|
||||
status: '可预览',
|
||||
location: `${floor} · ${poi.primaryCategoryZh}`,
|
||||
traffic: NAV_ROUTE_UNAVAILABLE_MESSAGE,
|
||||
tags: [
|
||||
floor,
|
||||
poi.primaryCategoryZh,
|
||||
isPoiAccessible(poi) ? '无障碍相关' : '展示点位'
|
||||
]
|
||||
}
|
||||
facility.value = toFacilityDetailViewModel(
|
||||
poi,
|
||||
guideUseCase.getRouteReadiness().message
|
||||
)
|
||||
} catch (error) {
|
||||
console.error('加载 clean 设施详情失败:', error)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<view class="hall-hero">
|
||||
<image class="hero-image" :src="hall.image" mode="aspectFill" />
|
||||
<view class="hall-badge">
|
||||
<text class="badge-text">{{ hall.floor }}</text>
|
||||
<text class="badge-text">{{ hall.floorLabel }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<!-- 底部操作栏 -->
|
||||
<view class="action-bar">
|
||||
<view class="action-btn primary" @tap="handleNavigate">
|
||||
<text class="btn-text">导航到展厅</text>
|
||||
<text class="btn-text">查看展厅位置</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -60,6 +60,15 @@ import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import GuidePageFrame from '@/components/navigation/GuidePageFrame.vue'
|
||||
import ExhibitCard from '@/components/content/ExhibitCard.vue'
|
||||
import {
|
||||
explainUseCase
|
||||
} from '@/usecases/explainUseCase'
|
||||
import {
|
||||
toExplainExhibitViewModel,
|
||||
toHallDetailViewModel,
|
||||
type ExplainExhibitViewModel,
|
||||
type HallDetailViewModel
|
||||
} from '@/view-models/explainViewModels'
|
||||
import {
|
||||
isGuideTopTab,
|
||||
navigateToGuideTopTab,
|
||||
@@ -68,24 +77,26 @@ import {
|
||||
|
||||
const activeTopTab = ref<GuideTopTab>('guide')
|
||||
|
||||
const hall = ref({
|
||||
id: '1',
|
||||
name: '1号展厅',
|
||||
floor: '1F',
|
||||
description: '文艺复兴时期艺术作品展厅,展示了欧洲文艺复兴时期最具代表性的绘画和雕塑作品。',
|
||||
const hall = ref<HallDetailViewModel>({
|
||||
id: '',
|
||||
name: '展厅内容',
|
||||
floorLabel: '楼层待补充',
|
||||
description: '该展厅介绍待正式内容库补充。',
|
||||
image: '/static/hall-placeholder.jpg',
|
||||
exhibitCount: 25,
|
||||
area: '500㎡'
|
||||
exhibitCount: 0,
|
||||
area: '待补充'
|
||||
})
|
||||
|
||||
const exhibits = ref([
|
||||
{ id: '1', name: '蒙娜丽莎', artist: '达芬奇', hasAudio: true },
|
||||
{ id: '2', name: '最后的晚餐', artist: '达芬奇', hasAudio: true }
|
||||
])
|
||||
const exhibits = ref<ExplainExhibitViewModel[]>([])
|
||||
|
||||
onLoad((options: any) => {
|
||||
onLoad(async (options: any) => {
|
||||
if (options.id) {
|
||||
console.log('加载展厅:', options.id)
|
||||
const hallData = await explainUseCase.getHallById(options.id)
|
||||
if (hallData) {
|
||||
hall.value = toHallDetailViewModel(hallData)
|
||||
const hallExhibits = await explainUseCase.listExhibitsByHallId(hallData.id)
|
||||
exhibits.value = hallExhibits.map(toExplainExhibitViewModel)
|
||||
}
|
||||
}
|
||||
|
||||
const tab = Array.isArray(options.tab) ? options.tab[0] : options.tab
|
||||
@@ -101,8 +112,17 @@ const handleExhibitClick = (exhibit: any) => {
|
||||
}
|
||||
|
||||
const handleNavigate = () => {
|
||||
console.log('导航到展厅')
|
||||
uni.navigateBack()
|
||||
if (!hall.value.poiId) {
|
||||
uni.showToast({
|
||||
title: '该展厅暂无三维位置数据',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
uni.navigateTo({
|
||||
url: `/pages/route/detail?facilityId=${encodeURIComponent(hall.value.poiId)}&target=${encodeURIComponent(hall.value.name)}&state=preview`
|
||||
})
|
||||
}
|
||||
|
||||
const handleTopTabChange = (tab: GuideTopTab) => {
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
:map-type="guideMapType"
|
||||
:outdoor-variant="guideOutdoorVariant"
|
||||
:indoor-asset-base-url="indoorNavAssetBaseUrl"
|
||||
:indoor-model-source="indoorModelSource"
|
||||
:floors="guideFloors"
|
||||
:normalize-floor-id="normalizeGuideFloorId"
|
||||
indoor-initial-view="overview"
|
||||
:indoor-view="indoorView"
|
||||
:active-floor="activeGuideFloor"
|
||||
@@ -80,6 +83,7 @@
|
||||
|
||||
<view v-else-if="currentTab === 'explain'" class="explain-page">
|
||||
<ExplainList
|
||||
:exhibits="explainExhibits"
|
||||
@exhibit-click="handleExplainExhibitClick"
|
||||
@featured-click="handleExplainFeaturedClick"
|
||||
@audio-click="handleAudioClick"
|
||||
@@ -109,7 +113,7 @@ import { computed, ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import GuidePageFrame from '@/components/navigation/GuidePageFrame.vue'
|
||||
import GuideMapShell from '@/components/navigation/GuideMapShell.vue'
|
||||
import ExplainList from '@/components/explain/ExplainList.vue'
|
||||
import ExplainList, { type Exhibit } from '@/components/explain/ExplainList.vue'
|
||||
import FloatingAudioButton from '@/components/audio/FloatingAudioButton.vue'
|
||||
import AudioPlayer, { type AudioItem } from '@/components/audio/AudioPlayer.vue'
|
||||
import {
|
||||
@@ -117,9 +121,20 @@ import {
|
||||
type GuideTopTab
|
||||
} from '@/utils/guideTopTabs'
|
||||
import {
|
||||
NAV_ASSET_BASE_URL,
|
||||
NAV_ROUTE_UNAVAILABLE_MESSAGE
|
||||
} from '@/services/navAssets'
|
||||
} from '@/domain/guideReadiness'
|
||||
import {
|
||||
guideUseCase
|
||||
} from '@/usecases/guideUseCase'
|
||||
import {
|
||||
explainUseCase
|
||||
} from '@/usecases/explainUseCase'
|
||||
import {
|
||||
toExplainExhibitViewModel
|
||||
} from '@/view-models/explainViewModels'
|
||||
import type {
|
||||
MuseumFloor
|
||||
} from '@/domain/museum'
|
||||
|
||||
// 3D 模式状态
|
||||
const is3DMode = ref(false)
|
||||
@@ -135,7 +150,10 @@ const showMarkerDetail = ref(false)
|
||||
const showAreaSelector = ref(false)
|
||||
const selectedAreaId = ref('service')
|
||||
|
||||
const indoorNavAssetBaseUrl = NAV_ASSET_BASE_URL
|
||||
const indoorNavAssetBaseUrl = guideUseCase.getAssetBaseUrl()
|
||||
const indoorModelSource = guideUseCase.getModelSource()
|
||||
const guideFloors = ref<MuseumFloor[]>([])
|
||||
const normalizeGuideFloorId = (labelOrId: string) => guideUseCase.normalizeFloorId(labelOrId)
|
||||
|
||||
const shortcutItems = [
|
||||
{ id: 'toilet', name: '卫生间', abbr: '卫' },
|
||||
@@ -149,6 +167,7 @@ const shortcutItems = [
|
||||
const showAudioPlayer = ref(false)
|
||||
const isAudioPlaying = ref(false)
|
||||
const currentAudio = ref<AudioItem | null>(null)
|
||||
const explainExhibits = ref<Exhibit[]>([])
|
||||
|
||||
// 选中的标记详情
|
||||
interface MarkerDetail {
|
||||
@@ -188,8 +207,35 @@ onLoad((options: any = {}) => {
|
||||
if (isGuideTopTab(tab)) {
|
||||
currentTab.value = tab
|
||||
}
|
||||
|
||||
void loadGuideFloors()
|
||||
void loadExplainExhibits()
|
||||
})
|
||||
|
||||
const loadGuideFloors = async () => {
|
||||
try {
|
||||
const floors = await guideUseCase.getFloors()
|
||||
guideFloors.value = floors
|
||||
activeGuideFloor.value = floors.find((floor) => floor.label === activeGuideFloor.value)?.label
|
||||
|| floors.find((floor) => floor.id === 'L1')?.label
|
||||
|| floors[0]?.label
|
||||
|| activeGuideFloor.value
|
||||
} catch (error) {
|
||||
console.error('加载导览楼层失败:', error)
|
||||
guideFloors.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const loadExplainExhibits = async () => {
|
||||
try {
|
||||
const exhibits = await explainUseCase.listExhibits()
|
||||
explainExhibits.value = exhibits.map(toExplainExhibitViewModel)
|
||||
} catch (error) {
|
||||
console.error('加载讲解内容失败:', error)
|
||||
explainExhibits.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索处理
|
||||
const handleSearchFocus = () => {
|
||||
searchBarFocused.value = true
|
||||
@@ -391,13 +437,23 @@ const guideSearchText = computed(() => {
|
||||
})
|
||||
|
||||
// 音频相关处理
|
||||
const handleAudioClick = (exhibit: any) => {
|
||||
console.log('点击音频播放:', exhibit)
|
||||
const handleAudioClick = async (exhibit: Exhibit) => {
|
||||
const selection = await explainUseCase.selectAudioForExhibit(exhibit.id)
|
||||
|
||||
if (!selection?.playable || !selection.media?.url) {
|
||||
uni.showToast({
|
||||
title: selection?.unavailableMessage || exhibit.audioUnavailableReason || '该展项暂无讲解音频',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
currentAudio.value = {
|
||||
id: exhibit.id,
|
||||
name: exhibit.name,
|
||||
audioUrl: exhibit.audioUrl || 'https://example.com/audio.mp3',
|
||||
image: exhibit.image
|
||||
id: selection.media.id,
|
||||
name: selection.track?.title || selection.exhibit.name,
|
||||
audioUrl: selection.media.url,
|
||||
image: selection.exhibit.image,
|
||||
duration: selection.media.duration
|
||||
}
|
||||
showAudioPlayer.value = true
|
||||
}
|
||||
@@ -431,30 +487,14 @@ const handleAudioEnded = (audio: AudioItem) => {
|
||||
}
|
||||
|
||||
// 讲解页面处理
|
||||
const handleExplainExhibitClick = (exhibit: any) => {
|
||||
console.log('点击讲解展品:', exhibit)
|
||||
const handleExplainExhibitClick = (exhibit: Exhibit) => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/exhibit/detail?id=${exhibit.id}&tab=explain`
|
||||
})
|
||||
}
|
||||
|
||||
const handleExplainFeaturedClick = (exhibit: any) => {
|
||||
console.log('点击推荐讲解:', exhibit)
|
||||
// 播放音频讲解
|
||||
if (exhibit.hasAudio) {
|
||||
currentAudio.value = {
|
||||
id: exhibit.id,
|
||||
name: exhibit.name,
|
||||
audioUrl: exhibit.audioUrl || 'https://example.com/audio.mp3',
|
||||
image: exhibit.image
|
||||
}
|
||||
showAudioPlayer.value = true
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '该展品暂无讲解音频',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
const handleExplainFeaturedClick = async (exhibit: Exhibit) => {
|
||||
await handleAudioClick(exhibit)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
>
|
||||
<GuideMapShell
|
||||
v-bind="shellConfig"
|
||||
:indoor-model-source="indoorModelSource"
|
||||
:floors="guideFloors"
|
||||
:normalize-floor-id="normalizeGuideFloorId"
|
||||
:target-focus-request="targetFocusRequest"
|
||||
@search-tap="handleSearchTap"
|
||||
@mode-change="handleModeChange"
|
||||
@@ -125,12 +128,18 @@ import GuidePageFrame from '@/components/navigation/GuidePageFrame.vue'
|
||||
import GuideMapShell from '@/components/navigation/GuideMapShell.vue'
|
||||
import LocationPreview from '@/components/navigation/LocationPreview.vue'
|
||||
import {
|
||||
NAV_FLOOR_OPTIONS,
|
||||
NAV_ROUTE_UNAVAILABLE_MESSAGE,
|
||||
formatNavFloorLabel,
|
||||
loadCleanNavPoiById,
|
||||
type CleanNavPoi
|
||||
} from '@/services/navAssets'
|
||||
guideUseCase
|
||||
} from '@/usecases/guideUseCase'
|
||||
import {
|
||||
initialLocationPreviewPlan,
|
||||
toTargetFocusRequestViewModel
|
||||
} from '@/view-models/guideViewModels'
|
||||
import type {
|
||||
GuideLocationPreview,
|
||||
GuideLocationPreviewPlan,
|
||||
GuideStartLocation,
|
||||
MuseumFloor
|
||||
} from '@/domain/museum'
|
||||
import {
|
||||
navigateToGuideTopTab,
|
||||
type GuideTopTab
|
||||
@@ -138,28 +147,11 @@ import {
|
||||
|
||||
type RouteViewState = 'preview' | 'location-error' | 'outdoor-preview'
|
||||
type GuideMode = '2d' | '3d'
|
||||
interface RouteStep {
|
||||
id: string
|
||||
text: string
|
||||
}
|
||||
|
||||
interface RouteTargetLocation {
|
||||
poiId: string
|
||||
name: string
|
||||
floorId: string
|
||||
floorLabel?: string
|
||||
primaryCategoryZh?: string
|
||||
positionGltf?: [number, number, number]
|
||||
}
|
||||
|
||||
interface RouteStartLocation {
|
||||
label: string
|
||||
floor?: string
|
||||
source?: string
|
||||
}
|
||||
type RouteTargetLocation = GuideLocationPreview
|
||||
type RouteStartLocation = GuideStartLocation
|
||||
|
||||
interface TargetPoiFocusRequest extends RouteTargetLocation {
|
||||
requestId: number
|
||||
requestId: number | string
|
||||
}
|
||||
|
||||
interface TargetPoiFocusResult {
|
||||
@@ -170,104 +162,44 @@ interface TargetPoiFocusResult {
|
||||
message?: string
|
||||
}
|
||||
|
||||
interface RoutePlan {
|
||||
id: string
|
||||
facilityId: string
|
||||
target: string
|
||||
summary: string
|
||||
steps: RouteStep[]
|
||||
targetLocation: RouteTargetLocation | null
|
||||
startLocation: RouteStartLocation | null
|
||||
}
|
||||
type RoutePlan = GuideLocationPreviewPlan
|
||||
|
||||
const routeDeepLinkStates: RouteViewState[] = ['preview', 'outdoor-preview']
|
||||
const indoorModelSource = guideUseCase.getModelSource()
|
||||
const guideFloors = ref<MuseumFloor[]>([])
|
||||
const normalizeGuideFloorId = (labelOrId: string) => guideUseCase.normalizeFloorId(labelOrId)
|
||||
|
||||
const startSourceLabels: Record<string, string> = {
|
||||
'facility-detail': '设施详情选择',
|
||||
manual: '手动选择'
|
||||
}
|
||||
|
||||
const formatStartSourceLabel = (source?: string) => (
|
||||
source ? startSourceLabels[source] || source : ''
|
||||
)
|
||||
|
||||
const formatStartStepText = (startLocation: RouteStartLocation) => {
|
||||
const sourceLabel = formatStartSourceLabel(startLocation.source)
|
||||
const floorSuffix = startLocation.floor && !startLocation.label.includes(startLocation.floor)
|
||||
? ` · ${startLocation.floor}`
|
||||
: ''
|
||||
const sourceSuffix = sourceLabel ? `(${sourceLabel})` : ''
|
||||
|
||||
return `起点:${startLocation.label}${floorSuffix}${sourceSuffix}`
|
||||
}
|
||||
|
||||
const createPreviewSteps = (
|
||||
poi: CleanNavPoi | null,
|
||||
startLocation: RouteStartLocation | null
|
||||
): RouteStep[] => {
|
||||
if (startLocation) {
|
||||
return [
|
||||
{
|
||||
id: 'start',
|
||||
text: formatStartStepText(startLocation)
|
||||
},
|
||||
{
|
||||
id: 'target',
|
||||
text: poi
|
||||
? `目标:${formatNavFloorLabel(poi.floorId)} · ${poi.primaryCategoryZh} · 位置预览`
|
||||
: '目标来自 clean 导览数据,暂仅支持位置预览'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
id: 'floor',
|
||||
text: poi ? `目标位于 ${formatNavFloorLabel(poi.floorId)} · ${poi.primaryCategoryZh}` : '目标来自 clean 导览数据'
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
text: NAV_ROUTE_UNAVAILABLE_MESSAGE
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const createRoutePlan = (
|
||||
facilityId: string,
|
||||
target: string,
|
||||
poi: CleanNavPoi | null = null,
|
||||
startLocation: RouteStartLocation | null = null
|
||||
): RoutePlan => ({
|
||||
id: `route-${facilityId || 'custom'}`,
|
||||
facilityId,
|
||||
target,
|
||||
summary: poi
|
||||
? `${formatNavFloorLabel(poi.floorId)} · ${poi.primaryCategoryZh} · 位置预览`
|
||||
: '位置预览 · 尚未接入正式路线图',
|
||||
steps: createPreviewSteps(poi, startLocation),
|
||||
targetLocation: poi ? {
|
||||
poiId: poi.id,
|
||||
name: poi.name,
|
||||
floorId: poi.floorId,
|
||||
floorLabel: formatNavFloorLabel(poi.floorId),
|
||||
primaryCategoryZh: poi.primaryCategoryZh,
|
||||
positionGltf: poi.positionGltf
|
||||
} : null,
|
||||
startLocation
|
||||
})
|
||||
|
||||
const route = ref<RoutePlan>(createRoutePlan('', '目标地点'))
|
||||
const route = ref<RoutePlan>(initialLocationPreviewPlan())
|
||||
const hasRouteTarget = ref(false)
|
||||
const routeViewState = ref<RouteViewState>('preview')
|
||||
const activeFloor = ref('1F')
|
||||
const targetFocusRequest = ref<TargetPoiFocusRequest | null>(null)
|
||||
const targetFocusRequestId = ref(0)
|
||||
const manualFloors = NAV_FLOOR_OPTIONS.map((floor) => floor.label)
|
||||
const manualFloors = computed(() => guideFloors.value.map((floor) => floor.label))
|
||||
const guideFloorLabel = (floorId: string) => (
|
||||
guideFloors.value.find((floor) => floor.id === floorId)?.label || floorId
|
||||
)
|
||||
const defaultGuideFloorLabel = () => (
|
||||
guideFloors.value.find((floor) => floor.id === 'L1')?.label
|
||||
|| guideFloors.value[0]?.label
|
||||
|| '1F'
|
||||
)
|
||||
const loadGuideFloors = async () => {
|
||||
if (guideFloors.value.length) return guideFloors.value
|
||||
|
||||
try {
|
||||
guideFloors.value = await guideUseCase.getFloors()
|
||||
} catch (error) {
|
||||
console.error('加载导览楼层失败:', error)
|
||||
guideFloors.value = []
|
||||
}
|
||||
|
||||
return guideFloors.value
|
||||
}
|
||||
const manualAreas = ['主入口', '服务台附近', '停车场入口']
|
||||
const isManualLocationPanelOpen = ref(false)
|
||||
const selectedManualFloor = ref('1F')
|
||||
const selectedManualArea = ref('服务台附近')
|
||||
|
||||
const normalizeRouteOption = (value: unknown) => {
|
||||
if (Array.isArray(value)) {
|
||||
return value[0]
|
||||
@@ -380,7 +312,36 @@ const createStartLocationFromOptions = (options: Record<string, unknown>) => {
|
||||
}
|
||||
}
|
||||
|
||||
const requestTargetFocus = (target: Partial<RouteTargetLocation> | null, fallbackName = route.value.target) => {
|
||||
if (!target?.poiId || !target.floorId) {
|
||||
targetFocusRequest.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
const floorLabel = target.floorLabel || guideFloorLabel(target.floorId)
|
||||
const focusTarget: RouteTargetLocation = {
|
||||
poiId: target.poiId,
|
||||
name: target.name || fallbackName,
|
||||
floorId: target.floorId,
|
||||
floorLabel,
|
||||
primaryCategoryZh: target.primaryCategoryZh,
|
||||
positionGltf: target.positionGltf
|
||||
}
|
||||
|
||||
activeFloor.value = floorLabel
|
||||
routeViewState.value = 'preview'
|
||||
targetFocusRequestId.value += 1
|
||||
targetFocusRequest.value = toTargetFocusRequestViewModel(
|
||||
focusTarget,
|
||||
targetFocusRequestId.value
|
||||
)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
const applyRouteOptions = async (options: Record<string, unknown> = {}) => {
|
||||
await loadGuideFloors()
|
||||
|
||||
const facilityId = normalizeStringOption(options.facilityId)
|
||||
const target = normalizeStringOption(options.target)
|
||||
const state = normalizeRouteOption(options.state)
|
||||
@@ -388,39 +349,42 @@ const applyRouteOptions = async (options: Record<string, unknown> = {}) => {
|
||||
|
||||
if (!facilityId && !target) {
|
||||
hasRouteTarget.value = false
|
||||
route.value = createRoutePlan('', '目标地点')
|
||||
route.value = initialLocationPreviewPlan()
|
||||
routeViewState.value = 'preview'
|
||||
activeFloor.value = '1F'
|
||||
activeFloor.value = defaultGuideFloorLabel()
|
||||
targetFocusRequest.value = null
|
||||
isManualLocationPanelOpen.value = false
|
||||
return false
|
||||
}
|
||||
|
||||
const matchedPoi = facilityId ? await loadCleanNavPoiById(facilityId) : null
|
||||
const matchedPoi = facilityId ? await guideUseCase.getPoiById(facilityId) : null
|
||||
|
||||
if (!matchedPoi) {
|
||||
hasRouteTarget.value = false
|
||||
route.value = createRoutePlan('', target || '目标地点')
|
||||
route.value = await guideUseCase.createLocationPreviewPlan('', target || '目标地点', startLocation)
|
||||
routeViewState.value = 'preview'
|
||||
activeFloor.value = startLocation?.floor || '1F'
|
||||
activeFloor.value = startLocation?.floor || defaultGuideFloorLabel()
|
||||
targetFocusRequest.value = null
|
||||
isManualLocationPanelOpen.value = false
|
||||
return false
|
||||
}
|
||||
|
||||
route.value = createRoutePlan(
|
||||
route.value = await guideUseCase.createLocationPreviewPlan(
|
||||
facilityId,
|
||||
target || matchedPoi.name,
|
||||
matchedPoi,
|
||||
startLocation
|
||||
)
|
||||
|
||||
hasRouteTarget.value = true
|
||||
routeViewState.value = isRouteViewState(state) ? state : 'preview'
|
||||
activeFloor.value = matchedPoi ? formatNavFloorLabel(matchedPoi.floorId) : startLocation?.floor || '1F'
|
||||
targetFocusRequest.value = null
|
||||
isManualLocationPanelOpen.value = false
|
||||
|
||||
if (routeViewState.value === 'preview') {
|
||||
requestTargetFocus(route.value.targetLocation, matchedPoi.name)
|
||||
} else {
|
||||
activeFloor.value = matchedPoi.floorLabel || guideFloorLabel(matchedPoi.floorId)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -479,23 +443,14 @@ const handleViewOutdoorMap = () => {
|
||||
routeViewState.value = 'outdoor-preview'
|
||||
}
|
||||
|
||||
const handleShowTargetLocation = (target: RouteTargetLocation | null) => {
|
||||
const targetLocation = target || route.value.targetLocation
|
||||
const handleShowTargetLocation = (target: Partial<RouteTargetLocation> | null) => {
|
||||
const focused = requestTargetFocus(target || route.value.targetLocation)
|
||||
|
||||
if (!targetLocation?.poiId || !targetLocation.floorId) {
|
||||
if (!focused) {
|
||||
uni.showToast({
|
||||
title: '目标暂无三维位置数据',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
routeViewState.value = 'preview'
|
||||
activeFloor.value = targetLocation.floorLabel || formatNavFloorLabel(targetLocation.floorId)
|
||||
targetFocusRequestId.value += 1
|
||||
targetFocusRequest.value = {
|
||||
...targetLocation,
|
||||
requestId: targetFocusRequestId.value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,6 +466,7 @@ const handleTargetFocus = (result: TargetPoiFocusResult) => {
|
||||
const handleReturnToPreview = () => {
|
||||
isManualLocationPanelOpen.value = false
|
||||
routeViewState.value = 'preview'
|
||||
requestTargetFocus(route.value.targetLocation)
|
||||
}
|
||||
|
||||
const handleRelocate = () => {
|
||||
@@ -540,39 +496,24 @@ const createManualStartLocation = (): RouteStartLocation => ({
|
||||
source: 'manual'
|
||||
})
|
||||
|
||||
const createCurrentTargetStep = (): RouteStep => {
|
||||
const targetLocation = route.value.targetLocation
|
||||
|
||||
return {
|
||||
id: 'target',
|
||||
text: targetLocation
|
||||
? `目标:${targetLocation.floorLabel || formatNavFloorLabel(targetLocation.floorId)} · ${targetLocation.primaryCategoryZh || route.value.target} · 位置预览`
|
||||
: '目标来自 clean 导览数据,暂仅支持位置预览'
|
||||
}
|
||||
}
|
||||
|
||||
const handleConfirmLocation = () => {
|
||||
const handleConfirmLocation = async () => {
|
||||
const startLocation = createManualStartLocation()
|
||||
|
||||
route.value = {
|
||||
...route.value,
|
||||
startLocation,
|
||||
steps: [
|
||||
{
|
||||
id: 'start',
|
||||
text: formatStartStepText(startLocation)
|
||||
},
|
||||
createCurrentTargetStep()
|
||||
]
|
||||
}
|
||||
route.value = await guideUseCase.createLocationPreviewPlan(
|
||||
route.value.facilityId,
|
||||
route.value.target,
|
||||
startLocation
|
||||
)
|
||||
activeFloor.value = startLocation.floor || activeFloor.value
|
||||
isManualLocationPanelOpen.value = false
|
||||
routeViewState.value = 'preview'
|
||||
requestTargetFocus(route.value.targetLocation)
|
||||
}
|
||||
|
||||
const handleModeChange = (mode: GuideMode) => {
|
||||
if (routeViewState.value === 'outdoor-preview' && mode === '3d') {
|
||||
routeViewState.value = 'preview'
|
||||
requestTargetFocus(route.value.targetLocation)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -596,7 +537,7 @@ const handleToolClick = (tool: string) => {
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: tool === '回正' ? '已回到三维总览' : NAV_ROUTE_UNAVAILABLE_MESSAGE,
|
||||
title: tool === '回正' ? '已回到三维总览' : guideUseCase.getRouteReadiness().message,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
search-top="60px"
|
||||
mode-top="104px"
|
||||
floor-top="208px"
|
||||
:indoor-model-source="indoorModelSource"
|
||||
:floors="guideFloors"
|
||||
:normalize-floor-id="normalizeGuideFloorId"
|
||||
@search-tap="handleSearchTap"
|
||||
@mode-change="handleModeChange"
|
||||
@floor-change="handleFloorChange"
|
||||
@@ -100,31 +103,31 @@ import { onLoad } from '@dcloudio/uni-app'
|
||||
import GuidePageFrame from '@/components/navigation/GuidePageFrame.vue'
|
||||
import GuideMapShell from '@/components/navigation/GuideMapShell.vue'
|
||||
import {
|
||||
formatNavFloorLabel,
|
||||
isPoiAccessible,
|
||||
searchCleanNavPois,
|
||||
type CleanNavPoi
|
||||
} from '@/services/navAssets'
|
||||
guideUseCase
|
||||
} from '@/usecases/guideUseCase'
|
||||
import {
|
||||
toFacilityResultViewModel,
|
||||
type FacilityResultViewModel
|
||||
} from '@/view-models/guideViewModels'
|
||||
import {
|
||||
navigateToGuideTopTab,
|
||||
type GuideTopTab
|
||||
} from '@/utils/guideTopTabs'
|
||||
import type {
|
||||
MuseumFloor
|
||||
} from '@/domain/museum'
|
||||
|
||||
interface FilterItem {
|
||||
id: 'all' | 'accessible' | 'floor'
|
||||
label: string
|
||||
}
|
||||
|
||||
interface FacilityResult {
|
||||
id: string
|
||||
name: string
|
||||
floor: string
|
||||
meta: string
|
||||
accessible: boolean
|
||||
action: '查看'
|
||||
}
|
||||
interface FacilityResult extends FacilityResultViewModel {}
|
||||
|
||||
const searchKeyword = ref('卫生间')
|
||||
const indoorModelSource = guideUseCase.getModelSource()
|
||||
const guideFloors = ref<MuseumFloor[]>([])
|
||||
const normalizeGuideFloorId = (labelOrId: string) => guideUseCase.normalizeFloorId(labelOrId)
|
||||
const searchDraftKeyword = ref('')
|
||||
const currentFilter = ref<FilterItem['id']>('all')
|
||||
const isLoading = ref(false)
|
||||
@@ -140,18 +143,6 @@ const filters: FilterItem[] = [
|
||||
|
||||
const facilities = ref<FacilityResult[]>([])
|
||||
|
||||
const toFacilityResult = (poi: CleanNavPoi): FacilityResult => {
|
||||
const floor = formatNavFloorLabel(poi.floorId)
|
||||
return {
|
||||
id: poi.id,
|
||||
name: poi.name,
|
||||
floor,
|
||||
meta: `${floor}|${poi.primaryCategoryZh}|${poi.navigationReadiness || '展示点位'}`,
|
||||
accessible: isPoiAccessible(poi),
|
||||
action: '查看'
|
||||
}
|
||||
}
|
||||
|
||||
const visibleFacilities = computed(() => {
|
||||
if (currentFilter.value === 'accessible') {
|
||||
return facilities.value.filter((item) => item.accessible)
|
||||
@@ -170,10 +161,10 @@ const resultTitle = computed(() => {
|
||||
const loadFacilityResults = async () => {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const pois = await searchCleanNavPois(searchKeyword.value)
|
||||
const pois = await guideUseCase.searchPois(searchKeyword.value)
|
||||
facilities.value = pois
|
||||
.filter((poi) => poi.primaryCategory !== 'touring_poi')
|
||||
.map(toFacilityResult)
|
||||
.filter((poi) => poi.primaryCategory.id !== 'touring_poi')
|
||||
.map(toFacilityResultViewModel)
|
||||
} catch (error) {
|
||||
console.error('加载 clean 导览搜索结果失败:', error)
|
||||
facilities.value = []
|
||||
@@ -186,11 +177,21 @@ const loadFacilityResults = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadGuideFloors = async () => {
|
||||
try {
|
||||
guideFloors.value = await guideUseCase.getFloors()
|
||||
} catch (error) {
|
||||
console.error('加载导览楼层失败:', error)
|
||||
guideFloors.value = []
|
||||
}
|
||||
}
|
||||
|
||||
onLoad((options: any) => {
|
||||
if (options.keyword) {
|
||||
searchKeyword.value = decodeURIComponent(options.keyword)
|
||||
}
|
||||
searchDraftKeyword.value = searchKeyword.value
|
||||
void loadGuideFloors()
|
||||
void loadFacilityResults()
|
||||
})
|
||||
|
||||
|
||||
120
src/repositories/ExplainRepository.ts
Normal file
120
src/repositories/ExplainRepository.ts
Normal file
@@ -0,0 +1,120 @@
|
||||
import type {
|
||||
ExplainTrack,
|
||||
MuseumExhibit,
|
||||
MuseumHall,
|
||||
SearchIndexItem
|
||||
} from '@/domain/museum'
|
||||
import {
|
||||
mediaRepository,
|
||||
type MediaRepository
|
||||
} from '@/repositories/MediaRepository'
|
||||
import {
|
||||
museumContentRepository,
|
||||
type MuseumContentRepository
|
||||
} from '@/repositories/MuseumContentRepository'
|
||||
|
||||
export interface ExplainRepository {
|
||||
listExhibits(): Promise<MuseumExhibit[]>
|
||||
getExhibitById(id: string): Promise<MuseumExhibit | null>
|
||||
listHalls(): Promise<MuseumHall[]>
|
||||
getHallById(id: string): Promise<MuseumHall | null>
|
||||
listTracks(): Promise<ExplainTrack[]>
|
||||
getTrackByExhibitId(exhibitId: string): Promise<ExplainTrack | null>
|
||||
searchExplain(keyword?: string): Promise<SearchIndexItem[]>
|
||||
}
|
||||
|
||||
const trackTitleFor = (exhibit: MuseumExhibit) => `${exhibit.name}讲解`
|
||||
|
||||
export class DefaultExplainRepository implements ExplainRepository {
|
||||
constructor(
|
||||
private readonly content: MuseumContentRepository = museumContentRepository,
|
||||
private readonly media: MediaRepository = mediaRepository
|
||||
) {}
|
||||
|
||||
listExhibits() {
|
||||
return this.content.listExhibits()
|
||||
}
|
||||
|
||||
getExhibitById(id: string) {
|
||||
return this.content.getExhibitById(id)
|
||||
}
|
||||
|
||||
listHalls() {
|
||||
return this.content.listHalls()
|
||||
}
|
||||
|
||||
getHallById(id: string) {
|
||||
return this.content.getHallById(id)
|
||||
}
|
||||
|
||||
async listTracks() {
|
||||
const exhibits = await this.content.listExhibits()
|
||||
|
||||
return Promise.all(exhibits.map(async (exhibit): Promise<ExplainTrack> => {
|
||||
const media = await this.media.getMediaForExplainTrack(exhibit.id)
|
||||
return {
|
||||
id: `track-${exhibit.id}`,
|
||||
exhibitId: exhibit.id,
|
||||
hallId: exhibit.hallId,
|
||||
title: trackTitleFor(exhibit),
|
||||
summary: exhibit.description,
|
||||
mediaId: media?.id,
|
||||
coverImage: exhibit.image,
|
||||
poiId: exhibit.poiId,
|
||||
floorId: exhibit.floorId,
|
||||
available: media?.available === true
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
async getTrackByExhibitId(exhibitId: string) {
|
||||
const tracks = await this.listTracks()
|
||||
return tracks.find((track) => track.exhibitId === exhibitId) || null
|
||||
}
|
||||
|
||||
async searchExplain(keyword = '') {
|
||||
const normalizedKeyword = keyword.trim().toLowerCase()
|
||||
const [exhibits, halls] = await Promise.all([
|
||||
this.content.listExhibits(),
|
||||
this.content.listHalls()
|
||||
])
|
||||
|
||||
const exhibitItems = exhibits
|
||||
.filter((exhibit) => !normalizedKeyword || [
|
||||
exhibit.name,
|
||||
exhibit.hallName,
|
||||
exhibit.floorLabel,
|
||||
...(exhibit.tags || [])
|
||||
].filter(Boolean).join(' ').toLowerCase().includes(normalizedKeyword))
|
||||
.map<SearchIndexItem>((exhibit) => ({
|
||||
id: exhibit.id,
|
||||
name: exhibit.name,
|
||||
desc: `${exhibit.hallName || '展项'} · ${exhibit.floorLabel || ''}`.trim(),
|
||||
type: 'exhibit',
|
||||
exhibitId: exhibit.id,
|
||||
hallId: exhibit.hallId,
|
||||
poiId: exhibit.poiId,
|
||||
floorId: exhibit.floorId
|
||||
}))
|
||||
|
||||
const hallItems = halls
|
||||
.filter((hall) => !normalizedKeyword || [
|
||||
hall.name,
|
||||
hall.floorLabel,
|
||||
hall.description
|
||||
].filter(Boolean).join(' ').toLowerCase().includes(normalizedKeyword))
|
||||
.map<SearchIndexItem>((hall) => ({
|
||||
id: hall.id,
|
||||
name: hall.name,
|
||||
desc: `${hall.floorLabel || ''} · ${hall.exhibitCount || 0}件展项`.trim(),
|
||||
type: 'hall',
|
||||
hallId: hall.id,
|
||||
poiId: hall.poiId,
|
||||
floorId: hall.floorId
|
||||
}))
|
||||
|
||||
return [...exhibitItems, ...hallItems]
|
||||
}
|
||||
}
|
||||
|
||||
export const explainRepository = new DefaultExplainRepository()
|
||||
64
src/repositories/GuideModelRepository.ts
Normal file
64
src/repositories/GuideModelRepository.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import type {
|
||||
GuideModelFloorAsset,
|
||||
GuideModelRenderPackage,
|
||||
GuideModelSource,
|
||||
GuideRenderPoi
|
||||
} from '@/domain/guideModel'
|
||||
import {
|
||||
formatNavFloorLabel
|
||||
} from '@/data/adapters/navAssetsAdapter'
|
||||
import {
|
||||
defaultStaticNavAssetsProvider,
|
||||
type StaticNavAssetsProvider,
|
||||
type StaticNavPoiPayload
|
||||
} from '@/data/providers/staticNavAssetsProvider'
|
||||
|
||||
const toRenderPoi = (poi: StaticNavPoiPayload): GuideRenderPoi => ({
|
||||
id: poi.id,
|
||||
name: poi.name,
|
||||
floorId: poi.floorId,
|
||||
primaryCategory: poi.primaryCategory,
|
||||
primaryCategoryZh: poi.primaryCategoryZh,
|
||||
iconType: poi.iconType || poi.primaryCategory,
|
||||
positionGltf: poi.positionGltf
|
||||
})
|
||||
|
||||
export interface GuideModelRepository extends GuideModelSource {}
|
||||
|
||||
export class StaticGuideModelRepository implements GuideModelRepository {
|
||||
constructor(private readonly provider: StaticNavAssetsProvider = defaultStaticNavAssetsProvider) {}
|
||||
|
||||
async loadPackage(): Promise<GuideModelRenderPackage> {
|
||||
const [manifest, floorIndex] = await Promise.all([
|
||||
this.provider.loadManifest(),
|
||||
this.provider.loadFloorIndex()
|
||||
])
|
||||
|
||||
const floors: GuideModelFloorAsset[] = [...floorIndex.floors]
|
||||
.sort((a, b) => a.order - b.order)
|
||||
.map((floor) => ({
|
||||
floorId: floor.floorId,
|
||||
label: formatNavFloorLabel(floor.floorId),
|
||||
order: floor.order,
|
||||
modelUrl: this.provider.assetUrl(floor.modelAsset)
|
||||
}))
|
||||
|
||||
return {
|
||||
overviewModelUrl: this.provider.assetUrl(manifest.assets.overviewModel.asset),
|
||||
floors
|
||||
}
|
||||
}
|
||||
|
||||
async loadFloorPois(floorId: string) {
|
||||
const floorIndex = await this.provider.loadFloorIndex()
|
||||
const floor = floorIndex.floors.find((item) => item.floorId === floorId)
|
||||
if (!floor) return []
|
||||
|
||||
const pois = await this.provider.loadFloorPois(floor.poiDataAsset)
|
||||
return pois
|
||||
.map(toRenderPoi)
|
||||
.filter((poi) => Array.isArray(poi.positionGltf) && poi.positionGltf.length === 3)
|
||||
}
|
||||
}
|
||||
|
||||
export const guideModelRepository = new StaticGuideModelRepository()
|
||||
122
src/repositories/GuideRepository.ts
Normal file
122
src/repositories/GuideRepository.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
import type {
|
||||
GuideLocationPreview,
|
||||
MuseumFloor,
|
||||
MuseumPoi
|
||||
} from '@/domain/museum'
|
||||
import {
|
||||
NAV_ROUTE_READINESS
|
||||
} from '@/domain/guideReadiness'
|
||||
import {
|
||||
formatNavFloorLabel,
|
||||
navFloorIdFromLabel,
|
||||
toMuseumPoi
|
||||
} from '@/data/adapters/navAssetsAdapter'
|
||||
import {
|
||||
defaultStaticNavAssetsProvider,
|
||||
type StaticNavAssetsProvider
|
||||
} from '@/data/providers/staticNavAssetsProvider'
|
||||
|
||||
const searchableCategories = new Set([
|
||||
'touring_poi',
|
||||
'basic_service_facility',
|
||||
'transport_circulation',
|
||||
'accessibility_special_service',
|
||||
'operation_experience'
|
||||
])
|
||||
|
||||
const toSearchText = (poi: MuseumPoi) => [
|
||||
poi.name,
|
||||
poi.floorId,
|
||||
poi.floorLabel,
|
||||
poi.primaryCategory.label,
|
||||
poi.primaryCategory.iconType,
|
||||
...poi.categories.flatMap((category) => [
|
||||
category.label,
|
||||
category.id,
|
||||
category.iconType
|
||||
])
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
.toLowerCase()
|
||||
|
||||
const toLocationPreview = (poi: MuseumPoi): GuideLocationPreview => ({
|
||||
poiId: poi.id,
|
||||
name: poi.name,
|
||||
floorId: poi.floorId,
|
||||
floorLabel: poi.floorLabel,
|
||||
primaryCategoryZh: poi.primaryCategory.label,
|
||||
positionGltf: poi.positionGltf
|
||||
})
|
||||
|
||||
export interface GuideRepository {
|
||||
getAssetBaseUrl(): string
|
||||
getFloors(): Promise<MuseumFloor[]>
|
||||
normalizeFloorId(labelOrId: string): string
|
||||
listPois(): Promise<MuseumPoi[]>
|
||||
getPoiById(id: string): Promise<MuseumPoi | null>
|
||||
searchPois(keyword?: string): Promise<MuseumPoi[]>
|
||||
getLocationPreview(poiId: string): Promise<GuideLocationPreview | null>
|
||||
getRouteReadiness(): typeof NAV_ROUTE_READINESS
|
||||
}
|
||||
|
||||
export class StaticGuideRepository implements GuideRepository {
|
||||
private poiCache: MuseumPoi[] | null = null
|
||||
|
||||
constructor(private readonly provider: StaticNavAssetsProvider = defaultStaticNavAssetsProvider) {}
|
||||
|
||||
getAssetBaseUrl() {
|
||||
return this.provider.baseUrl
|
||||
}
|
||||
|
||||
async getFloors() {
|
||||
const floorIndex = await this.provider.loadFloorIndex()
|
||||
return [...floorIndex.floors]
|
||||
.sort((a, b) => b.order - a.order)
|
||||
.map((floor) => ({
|
||||
id: floor.floorId,
|
||||
label: formatNavFloorLabel(floor.floorId),
|
||||
order: floor.order
|
||||
}))
|
||||
}
|
||||
|
||||
normalizeFloorId(labelOrId: string) {
|
||||
return navFloorIdFromLabel(labelOrId)
|
||||
}
|
||||
|
||||
async listPois() {
|
||||
if (this.poiCache) return this.poiCache
|
||||
|
||||
const pois = await this.provider.loadPoiIndex()
|
||||
this.poiCache = pois
|
||||
.filter((poi) => searchableCategories.has(poi.primaryCategory))
|
||||
.map(toMuseumPoi)
|
||||
|
||||
return this.poiCache
|
||||
}
|
||||
|
||||
async getPoiById(id: string) {
|
||||
const pois = await this.listPois()
|
||||
return pois.find((poi) => poi.id === id) || null
|
||||
}
|
||||
|
||||
async searchPois(keyword = '') {
|
||||
const pois = await this.listPois()
|
||||
const normalizedKeyword = keyword.trim().toLowerCase()
|
||||
|
||||
if (!normalizedKeyword) return pois
|
||||
|
||||
return pois.filter((poi) => toSearchText(poi).includes(normalizedKeyword))
|
||||
}
|
||||
|
||||
async getLocationPreview(poiId: string) {
|
||||
const poi = await this.getPoiById(poiId)
|
||||
return poi ? toLocationPreview(poi) : null
|
||||
}
|
||||
|
||||
getRouteReadiness() {
|
||||
return NAV_ROUTE_READINESS
|
||||
}
|
||||
}
|
||||
|
||||
export const guideRepository = new StaticGuideRepository()
|
||||
27
src/repositories/MediaRepository.ts
Normal file
27
src/repositories/MediaRepository.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type {
|
||||
MediaAsset
|
||||
} from '@/domain/museum'
|
||||
|
||||
export interface MediaRepository {
|
||||
getMediaById(id: string): Promise<MediaAsset | null>
|
||||
getMediaForExplainTrack(trackId: string): Promise<MediaAsset | null>
|
||||
}
|
||||
|
||||
const unavailableAudio = (id: string): MediaAsset => ({
|
||||
id,
|
||||
type: 'audio',
|
||||
available: false,
|
||||
unavailableReason: '正式讲解音频尚未接入媒体仓储'
|
||||
})
|
||||
|
||||
export class DefaultMediaRepository implements MediaRepository {
|
||||
async getMediaById(id: string) {
|
||||
return unavailableAudio(id)
|
||||
}
|
||||
|
||||
async getMediaForExplainTrack(trackId: string) {
|
||||
return unavailableAudio(`media-${trackId}`)
|
||||
}
|
||||
}
|
||||
|
||||
export const mediaRepository = new DefaultMediaRepository()
|
||||
124
src/repositories/MuseumContentRepository.ts
Normal file
124
src/repositories/MuseumContentRepository.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
import type {
|
||||
MuseumExhibit,
|
||||
MuseumHall,
|
||||
MuseumPoi,
|
||||
SearchIndexItem
|
||||
} from '@/domain/museum'
|
||||
import {
|
||||
guideRepository,
|
||||
type GuideRepository
|
||||
} from '@/repositories/GuideRepository'
|
||||
import {
|
||||
staticMuseumContentProvider,
|
||||
type MuseumContentProvider
|
||||
} from '@/data/providers/staticMuseumContentProvider'
|
||||
|
||||
export interface MuseumContentRepository {
|
||||
listFacilities(): Promise<MuseumPoi[]>
|
||||
getFacilityById(id: string): Promise<MuseumPoi | null>
|
||||
searchFacilities(keyword?: string): Promise<MuseumPoi[]>
|
||||
listExhibits(): Promise<MuseumExhibit[]>
|
||||
getExhibitById(id: string): Promise<MuseumExhibit | null>
|
||||
listHalls(): Promise<MuseumHall[]>
|
||||
getHallById(id: string): Promise<MuseumHall | null>
|
||||
searchContent(keyword?: string): Promise<SearchIndexItem[]>
|
||||
}
|
||||
|
||||
const normalize = (value: string) => value.trim().toLowerCase()
|
||||
const includesKeyword = (values: Array<string | undefined>, keyword: string) => (
|
||||
values.filter(Boolean).join(' ').toLowerCase().includes(keyword)
|
||||
)
|
||||
|
||||
export class DefaultMuseumContentRepository implements MuseumContentRepository {
|
||||
constructor(
|
||||
private readonly contentProvider: MuseumContentProvider = staticMuseumContentProvider,
|
||||
private readonly guide: GuideRepository = guideRepository
|
||||
) {}
|
||||
|
||||
listFacilities() {
|
||||
return this.guide.listPois()
|
||||
}
|
||||
|
||||
getFacilityById(id: string) {
|
||||
return this.guide.getPoiById(id)
|
||||
}
|
||||
|
||||
searchFacilities(keyword = '') {
|
||||
return this.guide.searchPois(keyword)
|
||||
}
|
||||
|
||||
listExhibits() {
|
||||
return this.contentProvider.listExhibits()
|
||||
}
|
||||
|
||||
async getExhibitById(id: string) {
|
||||
const exhibits = await this.contentProvider.listExhibits()
|
||||
return exhibits.find((exhibit) => exhibit.id === id) || null
|
||||
}
|
||||
|
||||
listHalls() {
|
||||
return this.contentProvider.listHalls()
|
||||
}
|
||||
|
||||
async getHallById(id: string) {
|
||||
const halls = await this.contentProvider.listHalls()
|
||||
return halls.find((hall) => hall.id === id) || null
|
||||
}
|
||||
|
||||
async searchContent(keyword = '') {
|
||||
const normalizedKeyword = normalize(keyword)
|
||||
const facilities = await this.searchFacilities(keyword)
|
||||
const exhibits = await this.listExhibits()
|
||||
const halls = await this.listHalls()
|
||||
|
||||
const exhibitItems = exhibits
|
||||
.filter((exhibit) => !normalizedKeyword || includesKeyword([
|
||||
exhibit.name,
|
||||
exhibit.hallName,
|
||||
exhibit.floorLabel,
|
||||
...(exhibit.tags || [])
|
||||
], normalizedKeyword))
|
||||
.map<SearchIndexItem>((exhibit) => ({
|
||||
id: exhibit.id,
|
||||
name: exhibit.name,
|
||||
desc: `${exhibit.hallName || '展项'} · ${exhibit.floorLabel || ''}`.trim(),
|
||||
type: 'exhibit',
|
||||
exhibitId: exhibit.id,
|
||||
poiId: exhibit.poiId,
|
||||
floorId: exhibit.floorId
|
||||
}))
|
||||
|
||||
const hallItems = halls
|
||||
.filter((hall) => !normalizedKeyword || includesKeyword([
|
||||
hall.name,
|
||||
hall.floorLabel,
|
||||
hall.description
|
||||
], normalizedKeyword))
|
||||
.map<SearchIndexItem>((hall) => ({
|
||||
id: hall.id,
|
||||
name: hall.name,
|
||||
desc: `${hall.floorLabel || ''} · ${hall.exhibitCount || 0}件展项`.trim(),
|
||||
type: 'hall',
|
||||
hallId: hall.id,
|
||||
poiId: hall.poiId,
|
||||
floorId: hall.floorId
|
||||
}))
|
||||
|
||||
const facilityItems = facilities.map<SearchIndexItem>((poi) => ({
|
||||
id: poi.id,
|
||||
name: poi.name,
|
||||
desc: `${poi.floorLabel} · ${poi.primaryCategory.label}`,
|
||||
type: 'facility',
|
||||
poiId: poi.id,
|
||||
floorId: poi.floorId
|
||||
}))
|
||||
|
||||
return [
|
||||
...exhibitItems,
|
||||
...hallItems,
|
||||
...facilityItems
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export const museumContentRepository = new DefaultMuseumContentRepository()
|
||||
@@ -1,164 +0,0 @@
|
||||
export const NAV_ASSET_BASE_URL = '/static/nav-assets/app_nav_assets_v2_clean_20260609_075339'
|
||||
|
||||
export const NAV_ROUTE_UNAVAILABLE_MESSAGE = '正式路线数据尚未接入,可先查看馆内三维位置'
|
||||
|
||||
export interface NavFloorOption {
|
||||
id: string
|
||||
label: string
|
||||
order: number
|
||||
}
|
||||
|
||||
export interface CleanNavPoiCategory {
|
||||
topCategory: string
|
||||
topCategoryZh: string
|
||||
subcategory: string
|
||||
iconType: string
|
||||
reason?: string
|
||||
}
|
||||
|
||||
export interface CleanNavPoi {
|
||||
id: string
|
||||
name: string
|
||||
floorId: string
|
||||
primaryCategory: string
|
||||
primaryCategoryZh: string
|
||||
categories?: CleanNavPoiCategory[]
|
||||
iconType?: string
|
||||
positionGltf?: [number, number, number]
|
||||
navigationReadiness?: string
|
||||
sourceConfidence?: string
|
||||
}
|
||||
|
||||
interface CleanPoiIndex {
|
||||
status: string
|
||||
pois: CleanNavPoi[]
|
||||
}
|
||||
|
||||
export const NAV_FLOOR_OPTIONS: NavFloorOption[] = [
|
||||
{ id: 'L5', label: '5F', order: 5 },
|
||||
{ id: 'L4', label: '4F', order: 4 },
|
||||
{ id: 'L3', label: '3F', order: 3 },
|
||||
{ id: 'L2', label: '2F', order: 2 },
|
||||
{ id: 'L1.5', label: '1.5F', order: 1.5 },
|
||||
{ id: 'L1', label: '1F', order: 1 },
|
||||
{ id: 'L-1', label: 'B1', order: -1 },
|
||||
{ id: 'L-2', label: 'B2', order: -2 }
|
||||
]
|
||||
|
||||
const searchableCategories = new Set([
|
||||
'touring_poi',
|
||||
'basic_service_facility',
|
||||
'transport_circulation',
|
||||
'accessibility_special_service',
|
||||
'operation_experience'
|
||||
])
|
||||
|
||||
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(/^\/+/, '')}`
|
||||
)
|
||||
|
||||
export const formatNavFloorLabel = (floorId: string) => (
|
||||
NAV_FLOOR_OPTIONS.find((floor) => floor.id === floorId)?.label || floorId
|
||||
)
|
||||
|
||||
export const navFloorIdFromLabel = (labelOrId: string) => (
|
||||
NAV_FLOOR_OPTIONS.find((floor) => floor.label === labelOrId || floor.id === labelOrId)?.id || labelOrId
|
||||
)
|
||||
|
||||
export const isPoiAccessible = (poi: CleanNavPoi) => (
|
||||
poi.primaryCategory === 'accessibility_special_service'
|
||||
|| poi.categories?.some((category) => category.topCategory === 'accessibility_special_service') === true
|
||||
)
|
||||
|
||||
const parseJsonPayload = <T>(payload: unknown): T => {
|
||||
if (typeof payload === 'string') {
|
||||
return JSON.parse(payload) as T
|
||||
}
|
||||
|
||||
return payload as T
|
||||
}
|
||||
|
||||
const requestJson = <T>(url: string): Promise<T> => new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url,
|
||||
method: 'GET',
|
||||
success: (response) => {
|
||||
const statusCode = Number(response.statusCode || 0)
|
||||
if (statusCode < 200 || statusCode >= 300) {
|
||||
reject(new Error(`导览资源读取失败: ${statusCode} ${url}`))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
resolve(parseJsonPayload<T>(response.data))
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
},
|
||||
fail: reject
|
||||
})
|
||||
})
|
||||
|
||||
export const loadCleanNavPois = async (baseUrl = NAV_ASSET_BASE_URL) => {
|
||||
const cacheKey = normalizeBaseUrl(baseUrl)
|
||||
const cachedPois = poiCache.get(cacheKey)
|
||||
if (cachedPois) return cachedPois
|
||||
|
||||
const pendingPois = poiRequestCache.get(cacheKey)
|
||||
if (pendingPois) return pendingPois
|
||||
|
||||
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) => {
|
||||
const pois = await loadCleanNavPois(baseUrl)
|
||||
return pois.find((poi) => poi.id === id) || null
|
||||
}
|
||||
|
||||
export const searchCleanNavPois = async (keyword = '', baseUrl = NAV_ASSET_BASE_URL) => {
|
||||
const pois = await loadCleanNavPois(baseUrl)
|
||||
const normalizedKeyword = keyword.trim().toLowerCase()
|
||||
|
||||
const matchedPois = normalizedKeyword
|
||||
? pois.filter((poi) => {
|
||||
const searchableText = [
|
||||
poi.name,
|
||||
poi.floorId,
|
||||
formatNavFloorLabel(poi.floorId),
|
||||
poi.primaryCategoryZh,
|
||||
poi.iconType,
|
||||
...(poi.categories || []).flatMap((category) => [
|
||||
category.topCategoryZh,
|
||||
category.subcategory,
|
||||
category.iconType
|
||||
])
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
.toLowerCase()
|
||||
|
||||
return searchableText.includes(normalizedKeyword)
|
||||
})
|
||||
: pois
|
||||
|
||||
return matchedPois
|
||||
}
|
||||
75
src/usecases/explainUseCase.ts
Normal file
75
src/usecases/explainUseCase.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import type {
|
||||
ExplainTrack,
|
||||
MediaAsset,
|
||||
MuseumExhibit,
|
||||
MuseumHall,
|
||||
SearchIndexItem
|
||||
} from '@/domain/museum'
|
||||
import {
|
||||
explainRepository,
|
||||
type ExplainRepository
|
||||
} from '@/repositories/ExplainRepository'
|
||||
import {
|
||||
mediaRepository,
|
||||
type MediaRepository
|
||||
} from '@/repositories/MediaRepository'
|
||||
|
||||
export interface ExplainAudioSelection {
|
||||
exhibit: MuseumExhibit
|
||||
track: ExplainTrack | null
|
||||
media: MediaAsset | null
|
||||
playable: boolean
|
||||
unavailableMessage?: string
|
||||
}
|
||||
|
||||
export class ExplainUseCase {
|
||||
constructor(
|
||||
private readonly explain: ExplainRepository = explainRepository,
|
||||
private readonly media: MediaRepository = mediaRepository
|
||||
) {}
|
||||
|
||||
listExhibits() {
|
||||
return this.explain.listExhibits()
|
||||
}
|
||||
|
||||
getExhibitById(id: string) {
|
||||
return this.explain.getExhibitById(id)
|
||||
}
|
||||
|
||||
listHalls(): Promise<MuseumHall[]> {
|
||||
return this.explain.listHalls()
|
||||
}
|
||||
|
||||
getHallById(id: string) {
|
||||
return this.explain.getHallById(id)
|
||||
}
|
||||
|
||||
async listExhibitsByHallId(hallId: string) {
|
||||
const exhibits = await this.explain.listExhibits()
|
||||
return exhibits.filter((exhibit) => exhibit.hallId === hallId)
|
||||
}
|
||||
|
||||
searchExplain(keyword?: string): Promise<SearchIndexItem[]> {
|
||||
return this.explain.searchExplain(keyword)
|
||||
}
|
||||
|
||||
async selectAudioForExhibit(exhibitId: string): Promise<ExplainAudioSelection | null> {
|
||||
const exhibit = await this.explain.getExhibitById(exhibitId)
|
||||
if (!exhibit) return null
|
||||
|
||||
const track = await this.explain.getTrackByExhibitId(exhibitId)
|
||||
const media = track?.mediaId
|
||||
? await this.media.getMediaById(track.mediaId)
|
||||
: null
|
||||
|
||||
return {
|
||||
exhibit,
|
||||
track,
|
||||
media,
|
||||
playable: media?.available === true && Boolean(media.url),
|
||||
unavailableMessage: media?.unavailableReason || '该展项暂无讲解音频'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const explainUseCase = new ExplainUseCase()
|
||||
124
src/usecases/guideUseCase.ts
Normal file
124
src/usecases/guideUseCase.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
import type {
|
||||
GuideLocationPreviewPlan,
|
||||
GuidePreviewStep,
|
||||
GuideStartLocation,
|
||||
MuseumPoi
|
||||
} from '@/domain/museum'
|
||||
import {
|
||||
guideRepository,
|
||||
type GuideRepository
|
||||
} from '@/repositories/GuideRepository'
|
||||
import {
|
||||
guideModelRepository,
|
||||
type GuideModelRepository
|
||||
} from '@/repositories/GuideModelRepository'
|
||||
|
||||
const startSourceLabels: Record<string, string> = {
|
||||
'facility-detail': '设施详情选择',
|
||||
manual: '手动选择'
|
||||
}
|
||||
|
||||
const formatStartSourceLabel = (source?: string) => (
|
||||
source ? startSourceLabels[source] || source : ''
|
||||
)
|
||||
|
||||
const formatStartStepText = (startLocation: GuideStartLocation) => {
|
||||
const sourceLabel = formatStartSourceLabel(startLocation.source)
|
||||
const floorSuffix = startLocation.floor && !startLocation.label.includes(startLocation.floor)
|
||||
? ` · ${startLocation.floor}`
|
||||
: ''
|
||||
const sourceSuffix = sourceLabel ? `(${sourceLabel})` : ''
|
||||
|
||||
return `起点:${startLocation.label}${floorSuffix}${sourceSuffix}`
|
||||
}
|
||||
|
||||
const createPreviewSteps = (
|
||||
poi: MuseumPoi | null,
|
||||
startLocation: GuideStartLocation | null,
|
||||
routeUnavailableMessage: string
|
||||
): GuidePreviewStep[] => {
|
||||
if (startLocation) {
|
||||
return [
|
||||
{
|
||||
id: 'start',
|
||||
text: formatStartStepText(startLocation)
|
||||
},
|
||||
{
|
||||
id: 'target',
|
||||
text: poi
|
||||
? `目标:${poi.floorLabel} · ${poi.primaryCategory.label} · 位置预览`
|
||||
: '目标来自 clean 导览数据,暂仅支持位置预览'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
id: 'floor',
|
||||
text: poi ? `目标位于 ${poi.floorLabel} · ${poi.primaryCategory.label}` : '目标来自 clean 导览数据'
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
text: routeUnavailableMessage
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
export class GuideUseCase {
|
||||
constructor(
|
||||
private readonly guide: GuideRepository = guideRepository,
|
||||
private readonly guideModel: GuideModelRepository = guideModelRepository
|
||||
) {}
|
||||
|
||||
getRouteReadiness() {
|
||||
return this.guide.getRouteReadiness()
|
||||
}
|
||||
|
||||
getFloors() {
|
||||
return this.guide.getFloors()
|
||||
}
|
||||
|
||||
getAssetBaseUrl() {
|
||||
return this.guide.getAssetBaseUrl()
|
||||
}
|
||||
|
||||
getModelSource() {
|
||||
return this.guideModel
|
||||
}
|
||||
|
||||
normalizeFloorId(labelOrId: string) {
|
||||
return this.guide.normalizeFloorId(labelOrId)
|
||||
}
|
||||
|
||||
searchPois(keyword?: string) {
|
||||
return this.guide.searchPois(keyword)
|
||||
}
|
||||
|
||||
getPoiById(id: string) {
|
||||
return this.guide.getPoiById(id)
|
||||
}
|
||||
|
||||
async createLocationPreviewPlan(
|
||||
facilityId: string,
|
||||
target: string,
|
||||
startLocation: GuideStartLocation | null = null
|
||||
): Promise<GuideLocationPreviewPlan> {
|
||||
const poi = facilityId ? await this.guide.getPoiById(facilityId) : null
|
||||
const routeReadiness = this.guide.getRouteReadiness()
|
||||
const targetLocation = poi ? await this.guide.getLocationPreview(poi.id) : null
|
||||
|
||||
return {
|
||||
id: `route-${facilityId || 'custom'}`,
|
||||
facilityId,
|
||||
target: target || poi?.name || '目标地点',
|
||||
summary: poi
|
||||
? `${poi.floorLabel} · ${poi.primaryCategory.label} · 位置预览`
|
||||
: '位置预览 · 尚未接入正式路线图',
|
||||
steps: createPreviewSteps(poi, startLocation, routeReadiness.message),
|
||||
targetLocation,
|
||||
startLocation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const guideUseCase = new GuideUseCase()
|
||||
@@ -1,98 +0,0 @@
|
||||
/**
|
||||
* Legacy demo data loader.
|
||||
*
|
||||
* 当前导览模块不要再从 src/assets/data 取数;室内导览、搜索、位置预览
|
||||
* 统一使用 src/services/navAssets.ts 读取 clean nav assets。
|
||||
* 这里保留给尚未重构的历史演示页面,避免删除造成不可控回归。
|
||||
*/
|
||||
|
||||
// 加载楼层数据
|
||||
export const loadFloors = async () => {
|
||||
try {
|
||||
const data = await import('@/assets/data/floors.json')
|
||||
return data.default || data
|
||||
} catch (error) {
|
||||
console.error('加载楼层数据失败:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
// 加载展厅数据
|
||||
export const loadHalls = async () => {
|
||||
try {
|
||||
const data = await import('@/assets/data/halls.json')
|
||||
return data.default || data
|
||||
} catch (error) {
|
||||
console.error('加载展厅数据失败:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
// 加载展品数据
|
||||
export const loadExhibits = async () => {
|
||||
try {
|
||||
const data = await import('@/assets/data/exhibits.json')
|
||||
return data.default || data
|
||||
} catch (error) {
|
||||
console.error('加载展品数据失败:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
// 加载设施数据
|
||||
export const loadFacilities = async () => {
|
||||
try {
|
||||
const data = await import('@/assets/data/facilities.json')
|
||||
return data.default || data
|
||||
} catch (error) {
|
||||
console.error('加载设施数据失败:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
// 加载路线数据
|
||||
export const loadRoutes = async () => {
|
||||
try {
|
||||
const data = await import('@/assets/data/routes.json')
|
||||
return data.default || data
|
||||
} catch (error) {
|
||||
console.error('加载路线数据失败:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
// 根据 ID 查找展品
|
||||
export const findExhibitById = async (id: string) => {
|
||||
const exhibits = await loadExhibits()
|
||||
return exhibits.find((item: any) => item.id === id)
|
||||
}
|
||||
|
||||
// 根据 ID 查找展厅
|
||||
export const findHallById = async (id: string) => {
|
||||
const halls = await loadHalls()
|
||||
return halls.find((item: any) => item.id === id)
|
||||
}
|
||||
|
||||
// 根据 ID 查找设施
|
||||
export const findFacilityById = async (id: string) => {
|
||||
const facilities = await loadFacilities()
|
||||
return facilities.find((item: any) => item.id === id)
|
||||
}
|
||||
|
||||
// 根据 ID 查找路线
|
||||
export const findRouteById = async (id: string) => {
|
||||
const routes = await loadRoutes()
|
||||
return routes.find((item: any) => item.id === id)
|
||||
}
|
||||
|
||||
// 根据楼层筛选展厅
|
||||
export const filterHallsByFloor = async (floorId: string) => {
|
||||
const halls = await loadHalls()
|
||||
return halls.filter((item: any) => item.floor === floorId)
|
||||
}
|
||||
|
||||
// 根据展厅筛选展品
|
||||
export const filterExhibitsByHall = async (hallId: string) => {
|
||||
const exhibits = await loadExhibits()
|
||||
return exhibits.filter((item: any) => item.hallId === hallId)
|
||||
}
|
||||
90
src/view-models/explainViewModels.ts
Normal file
90
src/view-models/explainViewModels.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import type {
|
||||
MuseumExhibit,
|
||||
MuseumHall,
|
||||
SearchIndexItem
|
||||
} from '@/domain/museum'
|
||||
|
||||
export interface ExplainExhibitViewModel {
|
||||
id: string
|
||||
name: string
|
||||
hall?: string
|
||||
floor?: string
|
||||
image?: string
|
||||
hasAudio: boolean
|
||||
audioUnavailableReason?: string
|
||||
poiId?: string
|
||||
}
|
||||
|
||||
export interface ExplainDetailViewModel {
|
||||
id: string
|
||||
name: string
|
||||
artist?: string
|
||||
year?: string
|
||||
material?: string
|
||||
size?: string
|
||||
hall?: string
|
||||
image: string
|
||||
description: string
|
||||
hasAudio: boolean
|
||||
audioUnavailableReason?: string
|
||||
poiId?: string
|
||||
}
|
||||
|
||||
export interface HallDetailViewModel {
|
||||
id: string
|
||||
name: string
|
||||
floorLabel: string
|
||||
description: string
|
||||
image: string
|
||||
exhibitCount: number
|
||||
area?: string
|
||||
poiId?: string
|
||||
}
|
||||
|
||||
export const toExplainExhibitViewModel = (exhibit: MuseumExhibit): ExplainExhibitViewModel => ({
|
||||
id: exhibit.id,
|
||||
name: exhibit.name,
|
||||
hall: exhibit.hallName && exhibit.floorLabel
|
||||
? `${exhibit.hallName} ${exhibit.floorLabel}`
|
||||
: exhibit.hallName || exhibit.floorLabel,
|
||||
floor: exhibit.floorLabel,
|
||||
image: exhibit.image,
|
||||
hasAudio: false,
|
||||
audioUnavailableReason: '正式讲解音频尚未接入媒体仓储',
|
||||
poiId: exhibit.poiId
|
||||
})
|
||||
|
||||
export const toExplainDetailViewModel = (exhibit: MuseumExhibit): ExplainDetailViewModel => ({
|
||||
id: exhibit.id,
|
||||
name: exhibit.name,
|
||||
artist: exhibit.artist,
|
||||
year: exhibit.year,
|
||||
material: exhibit.material,
|
||||
size: exhibit.size,
|
||||
hall: exhibit.hallName && exhibit.floorLabel
|
||||
? `${exhibit.hallName} ${exhibit.floorLabel}`
|
||||
: exhibit.hallName || exhibit.floorLabel,
|
||||
image: exhibit.image || '/static/exhibit-placeholder.jpg',
|
||||
description: exhibit.description || '该展项介绍待正式内容库补充。',
|
||||
hasAudio: false,
|
||||
audioUnavailableReason: '正式讲解音频尚未接入媒体仓储',
|
||||
poiId: exhibit.poiId
|
||||
})
|
||||
|
||||
export const toHallDetailViewModel = (hall: MuseumHall): HallDetailViewModel => ({
|
||||
id: hall.id,
|
||||
name: hall.name,
|
||||
floorLabel: hall.floorLabel || '楼层待补充',
|
||||
description: hall.description || '该展厅介绍待正式内容库补充。',
|
||||
image: hall.image || '/static/hall-placeholder.jpg',
|
||||
exhibitCount: hall.exhibitCount || 0,
|
||||
area: hall.area,
|
||||
poiId: hall.poiId
|
||||
})
|
||||
|
||||
export const toExplainSearchResultViewModel = (item: SearchIndexItem) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
desc: item.desc,
|
||||
type: item.type
|
||||
})
|
||||
70
src/view-models/guideViewModels.ts
Normal file
70
src/view-models/guideViewModels.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import type {
|
||||
GuideLocationPreview,
|
||||
GuideLocationPreviewPlan,
|
||||
MuseumPoi
|
||||
} from '@/domain/museum'
|
||||
|
||||
export interface FacilityResultViewModel {
|
||||
id: string
|
||||
name: string
|
||||
floor: string
|
||||
meta: string
|
||||
accessible: boolean
|
||||
action: '查看'
|
||||
}
|
||||
|
||||
export interface FacilityDetailViewModel {
|
||||
id: string
|
||||
name: string
|
||||
status: string
|
||||
location: string
|
||||
traffic: string
|
||||
tags: string[]
|
||||
}
|
||||
|
||||
export interface TargetPoiFocusRequestViewModel extends GuideLocationPreview {
|
||||
requestId: number | string
|
||||
}
|
||||
|
||||
export const toFacilityResultViewModel = (poi: MuseumPoi): FacilityResultViewModel => ({
|
||||
id: poi.id,
|
||||
name: poi.name,
|
||||
floor: poi.floorLabel,
|
||||
meta: `${poi.floorLabel}|${poi.primaryCategory.label}|${poi.navigationReadiness || '展示点位'}`,
|
||||
accessible: poi.accessible,
|
||||
action: '查看'
|
||||
})
|
||||
|
||||
export const toFacilityDetailViewModel = (
|
||||
poi: MuseumPoi,
|
||||
routeUnavailableMessage: string
|
||||
): FacilityDetailViewModel => ({
|
||||
id: poi.id,
|
||||
name: poi.name,
|
||||
status: '可预览',
|
||||
location: `${poi.floorLabel} · ${poi.primaryCategory.label}`,
|
||||
traffic: routeUnavailableMessage,
|
||||
tags: [
|
||||
poi.floorLabel,
|
||||
poi.primaryCategory.label,
|
||||
poi.accessible ? '无障碍相关' : '展示点位'
|
||||
]
|
||||
})
|
||||
|
||||
export const toTargetFocusRequestViewModel = (
|
||||
targetLocation: GuideLocationPreview,
|
||||
requestId: number | string
|
||||
): TargetPoiFocusRequestViewModel => ({
|
||||
...targetLocation,
|
||||
requestId
|
||||
})
|
||||
|
||||
export const initialLocationPreviewPlan = (): GuideLocationPreviewPlan => ({
|
||||
id: 'route-custom',
|
||||
facilityId: '',
|
||||
target: '目标地点',
|
||||
summary: '位置预览 · 尚未接入正式路线图',
|
||||
steps: [],
|
||||
targetLocation: null,
|
||||
startLocation: null
|
||||
})
|
||||
Reference in New Issue
Block a user