refactor(ui): 统一资源卡片规范并收敛面板布局与公共组件
This commit is contained in:
@@ -4,65 +4,40 @@ 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)
|
||||
CardSeparator()
|
||||
CardSectionHeader(title: "disk.distribution", valueLabel: "disk.utilization",
|
||||
value: MetricFormat.percent(disk?.usage), color: color)
|
||||
.help(Text("disk.capacityScope"))
|
||||
CapacityBar(values: [Double(disk.map { $0.total - min($0.total, $0.available) } ?? 0), Double(disk?.available ?? 0)],
|
||||
colors: [color, Color("MemoryAvailable")], total: Double(disk?.total ?? 1))
|
||||
HStack(spacing: 4) {
|
||||
CapacityField(title: "disk.used", value: MetricFormat.bytes(disk.map { $0.total - min($0.total, $0.available) }), color: color)
|
||||
CapacityField(title: "memory.available", value: MetricFormat.bytes(disk?.available), color: Color("MemoryAvailable"))
|
||||
}
|
||||
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()
|
||||
CardSeparator()
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("disk.remainingLife").foregroundStyle(.secondary)
|
||||
CardField(title: "disk.remainingLife") {
|
||||
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)
|
||||
}
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "disk.powerOnHours") {
|
||||
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)
|
||||
}
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "disk.localVolumes") {
|
||||
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)
|
||||
}.padding(.top, 3)
|
||||
}
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
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