修复离线路径误弹位置上报超时窗,并优化提醒设置与定位 Loading 展示。
离线或倒计时未进入提醒窗口时不再弹出超时提醒;全局 Loading 支持按需展示定位文案,提前提醒选项抽成共用组件。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -61,6 +61,8 @@ final class HomeLocationViewModel: ObservableObject {
|
||||
isOnline = false
|
||||
secondsUntilReport = 0
|
||||
expireTimestamp = nil
|
||||
showTimeoutDialog = false
|
||||
timeoutDialogTriggered = false
|
||||
return
|
||||
}
|
||||
|
||||
@ -156,31 +158,13 @@ final class HomeLocationViewModel: ObservableObject {
|
||||
await reportLocation(type: .immediate, staffId: staffId!, scenicId: scenicId!, toast: toast)
|
||||
}
|
||||
|
||||
/// 调用 detail 接口判断是否需要弹出超时提醒。
|
||||
/// 根据本地在线状态和倒计时判断是否需要弹出超时提醒。
|
||||
func checkLocationTimeout(staffId: Int?) async {
|
||||
guard reminderMinutes > 0 else {
|
||||
guard isOnline, reminderMinutes > 0, secondsUntilReport > 0 else {
|
||||
showTimeoutDialog = false
|
||||
return
|
||||
}
|
||||
guard let staffId, staffId > 0 else {
|
||||
showTimeoutDialog = false
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
let detail = try await api.locationDetail(staffId: staffId)
|
||||
if detail.expireTime <= 0 {
|
||||
showTimeoutDialog = true
|
||||
return
|
||||
}
|
||||
|
||||
let currentMillis = Date().timeIntervalSince1970 * 1000
|
||||
let expireMillis = Double(detail.expireTime) * 1000
|
||||
let thresholdMillis = expireMillis - Double(reminderMinutes * 60 * 1000)
|
||||
showTimeoutDialog = currentMillis >= thresholdMillis
|
||||
} catch {
|
||||
showTimeoutDialog = true
|
||||
}
|
||||
evaluateReminderThreshold(remainingSeconds: secondsUntilReport, forceDialog: true)
|
||||
}
|
||||
|
||||
/// 关闭超时对话框并将用户置为离线。
|
||||
@ -313,6 +297,8 @@ final class HomeLocationViewModel: ObservableObject {
|
||||
secondsUntilReport = 0
|
||||
lastReportAnchorTime = nil
|
||||
expireTimestamp = nil
|
||||
showTimeoutDialog = false
|
||||
timeoutDialogTriggered = false
|
||||
if clearPersisted {
|
||||
store.saveOnlineStatus(false)
|
||||
store.clearLastReportTime()
|
||||
@ -344,9 +330,9 @@ final class HomeLocationViewModel: ObservableObject {
|
||||
return false
|
||||
}
|
||||
|
||||
/// 判断是否到达提前提醒阈值。
|
||||
/// 判断是否到达提前提醒阈值(仅在线且倒计时进入提醒窗口时触发)。
|
||||
private func evaluateReminderThreshold(remainingSeconds: Int, forceDialog: Bool) {
|
||||
guard reminderMinutes > 0 else { return }
|
||||
guard isOnline, reminderMinutes > 0 else { return }
|
||||
let thresholdSeconds = reminderMinutes * 60
|
||||
guard remainingSeconds <= thresholdSeconds else { return }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user