481 lines
18 KiB
Dart
481 lines
18 KiB
Dart
// import 'package:ef/ef.dart';
|
||
// import 'package:flutter/material.dart';
|
||
// import 'package:flutter_svg/svg.dart';
|
||
// import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||
// import 'package:vbvs_app/common/color/appConstants.dart';
|
||
// import 'package:vbvs_app/common/util/FitTool.dart';
|
||
// import 'package:vbvs_app/common/util/MyUtils.dart';
|
||
// import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||
// import 'package:vbvs_app/enum/APPPackageType.dart';
|
||
// import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
|
||
// import 'package:vbvs_app/pages/sleep_report/chart/FatigueCircleIndicator.dart';
|
||
// import 'package:EasyDartModule/EasyDartModule.dart' as es;
|
||
|
||
// class QcHeartHealthWidget extends StatefulWidget {
|
||
// var reportData; // 改为更通用的名称
|
||
// QcHeartHealthWidget({super.key, required this.reportData});
|
||
|
||
// @override
|
||
// State<QcHeartHealthWidget> createState() => _QcHeartHealthWidgetState();
|
||
// }
|
||
|
||
// class _QcHeartHealthWidgetState extends State<QcHeartHealthWidget> {
|
||
// @override
|
||
// void setState(VoidCallback callback) {
|
||
// super.setState(callback);
|
||
// }
|
||
|
||
// @override
|
||
// void initState() {
|
||
// super.initState();
|
||
// }
|
||
|
||
// @override
|
||
// void dispose() {
|
||
// super.dispose();
|
||
// }
|
||
|
||
// @override
|
||
// Widget build(BuildContext context) {
|
||
// try {
|
||
// if (widget.reportData == null) {
|
||
// return Container();
|
||
// }
|
||
|
||
// // 从reportData中获取xljk数据
|
||
// List xljkData = widget.reportData['xljk'] ?? [];
|
||
// if (xljkData.isEmpty) {
|
||
// return Container();
|
||
// }
|
||
|
||
// var showLabel = convertMentalHealthData(xljkData);
|
||
|
||
// // 如果没有有效数据,不显示组件
|
||
// if (showLabel.isEmpty) {
|
||
// return Container();
|
||
// }
|
||
|
||
// return Container(
|
||
// width: double.infinity,
|
||
// decoration: BoxDecoration(
|
||
// color: themeController.currentColor.sc5,
|
||
// borderRadius: BorderRadius.circular(
|
||
// AppConstants().normal_container_radius), // 你可以按需调整圆角半径
|
||
// ),
|
||
// child: Padding(
|
||
// padding:
|
||
// EdgeInsetsDirectional.fromSTEB(26.rpx, 29.rpx, 26.rpx, 0.rpx),
|
||
// child: Column(
|
||
// mainAxisSize: MainAxisSize.max,
|
||
// children: [
|
||
// Container(
|
||
// child: Row(
|
||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
// children: [
|
||
// Text(
|
||
// "心理健康评估".tr,
|
||
// style: TextStyle(
|
||
// color: themeController.currentColor.sc3,
|
||
// fontSize: AppConstants().title_text_fontSize),
|
||
// ),
|
||
// ClickableContainer(
|
||
// backgroundColor: Colors.transparent,
|
||
// highlightColor: Colors.white, // 或设置为你需要的水波纹颜色
|
||
// padding: EdgeInsetsDirectional.fromSTEB(
|
||
// 14.rpx, 10.rpx, 14.rpx, 10.rpx), //
|
||
// borderRadius: 0.rpx, // 圆形点击区域
|
||
// onTap: () {
|
||
// if (AppConstants().ent_type ==
|
||
// APPPackageType.MHT.code) {
|
||
// showTipDialog(
|
||
// context,
|
||
// Container(
|
||
// child: Text(
|
||
// "心率健康评估主要通过用户睡眠报告中的时间点、体征数据及HRV数据等信息,来判断其心理健康水平、疲劳程度。"
|
||
// .tr,
|
||
// style: TextStyle(
|
||
// fontSize: 26.rpx,
|
||
// color: Colors.black,
|
||
// ),
|
||
// ),
|
||
// ),
|
||
// backgroundColor: Color(0xFFFFFFFF),
|
||
// colors: [
|
||
// Color(0XFF1592AA),
|
||
// Color(0xFF0C83A7),
|
||
// Color(0xFF006FA3)
|
||
// ],
|
||
// );
|
||
// } else {
|
||
// showTipDialog(
|
||
// context,
|
||
// Container(
|
||
// child: Text(
|
||
// "心率健康评估主要通过用户睡眠报告中的时间点、体征数据及HRV数据等信息,来判断其心理健康水平、疲劳程度。"
|
||
// .tr,
|
||
// style: TextStyle(
|
||
// fontSize: 26.rpx,
|
||
// color: themeController.currentColor.sc3,
|
||
// ),
|
||
// ),
|
||
// ),
|
||
// backgroundColor: themeController.currentColor.sc17,
|
||
// colors: AppConstants().thNormalButton,
|
||
// );
|
||
// }
|
||
// },
|
||
// child: Container(
|
||
// padding: EdgeInsetsDirectional.fromSTEB(
|
||
// 0, 0.rpx, 0.rpx, 0), // 外部 padding 移到内部
|
||
// width: 28.rpx,
|
||
// height: 28.rpx,
|
||
// child: SvgPicture.asset(
|
||
// 'assets/img/icon/explain.svg',
|
||
// fit: BoxFit.cover,
|
||
// color: themeController.currentColor.sc4,
|
||
// ),
|
||
// ),
|
||
// ),
|
||
// ],
|
||
// ),
|
||
// ),
|
||
// SizedBox(
|
||
// height: 104.rpx,
|
||
// ),
|
||
// Padding(
|
||
// padding: EdgeInsetsDirectional.fromSTEB(
|
||
// 30.rpx, 0.rpx, 30.rpx, 0.rpx),
|
||
// child: Row(
|
||
// mainAxisAlignment: MainAxisAlignment.center,
|
||
// children: [
|
||
// if (showLabel.length > 0)
|
||
// Flexible(
|
||
// flex: 1,
|
||
// child: FatigueCircleIndicator(
|
||
// data: showLabel[0],
|
||
// ),
|
||
// ),
|
||
// if (showLabel.length > 1)
|
||
// Flexible(
|
||
// flex: 1,
|
||
// child: FatigueCircleIndicator(
|
||
// data: showLabel[1],
|
||
// ),
|
||
// ),
|
||
// ].divide(SizedBox(
|
||
// width: 110.rpx,
|
||
// )),
|
||
// ),
|
||
// ),
|
||
// SizedBox(
|
||
// height: 72.rpx,
|
||
// ),
|
||
// ],
|
||
// ),
|
||
// ),
|
||
// );
|
||
// } catch (e) {
|
||
// es.EasyDartModule.logger.error("心理健康绘制异常${e}");
|
||
// return Container();
|
||
// }
|
||
// }
|
||
|
||
// List<Map<String, dynamic>> convertMentalHealthData(List data) {
|
||
// return data.map<Map<String, dynamic>>((item) {
|
||
// final String? colorStr = item['color'];
|
||
// final int value = item['val'].toInt() ?? 0; // 注意这里从val取值
|
||
// final String explain =
|
||
// (item['tips'] != null && (item['tips'] as String).trim().isNotEmpty)
|
||
// ? item['tips']
|
||
// : '未知数据'.tr;
|
||
|
||
// // 根据value值确定level描述
|
||
// String level = '';
|
||
// if (value <= 30) {
|
||
// level = '较低';
|
||
// } else if (value <= 60) {
|
||
// level = '正常';
|
||
// } else if (value <= 80) {
|
||
// level = '偏高';
|
||
// } else {
|
||
// level = '严重';
|
||
// }
|
||
|
||
// return {
|
||
// 'name': item['name'] ?? '未知指标',
|
||
// 'color': colorStr != null && colorStr.isNotEmpty
|
||
// ? stringToColor(colorStr)
|
||
// : stringToColor("#00C1AA"), // 默认颜色
|
||
// 'percent': value,
|
||
// 'explain': level, // 使用计算出的level
|
||
// "bottomColor": stringToColor("#393D49"),
|
||
// };
|
||
// }).toList();
|
||
// }
|
||
// }
|
||
|
||
import 'package:ef/ef.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_svg/svg.dart';
|
||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||
import 'package:vbvs_app/enum/APPPackageType.dart';
|
||
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
|
||
import 'package:vbvs_app/pages/sleep_report/chart/FatigueCircleIndicator.dart';
|
||
import 'package:EasyDartModule/EasyDartModule.dart' as es;
|
||
|
||
class QcHeartHealthWidget extends StatefulWidget {
|
||
var reportData; // 改为更通用的名称
|
||
QcHeartHealthWidget({super.key, required this.reportData});
|
||
|
||
@override
|
||
State<QcHeartHealthWidget> createState() => _QcHeartHealthWidgetState();
|
||
}
|
||
|
||
class _QcHeartHealthWidgetState extends State<QcHeartHealthWidget> {
|
||
// 缓存xljk的配置数据,用于根据level获取对应的name
|
||
Map<int, String>? _xljkNameMap;
|
||
|
||
@override
|
||
void setState(VoidCallback callback) {
|
||
super.setState(callback);
|
||
}
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_initXljkConfig();
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
super.dispose();
|
||
}
|
||
|
||
// 初始化xljk配置映射
|
||
void _initXljkConfig() {
|
||
try {
|
||
if (widget.reportData == null) return;
|
||
|
||
Map<String, dynamic> typeData = widget.reportData['type'] ?? {};
|
||
List<dynamic> xljkConfigList = typeData['xljk'] ?? [];
|
||
|
||
if (xljkConfigList.isNotEmpty) {
|
||
_xljkNameMap = {};
|
||
for (var config in xljkConfigList) {
|
||
int level = config['level'] ?? 0;
|
||
_xljkNameMap![level] = config['name'] ?? '未知';
|
||
}
|
||
}
|
||
} catch (e) {
|
||
es.EasyDartModule.logger.error("初始化xljk配置异常:$e");
|
||
}
|
||
}
|
||
|
||
// 辅助方法:将颜色字符串转换为Color对象
|
||
Color _getColorFromString(String colorStr) {
|
||
try {
|
||
// 如果颜色字符串以#开头,直接使用
|
||
if (colorStr.startsWith('#')) {
|
||
return Color(int.parse('0xFF${colorStr.substring(1)}'));
|
||
}
|
||
// 如果是6位十六进制颜色码(不带#)
|
||
else if (colorStr.length == 6) {
|
||
return Color(int.parse('0xFF$colorStr'));
|
||
}
|
||
} catch (e) {
|
||
es.EasyDartModule.logger.error("颜色转换异常:$e");
|
||
}
|
||
// 默认返回主题色
|
||
return themeController.currentColor.sc3;
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
try {
|
||
if (widget.reportData == null) {
|
||
return Container();
|
||
}
|
||
|
||
// 从reportData中获取xljk数据(这是实际的心率健康数据)
|
||
List xljkData = widget.reportData['xljk'] ?? [];
|
||
if (xljkData.isEmpty) {
|
||
return Container();
|
||
}
|
||
|
||
var showLabel = convertMentalHealthData(xljkData);
|
||
|
||
// 如果没有有效数据,不显示组件
|
||
if (showLabel.isEmpty) {
|
||
return Container();
|
||
}
|
||
|
||
return Container(
|
||
width: double.infinity,
|
||
decoration: BoxDecoration(
|
||
color: themeController.currentColor.sc5,
|
||
borderRadius: BorderRadius.circular(
|
||
AppConstants().normal_container_radius), // 你可以按需调整圆角半径
|
||
),
|
||
child: Padding(
|
||
padding:
|
||
EdgeInsetsDirectional.fromSTEB(26.rpx, 29.rpx, 26.rpx, 0.rpx),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.max,
|
||
children: [
|
||
Container(
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
"心理健康评估".tr,
|
||
style: TextStyle(
|
||
color: themeController.currentColor.sc3,
|
||
fontSize: AppConstants().title_text_fontSize),
|
||
),
|
||
ClickableContainer(
|
||
backgroundColor: Colors.transparent,
|
||
highlightColor: Colors.white, // 或设置为你需要的水波纹颜色
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
14.rpx, 10.rpx, 14.rpx, 10.rpx), //
|
||
borderRadius: 0.rpx, // 圆形点击区域
|
||
onTap: () {
|
||
if (AppConstants().ent_type ==
|
||
APPPackageType.MHT.code) {
|
||
showTipDialog(
|
||
context,
|
||
Container(
|
||
child: Text(
|
||
"心率健康评估主要通过用户睡眠报告中的时间点、体征数据及HRV数据等信息,来判断其心理健康水平、疲劳程度。"
|
||
.tr,
|
||
style: TextStyle(
|
||
fontSize: 26.rpx,
|
||
color: Colors.black,
|
||
),
|
||
),
|
||
),
|
||
backgroundColor: Color(0xFFFFFFFF),
|
||
colors: [
|
||
Color(0XFF1592AA),
|
||
Color(0xFF0C83A7),
|
||
Color(0xFF006FA3)
|
||
],
|
||
);
|
||
} else {
|
||
showTipDialog(
|
||
context,
|
||
Container(
|
||
child: Text(
|
||
"心率健康评估主要通过用户睡眠报告中的时间点、体征数据及HRV数据等信息,来判断其心理健康水平、疲劳程度。"
|
||
.tr,
|
||
style: TextStyle(
|
||
fontSize: 26.rpx,
|
||
color: themeController.currentColor.sc3,
|
||
),
|
||
),
|
||
),
|
||
backgroundColor: themeController.currentColor.sc17,
|
||
colors: AppConstants().thNormalButton,
|
||
);
|
||
}
|
||
},
|
||
child: Container(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
0, 0.rpx, 0.rpx, 0), // 外部 padding 移到内部
|
||
width: 28.rpx,
|
||
height: 28.rpx,
|
||
child: SvgPicture.asset(
|
||
'assets/img/icon/explain.svg',
|
||
fit: BoxFit.cover,
|
||
color: themeController.currentColor.sc4,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 104.rpx,
|
||
),
|
||
Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
30.rpx, 0.rpx, 30.rpx, 0.rpx),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
if (showLabel.length > 0)
|
||
Flexible(
|
||
flex: 1,
|
||
child: FatigueCircleIndicator(
|
||
data: showLabel[0],
|
||
),
|
||
),
|
||
if (showLabel.length > 1)
|
||
Flexible(
|
||
flex: 1,
|
||
child: FatigueCircleIndicator(
|
||
data: showLabel[1],
|
||
),
|
||
),
|
||
].divide(SizedBox(
|
||
width: 110.rpx,
|
||
)),
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 72.rpx,
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
} catch (e) {
|
||
es.EasyDartModule.logger.error("心理健康绘制异常${e}");
|
||
return Container();
|
||
}
|
||
}
|
||
|
||
List<Map<String, dynamic>> convertMentalHealthData(List data) {
|
||
return data.map<Map<String, dynamic>>((item) {
|
||
final String? colorStr = item['color'];
|
||
final int value = item['val']?.toInt() ?? 0;
|
||
final int level = item['level'] ?? 0; // 获取level值
|
||
final String explain =
|
||
(item['tips'] != null && (item['tips'] as String).trim().isNotEmpty)
|
||
? item['tips']
|
||
: '未知数据'.tr;
|
||
|
||
// 从配置映射中获取对应的name,如果没有则使用默认级别描述
|
||
String levelName;
|
||
if (_xljkNameMap != null && _xljkNameMap!.containsKey(level)) {
|
||
levelName = _xljkNameMap![level]!;
|
||
} else {
|
||
// 默认级别判断逻辑
|
||
if (value <= 30) {
|
||
levelName = '较低';
|
||
} else if (value <= 60) {
|
||
levelName = '正常';
|
||
} else if (value <= 80) {
|
||
levelName = '偏高';
|
||
} else {
|
||
levelName = '严重';
|
||
}
|
||
}
|
||
|
||
return {
|
||
'name': item['name'] ?? '未知指标',
|
||
'color': colorStr != null && colorStr.isNotEmpty
|
||
? _getColorFromString(colorStr)
|
||
: _getColorFromString("#00C1AA"), // 默认颜色
|
||
'percent': value,
|
||
'explain': levelName, // 使用从配置获取的levelName或默认级别
|
||
'level': level, // 保留level信息
|
||
"bottomColor": _getColorFromString("#393D49"),
|
||
};
|
||
}).toList();
|
||
}
|
||
}
|