feat(storage): 按容量分布与设备状态重设计存储卡片
This commit is contained in:
@@ -315,14 +315,14 @@ struct MenuPanelView: View {
|
||||
ResourceCard(title: "metric.disk", symbol: "internaldrive", color: Color("MetricDisk"), value: snapshot.disk.map { String(format: "%.0f / %.0f GB", Double($0.total - min($0.total, $0.available)) / 1_000_000_000, Double($0.total) / 1_000_000_000) } ?? "--") {
|
||||
|
||||
|
||||
PanelTrendChart(dates: samples.map(\.date), first: samples.map(\.read), second: samples.map(\.write), color: Color("MetricDisk"), secondColor: Color("MetricNetwork"), fixedScale: nil, firstLabel: "disk.read", secondLabel: "disk.write", expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
Text("disk.physicalIO").foregroundStyle(.secondary)
|
||||
HStack { line("disk.read", MetricFormat.rate(snapshot.diskIO?.read)); line("disk.write", MetricFormat.rate(snapshot.diskIO?.written)) }
|
||||
HStack { line("disk.remainingLife", MetricFormat.percent(snapshot.diskHealth?.remainingLife)); line("disk.powerOnHours", snapshot.diskHealth?.powerOnHours.map { "\($0) h" } ?? "--") }
|
||||
|
||||
|
||||
Spacer(minLength: 0)
|
||||
Button("disk.volumes") { showVolumes.toggle() }.popover(isPresented: $showVolumes) {
|
||||
PanelTrendChart(dates: samples.map(\.date), first: samples.map(\.read), second: samples.map(\.write), color: Color("MetricDisk"), secondColor: Color("MetricNetwork"), fixedScale: nil, firstLabel: "disk.read", secondLabel: "disk.write", expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals, plotHeight: 48)
|
||||
Text("disk.physicalIO")
|
||||
.font(.system(size: 9)).foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
StorageDetailsView(disk: snapshot.disk, health: snapshot.diskHealth) {
|
||||
showVolumes.toggle()
|
||||
}
|
||||
.popover(isPresented: $showVolumes) {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("disk.homeVolume")
|
||||
Text("panel.smartScope").foregroundStyle(.secondary)
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import SwiftUI
|
||||
|
||||
struct StorageDetailsView: View {
|
||||
let disk: DiskMetrics?
|
||||
let health: DiskHealthMetrics?
|
||||
let showVolumes: () -> Void
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
private let color = Color("MetricDisk")
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Divider()
|
||||
HStack {
|
||||
Text("disk.distribution").fontWeight(.semibold).help(Text("disk.capacityScope"))
|
||||
Spacer()
|
||||
Text("disk.utilization").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: MetricFormat.percent(disk?.usage)).foregroundStyle(color)
|
||||
}
|
||||
GeometryReader { proxy in
|
||||
ZStack(alignment: .leading) {
|
||||
Rectangle().fill(Color("MemoryAvailable"))
|
||||
Rectangle().fill(color)
|
||||
.frame(width: proxy.size.width * CGFloat(disk?.usage ?? 0))
|
||||
}
|
||||
// Clip the whole track, with no minimum fill width for tiny values.
|
||||
.clipShape(Capsule())
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: disk?.usage)
|
||||
}.frame(height: 7).accessibilityHidden(true)
|
||||
HStack {
|
||||
capacity("disk.used", value: disk.map { $0.total - min($0.total, $0.available) }, tint: color)
|
||||
capacity("memory.available", value: disk?.available, tint: Color("MemoryAvailable"))
|
||||
}
|
||||
Divider()
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("disk.remainingLife").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: MetricFormat.percent(health?.remainingLife))
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Divider().frame(height: 30)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("disk.powerOnHours").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: health?.powerOnHours.map { "\($0) h" } ?? "--")
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Divider().frame(height: 30)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("disk.localVolumes").foregroundStyle(.secondary)
|
||||
Button(action: showVolumes) {
|
||||
HStack(spacing: 2) {
|
||||
Text("disk.viewDetails")
|
||||
Image(systemName: "chevron.right").font(.system(size: 8))
|
||||
}
|
||||
}.buttonStyle(.plain)
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
Text("disk.refreshNote").font(.system(size: 9)).foregroundStyle(.secondary)
|
||||
}.padding(.top, 3)
|
||||
}
|
||||
|
||||
private func capacity(_ title: LocalizedStringKey, value: UInt64?, tint: Color) -> some View {
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
HStack(spacing: 4) {
|
||||
Circle().fill(tint).frame(width: 4, height: 4)
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
}
|
||||
AnimatedMetricText(value: MetricFormat.bytes(value)).fontWeight(.medium)
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.font(.system(size: 10)).lineLimit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user