feat(ui): 统一实现卡片背景趋势与大数值布局

This commit is contained in:
2026-11-15 15:40:29 +08:00
parent 397156249b
commit 3c1a2baace
25 changed files with 447 additions and 268 deletions
@@ -6,50 +6,51 @@ extension MenuPanelView {
ResourceCard(
title: "metric.network", symbol: "network", color: Color("MetricNetwork"), value: "↓ " + MetricFormat.rate(total(\.download)),
secondaryValue: "↑ " + MetricFormat.rate(total(\.upload)), valueColor: Color("MetricMemory"),
secondaryValueColor: Color("SeriesUpload")
secondaryValueColor: Color("SeriesUpload"), headerAccessory: AnyView(networkInterfacePicker),
chart: {
PanelTrendChart(
dates: networkDates, first: networkDownloads, second: networkUploads, color: Color("MetricMemory"),
secondColor: Color("SeriesUpload"), fixedScale: nil, firstLabel: "network.download", secondLabel: "network.upload",
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: networkIntervals, visibleSeriesCount: 2
).id(selectedInterface)
}
) {
PanelTrendChart(
dates: networkDates, first: networkDownloads, second: networkUploads, color: Color("MetricMemory"),
secondColor: Color("SeriesUpload"), fixedScale: nil, firstLabel: "network.download", secondLabel: "network.upload",
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: networkIntervals, showsLegendValues: false
).id(selectedInterface)
CardSeparator()
HStack(alignment: .top, spacing: 8) {
HStack(spacing: 12) {
networkTotal(
"network.received", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.received }),
symbol: "arrow.down", color: Color("MetricMemory"))
Divider().frame(height: 32)
networkTotal(
"network.sent", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.sent }),
symbol: "arrow.up", color: Color("SeriesUpload"))
Divider().frame(height: 32)
VStack(alignment: .leading, spacing: 4) {
HStack(spacing: 4) {
Circle().fill(networkStatusColor).frame(width: 5, height: 5)
Picker("panel.interface", selection: $selectedInterface) {
Text("network.all").tag("")
ForEach(snapshot.network ?? [], id: \.identity) { item in
Text(verbatim: item.name).tag(item.identity)
}
}.labelsHidden().controlSize(.mini).fixedSize()
}
Text(networkStatusLabel).help(Text(networkStatusLabel))
}.frame(maxWidth: .infinity, alignment: .leading)
}.font(PanelStyle.label).lineLimit(1)
CardSeparator()
HStack(spacing: 8) {
}
VStack(spacing: 4) {
networkAddress("network.public", address: publicIPAddress)
Divider().frame(height: 15)
networkAddress(
"network.local",
address: addressInterface?.addresses.first(where: { !$0.contains(":") }) ?? addressInterface?.addresses.first)
}.font(PanelStyle.label)
.modifier(CardInset())
.accessibilityElement(children: .contain)
.accessibilityLabel(Text("network.addresses"))
}
.font(PanelStyle.label)
.accessibilityElement(children: .contain)
.accessibilityLabel(Text("network.addresses"))
}
.modifier(PanelPublicIPRefresh(metrics: metrics, address: $publicIPAddress))
}
private var networkInterfacePicker: some View {
HStack(spacing: 4) {
Circle().fill(networkStatusColor).frame(width: 5, height: 5)
Picker("panel.interface", selection: $selectedInterface) {
Text("network.all").tag("")
ForEach(snapshot.network ?? [], id: \.identity) { item in
Text(verbatim: item.name).tag(item.identity)
}
}.labelsHidden().controlSize(.mini).frame(maxWidth: 100)
}
.help(Text(networkStatusLabel))
.accessibilityElement(children: .contain)
.accessibilityValue(Text(networkStatusLabel))
}
func networkAddress(_ title: LocalizedStringKey, address: String?) -> some View {
HStack(spacing: 3) {
Text(title).foregroundStyle(.secondary)