refactor: 重构数据层支持 SGS SDK 集成
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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`
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user