diff --git a/pages/home/index.ts b/pages/home/index.ts index 9090def..d7df42f 100644 --- a/pages/home/index.ts +++ b/pages/home/index.ts @@ -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 + }) } }, diff --git a/pages/home/index.wxss b/pages/home/index.wxss index efc79be..c85e022 100644 --- a/pages/home/index.wxss +++ b/pages/home/index.wxss @@ -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);