Feat: 实现随机心率

This commit is contained in:
2026-01-02 11:44:55 +08:00
parent 55ae41db38
commit b3e9214d75
2 changed files with 25 additions and 4 deletions
+20 -4
View File
@@ -1,3 +1,21 @@
import http from '@ohos.net.http';
//
// async function fetchHeartRateData(): Promise<number> {
// 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,
+5
View File
@@ -10,6 +10,11 @@
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"requestPermissions": [
{
"name": "ohos.permission.INTERNET"
}
],
"abilities": [
{
"name": "EntryAbility",