统一中间层楼层展示为MF
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-19 16:37:16 +08:00
parent d199b4602f
commit 97788a3e9f
4 changed files with 24 additions and 3 deletions

View File

@@ -19,11 +19,13 @@ export const formatNavFloorLabel = (floorId: string) => {
const value = Number(match[1])
if (Number.isNaN(value)) return floorId
if (value === 1.5) return 'MF'
return value < 0 ? `B${Math.abs(value)}` : `${value}F`
}
export const navFloorIdFromLabel = (labelOrId: string) => {
if (floorIdPattern.test(labelOrId)) return labelOrId
if (labelOrId.trim().toUpperCase() === 'MF') return 'L1.5'
const basementMatch = labelOrId.match(/^B(\d+(?:\.\d+)?)$/i)
if (basementMatch) return `L-${basementMatch[1]}`

View File

@@ -226,7 +226,7 @@ export const formatSgsFloorLabel = (floorCode?: string | null, floorName?: strin
if (basementMatch) return `B${basementMatch[1]}`
const floorMatch = floorCode?.match(/^L(\d+(?:\.\d+)?)$/)
if (floorMatch) return `${floorMatch[1]}F`
if (floorMatch) return floorMatch[1] === '1.5' ? 'MF' : `${floorMatch[1]}F`
return floorName || floorCode || '未知楼层'
}

View File

@@ -16,7 +16,7 @@ interface FloorLike {
}
const indoorFloorCodePattern = /^L-?\d+(?:\.\d+)?$/i
const indoorFloorLabelPattern = /^(?:B\d+(?:\.\d+)?|\d+(?:\.\d+)?F)$/i
const indoorFloorLabelPattern = /^(?:B\d+(?:\.\d+)?|\d+(?:\.\d+)?F|MF)$/i
const rawNumericIdPattern = /^\d{6,}$/
const nonNavigableFloorPattern = /(EXTERIOR|OUTDOOR|BUILDING|FACADE|EXTERNAL|外立面|建筑外观|建筑外立面|馆外模型|馆外场景|馆外底图|馆外建筑|馆外外观|馆外)$/i
@@ -37,6 +37,8 @@ const parseFloorLevelFromToken = (value: unknown) => {
const labelMatch = normalized.match(/^(\d+(?:\.\d+)?)F$/)
if (labelMatch) return Number(labelMatch[1])
if (normalized === 'MF') return 1.5
const codeMatch = normalized.match(/^L(-?\d+(?:\.\d+)?)$/)
if (codeMatch) return Number(codeMatch[1])

View File

@@ -0,0 +1,17 @@
import { describe, expect, it } from 'vitest'
import { formatNavFloorLabel, navFloorIdFromLabel } from '@/data/adapters/navAssetsAdapter'
import { formatSgsFloorLabel } from '@/data/adapters/sgsSdkGuideAdapter'
import { getFloorSortLevel, isIndoorNavigableFloor } from '@/domain/guideFloor'
describe('中间层游客展示', () => {
it('将稳定层 ID L1.5 显示为 MF并可反向解析', () => {
expect(formatNavFloorLabel('L1.5')).toBe('MF')
expect(navFloorIdFromLabel('MF')).toBe('L1.5')
expect(formatSgsFloorLabel('L1.5')).toBe('MF')
})
it('MF 保持可导航和正确的楼层排序', () => {
expect(isIndoorNavigableFloor({ label: 'MF' })).toBe(true)
expect(getFloorSortLevel({ label: 'MF' })).toBe(1.5)
})
})