定位刷新超时返回最近一次位置

This commit is contained in:
stu2not
2026-05-27 16:53:03 +08:00
parent bb56cda2e8
commit fb11e48584
4 changed files with 30 additions and 19 deletions

View File

@@ -2,9 +2,7 @@ import { View, Text, Map } from '@tarojs/components'
import { useState } from 'react'
import Taro, { useDidShow } from '@tarojs/taro'
import { getToken } from '@/services/auth'
import { DEVICE_UNAVAILABLE_MESSAGE } from '@/services/api'
import { loadCurrentChildBindingContext } from '@/services/binding'
import { getDeviceOnlineStatus } from '@/services/device'
import {
getCurrentDeviceLocation,
getDeviceTrajectory,
@@ -187,18 +185,11 @@ export default function Location() {
return
}
const onlineStatus = await getDeviceOnlineStatus(resolvedDeviceId)
if (onlineStatus && !onlineStatus.online) {
setDeviceLocation(null)
setTrajectory([])
setSelectedPoint(null)
setCoordinates(DEFAULT_COORDINATES)
setLocationNotice(onlineStatus.message || '设备不在线或暂时无法上报位置')
return
}
const currentLocation = await getCurrentDeviceLocation(resolvedDeviceId)
setDeviceLocation(currentLocation)
if (currentLocation?.stale || currentLocation?.realtime === false) {
setLocationNotice('已显示最近一次定位')
}
const nextCoordinates = currentLocation
? {
@@ -249,9 +240,7 @@ export default function Location() {
}
setLoading(false)
console.error('[location] load failed:', error)
const message = error?.message === DEVICE_UNAVAILABLE_MESSAGE
? '设备不在线或处于休眠中,暂时无法获取位置'
: error?.message || '位置更新失败'
const message = error?.status === 408 ? '暂时无法刷新定位' : error?.message || '位置更新失败'
Taro.showToast({
title: message,
icon: 'none',

View File

@@ -17,6 +17,8 @@ export interface DeviceLocation {
device_time: string
server_time: string
updated_at: string
stale?: boolean
realtime?: boolean
}
export interface DeviceTrajectoryPoint extends DeviceLocation {