Feat: 实现随机心率
This commit is contained in:
@@ -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 {
|
class HealthData {
|
||||||
caloriesCurrent: number = 0;
|
caloriesCurrent: number = 0;
|
||||||
@@ -14,7 +32,7 @@ class HealthData {
|
|||||||
weight: number = 0;
|
weight: number = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数据库配置接口
|
|
||||||
interface DBConfig {
|
interface DBConfig {
|
||||||
url: string;
|
url: string;
|
||||||
user: string;
|
user: string;
|
||||||
@@ -22,7 +40,6 @@ interface DBConfig {
|
|||||||
database: string;
|
database: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数据库配置(需替换为实际信息)
|
|
||||||
const DB_CONFIG: DBConfig = {
|
const DB_CONFIG: DBConfig = {
|
||||||
url: 'YOUR_DATABASE_URL',
|
url: 'YOUR_DATABASE_URL',
|
||||||
user: 'YOUR_USERNAME',
|
user: 'YOUR_USERNAME',
|
||||||
@@ -36,12 +53,11 @@ export struct Module1 {
|
|||||||
|
|
||||||
aboutToAppear() {
|
aboutToAppear() {
|
||||||
this.loadHealthData();
|
this.loadHealthData();
|
||||||
|
this.healthData.heartRate = getRateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 模拟数据加载方法(需替换为实际数据库连接)
|
// 模拟数据加载方法(需替换为实际数据库连接)
|
||||||
loadHealthData() {
|
loadHealthData() {
|
||||||
// TODO: 实现真实数据库连接
|
|
||||||
// 示例模拟数据
|
|
||||||
this.healthData = {
|
this.healthData = {
|
||||||
caloriesCurrent: 117,
|
caloriesCurrent: 117,
|
||||||
caloriesTarget: 500,
|
caloriesTarget: 500,
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
"deliveryWithInstall": true,
|
"deliveryWithInstall": true,
|
||||||
"installationFree": false,
|
"installationFree": false,
|
||||||
"pages": "$profile:main_pages",
|
"pages": "$profile:main_pages",
|
||||||
|
"requestPermissions": [
|
||||||
|
{
|
||||||
|
"name": "ohos.permission.INTERNET"
|
||||||
|
}
|
||||||
|
],
|
||||||
"abilities": [
|
"abilities": [
|
||||||
{
|
{
|
||||||
"name": "EntryAbility",
|
"name": "EntryAbility",
|
||||||
|
|||||||
Reference in New Issue
Block a user