fix(usage): 首页使用时长应用行顶部对齐并固定三行高度
- usage-body 改 flex-start,应用行与左侧环形同高起排(单行不再居中) - 条列固定 3 行高度,不足 3 行补占位行,卡片高度与首行位置稳定
This commit is contained in:
1 parent
97d43583ae
commit
9f55e142fa
3 files changed
+24
-2
No files matched your search
+12
-1
@@ -121,6 +121,7 @@ Page({
|
||||
usageTotal: '—',
|
||||
usageRingPercent: 0,
|
||||
usageItems: [] as UsageItem[],
|
||||
placeholderCount: [1, 2, 3] as number[],
|
||||
usageLoading: true,
|
||||
deviceOps: [
|
||||
{ key: 'screenshot', emoji: '📸', color: '#07C160', label: '屏幕截图' },
|
||||
@@ -323,6 +324,7 @@ Page({
|
||||
usageTotal: formatUsageDuration(cached.total),
|
||||
usageRingPercent: cached.items.length ? cached.items[0].percent : 0,
|
||||
usageItems: cached.items,
|
||||
placeholderCount: placeholderRows(cached.items.length),
|
||||
usageLoading: false
|
||||
})
|
||||
}
|
||||
@@ -351,15 +353,18 @@ Page({
|
||||
usageTotal: formatUsageDuration(total),
|
||||
usageRingPercent: items.length ? items[0].percent : 0,
|
||||
usageItems: items,
|
||||
placeholderCount: placeholderRows(items.length),
|
||||
usageLoading: false
|
||||
})
|
||||
saveUsageTodayCache(sn, today, { total, items })
|
||||
} catch {
|
||||
// 请求失败结束骨架,避免一直显示占位
|
||||
const items = cached ? this.data.usageItems : []
|
||||
this.setData({
|
||||
usageTotal: cached ? this.data.usageTotal : '0s',
|
||||
usageRingPercent: cached ? this.data.usageRingPercent : 0,
|
||||
usageItems: cached ? this.data.usageItems : [],
|
||||
usageItems: items,
|
||||
placeholderCount: placeholderRows(items.length),
|
||||
usageLoading: false
|
||||
})
|
||||
}
|
||||
@@ -578,3 +583,9 @@ function dayKey(time: Date): string {
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${time.getFullYear()}-${pad(time.getMonth() + 1)}-${pad(time.getDate())}`
|
||||
}
|
||||
|
||||
/** 补足到 3 行所需的占位行数量 */
|
||||
function placeholderRows(count: number): number[] {
|
||||
const need = Math.max(0, 3 - count)
|
||||
return Array.from({ length: need }, (_, i) => i)
|
||||
}
|
||||
@@ -106,6 +106,8 @@
|
||||
<view class="usage-bar-fill" style="width: {{item.percent}}%; background: {{item.color}};"></view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 不足 3 行时补占位行,保证首行位置与卡片高度稳定 -->
|
||||
<view class="usage-bar-placeholder" wx:for="{{placeholderCount}}" wx:key="*this"></view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
+10
-1
@@ -174,7 +174,8 @@
|
||||
/* 使用时长 */
|
||||
.usage-body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
/* 顶部对齐:应用行与左侧环形同高起排,1 行时不垂直居中 */
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.usage-ring {
|
||||
@@ -219,6 +220,8 @@
|
||||
.usage-bars {
|
||||
flex: 1;
|
||||
margin-left: var(--gutter);
|
||||
/* 固定 3 行高度,应用数变化时卡片高度与首行位置不变 */
|
||||
height: 144rpx;
|
||||
}
|
||||
|
||||
.usage-bar {
|
||||
@@ -233,6 +236,12 @@
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* 不足 3 行时的占位行,保持首行位置一致 */
|
||||
.usage-bar-placeholder {
|
||||
height: 40rpx;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.usage-bar-label {
|
||||
flex-shrink: 0;
|
||||
width: 132rpx;
|
||||
|
||||
Reference in new issue
Block a user