feat(mini): align companion pages and show OTA progress
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import type { DeviceFirmwareStatus } from '@/services/device'
|
||||
|
||||
export function firmwareProgressView(status: DeviceFirmwareStatus | null, refreshError = false) {
|
||||
const state = String(status?.update_status || '').toLowerCase()
|
||||
const complete = state === 'success' || state === 'completed'
|
||||
const failed = state === 'failed'
|
||||
const value = Number(status?.progress)
|
||||
const progress = complete ? 100 : Number.isFinite(value) ? Math.max(0, Math.min(100, value)) : 0
|
||||
const hasProgress = complete || progress > 0
|
||||
const target = status?.target_version
|
||||
const version = target && !['unknown', 'updating'].includes(target) ? target : status?.latest_version
|
||||
const title = complete ? '固件更新完成' : failed ? '固件更新失败' : '固件更新中'
|
||||
const message = complete ? '设备已完成更新,可以继续使用。'
|
||||
: failed ? '更新未完成,请确认设备电量和网络后重试。'
|
||||
: refreshError ? '暂时无法刷新进度,正在重试。你可以先关闭此窗口。'
|
||||
: state === 'sent' ? '更新指令已发送,等待设备确认。'
|
||||
: progress >= 100 ? '进度已达 100%,等待设备确认更新结果。'
|
||||
: hasProgress ? '请保持设备电量充足,并连接网络。'
|
||||
: '设备正在处理更新,等待进度上报。'
|
||||
return { title, message, version, progress, percent: Math.floor(progress), hasProgress, complete, failed }
|
||||
}
|
||||
Reference in New Issue
Block a user