Feat: 数据库模拟数据
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user