From b3e9214d75014b9a04bf0a513ab79d59607738df Mon Sep 17 00:00:00 2001 From: wonder Date: Fri, 2 Jan 2026 11:44:55 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20=E5=AE=9E=E7=8E=B0=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E5=BF=83=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/home/view/Module1.ets | 24 ++++++++++++++++++++---- entry/src/main/module.json5 | 5 +++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/entry/src/main/ets/home/view/Module1.ets b/entry/src/main/ets/home/view/Module1.ets index 5759d5d..8bf145a 100644 --- a/entry/src/main/ets/home/view/Module1.ets +++ b/entry/src/main/ets/home/view/Module1.ets @@ -1,3 +1,21 @@ +import http from '@ohos.net.http'; +// +// async function fetchHeartRateData(): Promise { +// const httpRequest = http.createHttp(); +// const url = 'https://uapis.cn/api/v1/misc/randomnumber?min=60&max=120&count=1'; +// +// const response = await httpRequest.request(url, { +// method: http.RequestMethod.GET +// }); +// +// const result = JSON.parse(response.result.toString()); +// return Number(result.numbers); +// } + +function getRateData(): number { + return Math.trunc(Math.random() * 60 + 60); +} + // 健康数据结构体 class HealthData { caloriesCurrent: number = 0; @@ -14,7 +32,7 @@ class HealthData { weight: number = 0; } -// 数据库配置接口 + interface DBConfig { url: string; user: string; @@ -22,7 +40,6 @@ interface DBConfig { database: string; } -// 数据库配置(需替换为实际信息) const DB_CONFIG: DBConfig = { url: 'YOUR_DATABASE_URL', user: 'YOUR_USERNAME', @@ -36,12 +53,11 @@ export struct Module1 { aboutToAppear() { this.loadHealthData(); + this.healthData.heartRate = getRateData(); } // 模拟数据加载方法(需替换为实际数据库连接) loadHealthData() { - // TODO: 实现真实数据库连接 - // 示例模拟数据 this.healthData = { caloriesCurrent: 117, caloriesTarget: 500, diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index 1ce402d..f1faee7 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -10,6 +10,11 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ], "abilities": [ { "name": "EntryAbility",