refactor: 重构数据层支持 SGS SDK 集成

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
lyf
2026-06-26 04:21:12 +08:00
parent a7413ee037
commit 15fbbec12d
16 changed files with 762 additions and 54 deletions

View File

@@ -20,6 +20,8 @@ export interface SgsTargetFocusResult {
message?: string
}
export type SgsFloorId = string | number
export const toNumericFloorId = (floorId: string | number | undefined) => {
if (typeof floorId === 'number') return floorId
if (!floorId) return 1
@@ -29,6 +31,17 @@ export const toNumericFloorId = (floorId: string | number | undefined) => {
return Number.isFinite(numeric) && numeric > 0 ? numeric : 1
}
export const toSgsFloorId = (floorId: string | number | undefined): SgsFloorId => {
if (typeof floorId === 'number') return floorId
if (!floorId) return 1
const normalized = floorId.toString().trim()
if (/^\d{15,}$/.test(normalized)) return normalized
if (/^\d+$/.test(normalized)) return Number(normalized)
return toNumericFloorId(normalized)
}
export const toAppFloorId = (floorId: string | number | undefined) => `L${toNumericFloorId(floorId)}`
export const toFloorLabel = (floorId: string | number | undefined) => `${toNumericFloorId(floorId)}F`

View File

@@ -14,7 +14,7 @@ interface SgsMapServiceOptions {
scriptUrl: string
sdkUrl: string
targetOrigin: string
floorId: number
floorId: string | number
timeout: number
}
@@ -116,7 +116,7 @@ export class SgsMapService {
return this.sdk
}
async changeFloor(floorId: number) {
async changeFloor(floorId: string | number) {
const sdk = await this.getReadySdk()
return sdk.changeFloor(floorId, this.options.timeout)
}