TodayDataView.swift
3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// TodayDataView.swift
// hippo-watch Watch App
//
// Created by shihao on 2025/7/7.
//
import Foundation
import SwiftUI
struct TodayDataView: View {
@ObservedObject private var dataManager = WatchDataManager.share
var body: some View {
ScrollView {
VStack(spacing: 0) {
// 顶部时间和标题
HStack(spacing: 2) {
Spacer()
Text("我的今日数据")
.font(.system(size: 17))
.foregroundColor(.white)
.padding(.horizontal, 8.x)
}
// 数据卡片列表
VStack(spacing: 4.x) {
// 平均HRV
DataCard(
icon: .todayDataHRV,
iconColor: .pink,
title: "平均HRV",
value: dataManager.myTodayAvgHRV.map {
$0.truncatingRemainder(dividingBy: 1) == 0 ? String(Int($0)) : String(format: "%.1f", $0)
} ?? "-",
unit: "ms"
)
// 最新心率
DataCard(
icon: .todayDataHR,
iconColor: .red,
title: "最新心率",
value: dataManager.myLatestHeartRate?.int.string ?? "-",
unit: "次/分"
)
// 步数
DataCard(
icon: .todayDataStep,
iconColor: .orange,
title: "步数",
value: dataManager.myTodayStepCount?.string ?? "-",
unit: "步"
)
// 活动记录
DataCard(
icon: .todayDataActivity,
iconColor: .orange,
title: "活动记录",
value: dataManager.myTodayActiveEnergy?.int.string ?? "-",
unit: "千卡"
)
}
.padding(.top, 14.x)
.padding(.horizontal, 8.x)
}
.background(Color.black)
}
.onAppear {
ThinkSDKUtil.track(eventName: "enter_doublefeel_watch_page",
properties: ["page_type": "今日数据"])
}
}
}
struct DataCard: View {
let icon: ImageResource
let iconColor: Color
let title: String
let value: String
let unit: String
var body: some View {
HStack(spacing: 0) {
// 左侧图标
Image(icon)
.foregroundColor(iconColor)
.font(.system(size: 14))
.frame(width: 20.x, height: 20.x)
// 标题
Text(title)
.font(.system(size: 14, weight: .semibold))
.foregroundColor(.white)
.padding(.leading, 4.x)
Spacer()
// 数值
Text(value)
.font(.system(size: 14, weight: .semibold))
.foregroundColor(.white)
Text(unit)
.font(.system(size: 12, weight: .regular))
.foregroundColor(.white.opacity(0.6))
.padding(.leading, 2.x)
.padding(.trailing, 8.x)
}
.padding(.leading, 8.x)
.padding(.vertical, 10.x)
.background(
RoundedRectangle(cornerRadius: 16.x)
.fill(Color.white.opacity(0.31))
)
}
}