From b289211123705f31ca3c43eaedf0ed3c7b1254b4 Mon Sep 17 00:00:00 2001 From: wonder Date: Tue, 23 Dec 2025 17:23:45 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20=E6=95=B0=E6=8D=AE=E5=BA=93=E6=A8=A1?= =?UTF-8?q?=E6=8B=9F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/home/view/Module1.ets | 87 ++++++++++++++++++++---- 1 file changed, 75 insertions(+), 12 deletions(-) diff --git a/entry/src/main/ets/home/view/Module1.ets b/entry/src/main/ets/home/view/Module1.ets index c0aaf42..5759d5d 100644 --- a/entry/src/main/ets/home/view/Module1.ets +++ b/entry/src/main/ets/home/view/Module1.ets @@ -1,5 +1,68 @@ +// 健康数据结构体 +class HealthData { + caloriesCurrent: number = 0; + caloriesTarget: number = 0; + stepsCurrent: number = 0; + stepsTarget: number = 0; + intensityCurrent: number = 0; + intensityTarget: number = 0; + activityCount: number = 0; + sleepDuration: string = ''; + sleepQuality: string = ''; + heartRate: number = 0; + bloodOxygen: number = 0; + weight: number = 0; +} + +// 数据库配置接口 +interface DBConfig { + url: string; + user: string; + password: string; + database: string; +} + +// 数据库配置(需替换为实际信息) +const DB_CONFIG: DBConfig = { + url: 'YOUR_DATABASE_URL', + user: 'YOUR_USERNAME', + password: 'YOUR_PASSWORD', + database: 'YOUR_DB_NAME' +}; + @Component export struct Module1 { + @State healthData: HealthData = new HealthData(); + + aboutToAppear() { + this.loadHealthData(); + } + + // 模拟数据加载方法(需替换为实际数据库连接) + loadHealthData() { + // TODO: 实现真实数据库连接 + // 示例模拟数据 + this.healthData = { + caloriesCurrent: 117, + caloriesTarget: 500, + stepsCurrent: 1889, + stepsTarget: 8000, + intensityCurrent: 13, + intensityTarget: 30, + activityCount: 4, + sleepDuration: '8时27分', + sleepQuality: '良好', + heartRate: 96, + bloodOxygen: 97, + weight: 58.50 + }; + + // 真实数据加载示例伪代码: + // fetchDataFromDB().then(data => { + // this.healthData = data; + // }); + } + build() { Column() { Row() { @@ -11,14 +74,14 @@ export struct Module1 { .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#2E86C1') - Text('117') + Text(this.healthData.caloriesCurrent.toString()) .maxFontSize(20) .margin(2) .minFontSize(8) .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#3498DB') - Text('/500千卡') + Text(`/${this.healthData.caloriesTarget}千卡`) .maxFontSize(12) .fontColor('#888888') .margin(2) @@ -39,14 +102,14 @@ export struct Module1 { .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#28B463') - Text('1889') + Text(this.healthData.stepsCurrent.toString()) .maxFontSize(20) .margin(2) .minFontSize(8) .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#2ECC71') - Text('/8000步') + Text(`/${this.healthData.stepsTarget}步`) .maxFontSize(12) .fontColor('#888888') .margin(2) @@ -67,14 +130,14 @@ export struct Module1 { .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#7D3C98') - Text('13') + Text(this.healthData.intensityCurrent.toString()) .maxFontSize(20) .margin(2) .minFontSize(8) .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#9B59B6') - Text('/30分钟') + Text(`/${this.healthData.intensityTarget}分钟`) .maxFontSize(12) .fontColor('#888888') .margin(2) @@ -93,7 +156,7 @@ export struct Module1 { Row() { Column() { - Text('活动次数 4 次') + Text(`活动次数 ${this.healthData.activityCount} 次`) .maxFontSize(14) .margin(2) .minFontSize(8) @@ -113,14 +176,14 @@ export struct Module1 { .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#D35400') - Text('8时27分') + Text(this.healthData.sleepDuration) .maxFontSize(20) .margin(2) .minFontSize(8) .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#E67E22') - Text('12月23日 睡眠质量良好') + Text(`12月23日 睡眠质量${this.healthData.sleepQuality}`) .maxFontSize(12) .fontColor('#888888') .margin(2) @@ -154,7 +217,7 @@ export struct Module1 { .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#C0392B') - Text('96次/分') + Text(`${this.healthData.heartRate}次/分`) .maxFontSize(20) .margin(2) .minFontSize(8) @@ -188,7 +251,7 @@ export struct Module1 { .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#16A085') - Text('97%') + Text(`${this.healthData.bloodOxygen}%`) .maxFontSize(20) .margin(2) .minFontSize(8) @@ -222,7 +285,7 @@ export struct Module1 { .textOverflow({ overflow: TextOverflow.Ellipsis }) .maxLines(1) .fontColor('#8E44AD') - Text('58.50KG') + Text(`${this.healthData.weight.toFixed(2)}KG`) .maxFontSize(20) .margin(2) .minFontSize(8)