fix(usage): 修复首页使用时长卡在骨架并统一占位对齐
- 当天无数据(后端返回 null,如跨天后设备尚未上报)按 0 处理,不再抛异常卡在加载态 - 请求失败时结束骨架,保留缓存或回落 0s - 占位行与真实行统一 40rpx 行高、12rpx 间距,三条纵向位置对齐
This commit is contained in:
1 parent
b41d604e83
commit
02d98fb8b3
2 files changed
+22
-3
No files matched your search
+18
-1
@@ -328,6 +328,17 @@ Page({
|
||||
}
|
||||
try {
|
||||
const day = await getUsageDay(sn)
|
||||
// 当天无数据时后端返回 null(如跨天后设备尚未上报):按 0 处理,不能卡在骨架
|
||||
if (!day) {
|
||||
this.setData({
|
||||
usageTotal: '0s',
|
||||
usageRingPercent: 0,
|
||||
usageItems: [],
|
||||
usageLoading: false
|
||||
})
|
||||
saveUsageTodayCache(sn, today, { total: 0, items: [] })
|
||||
return
|
||||
}
|
||||
const total = Number(day.totalMs) || 0
|
||||
const colors = ['#07C160', '#5B8DEF', '#F5A623']
|
||||
const items: UsageItem[] = (day.apps || []).slice(0, 3).map((app, index) => ({
|
||||
@@ -344,7 +355,13 @@ Page({
|
||||
})
|
||||
saveUsageTodayCache(sn, today, { total, items })
|
||||
} catch {
|
||||
this.setData({ usageTotal: '—', usageRingPercent: 0, usageItems: [] })
|
||||
// 请求失败结束骨架,避免一直显示占位
|
||||
this.setData({
|
||||
usageTotal: cached ? this.data.usageTotal : '0s',
|
||||
usageRingPercent: cached ? this.data.usageRingPercent : 0,
|
||||
usageItems: cached ? this.data.usageItems : [],
|
||||
usageLoading: false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -224,7 +224,9 @@
|
||||
.usage-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 16rpx;
|
||||
/* 固定行高:骨架与真实数据三行的纵向位置保持一致 */
|
||||
height: 40rpx;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.usage-bar:last-child {
|
||||
@@ -321,7 +323,7 @@
|
||||
|
||||
.usage-skeleton-label {
|
||||
width: 132rpx;
|
||||
height: 20rpx;
|
||||
height: 24rpx;
|
||||
flex-shrink: 0;
|
||||
border-radius: 6rpx;
|
||||
background: var(--track);
|
||||
|
||||
Reference in new issue
Block a user