468 lines
17 KiB
Dart
468 lines
17 KiB
Dart
// import 'package:ef/ef.dart';
|
||
// import 'package:flutter/material.dart';
|
||
// import 'package:flutter_svg/svg.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/StatusBarWithIndicator.dart';
|
||
// import 'package:EasyDartModule/EasyDartModule.dart' as es;
|
||
|
||
// class QcPiLaoZhiShuPercentWidget extends StatefulWidget {
|
||
// var reportData; // 改为更通用的名称
|
||
// QcPiLaoZhiShuPercentWidget({super.key, required this.reportData});
|
||
|
||
// @override
|
||
// State<QcPiLaoZhiShuPercentWidget> createState() =>
|
||
// _PiLaoZhiShuPercentWidgetState();
|
||
// }
|
||
|
||
// class _PiLaoZhiShuPercentWidgetState extends State<QcPiLaoZhiShuPercentWidget> {
|
||
// @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中获取plzs数据
|
||
// Map<String, dynamic> plzsData = widget.reportData['plzs'] ?? {};
|
||
// if (plzsData.isEmpty) {
|
||
// return Container();
|
||
// }
|
||
|
||
// int level = plzsData['level'] ?? 0;
|
||
|
||
// // 根据level值确定显示内容和颜色
|
||
// String levelText = '';
|
||
// Color levelColor = themeController.currentColor.sc3;
|
||
|
||
// switch (level) {
|
||
// case 0:
|
||
// levelText = '正常';
|
||
// levelColor = Colors.green;
|
||
// break;
|
||
// case 1:
|
||
// levelText = '轻度疲劳';
|
||
// levelColor = Colors.orange;
|
||
// break;
|
||
// case 2:
|
||
// levelText = '中度疲劳';
|
||
// levelColor = Colors.red;
|
||
// break;
|
||
// case 3:
|
||
// levelText = '重度疲劳';
|
||
// levelColor = Colors.red;
|
||
// break;
|
||
// default:
|
||
// levelText = '未知';
|
||
// levelColor = Colors.grey;
|
||
// }
|
||
|
||
// // 构建StatusBarWithIndicator需要的数据格式
|
||
// List<Map<String, dynamic>> showLabel = [
|
||
// {
|
||
// 'key': 0,
|
||
// 'name': '正常',
|
||
// 'color': Colors.green,
|
||
// },
|
||
// {
|
||
// 'key': 1,
|
||
// 'name': '轻度疲劳',
|
||
// 'color': Colors.orange,
|
||
// },
|
||
// {
|
||
// 'key': 2,
|
||
// 'name': '中度疲劳',
|
||
// 'color': Colors.red,
|
||
// },
|
||
// {
|
||
// 'key': 3,
|
||
// 'name': '重度疲劳',
|
||
// 'color': Colors.red,
|
||
// },
|
||
// ];
|
||
|
||
// 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, 45.rpx),
|
||
// child: Column(
|
||
// mainAxisSize: MainAxisSize.max,
|
||
// children: [
|
||
// Container(
|
||
// child: Row(
|
||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
// children: [
|
||
// Expanded(
|
||
// child: Text(
|
||
// "疲劳指数".tr,
|
||
// style: TextStyle(
|
||
// color: themeController.currentColor.sc3,
|
||
// fontSize: AppConstants().title_text_fontSize),
|
||
// maxLines: 1,
|
||
// overflow: TextOverflow.ellipsis,
|
||
// ),
|
||
// ),
|
||
// 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(
|
||
// "疲劳指数是评估人体疲劳程度的重要指标,反映身体和精神状态的疲劳水平。".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(
|
||
// "疲劳指数是评估人体疲劳程度的重要指标,反映身体和精神状态的疲劳水平。".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),
|
||
// width: 28.rpx,
|
||
// height: 28.rpx,
|
||
// child: SvgPicture.asset(
|
||
// 'assets/img/icon/explain.svg',
|
||
// fit: BoxFit.cover,
|
||
// color: themeController.currentColor.sc4,
|
||
// ),
|
||
// ),
|
||
// ),
|
||
// ],
|
||
// ),
|
||
// ),
|
||
// SizedBox(
|
||
// height: 83.rpx,
|
||
// ),
|
||
// // 显示level值的文本
|
||
// // Padding(
|
||
// // padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 0.rpx, 30.rpx, 30.rpx),
|
||
// // child: Row(
|
||
// // mainAxisAlignment: MainAxisAlignment.center,
|
||
// // children: [
|
||
// // Text(
|
||
// // '当前状态:',
|
||
// // style: TextStyle(
|
||
// // fontSize: 30.rpx,
|
||
// // color: themeController.currentColor.sc4,
|
||
// // ),
|
||
// // ),
|
||
// // Text(
|
||
// // levelText,
|
||
// // style: TextStyle(
|
||
// // fontSize: 36.rpx,
|
||
// // fontWeight: FontWeight.bold,
|
||
// // color: levelColor,
|
||
// // ),
|
||
// // ),
|
||
// // ],
|
||
// // ),
|
||
// // ),
|
||
// Padding(
|
||
// padding: EdgeInsetsDirectional.fromSTEB(
|
||
// 30.rpx, 0.rpx, 30.rpx, 0.rpx),
|
||
// child: StatusBarWithIndicator(
|
||
// selectKey: level, // 使用level值作为选中的key
|
||
// showLabel: showLabel,
|
||
// currentValueText: "当前属于".tr,
|
||
// showCurrentValue: true,
|
||
// ),
|
||
// ),
|
||
// SizedBox(
|
||
// height: 56.rpx,
|
||
// ),
|
||
// ],
|
||
// ),
|
||
// ),
|
||
// );
|
||
// } catch (e) {
|
||
// es.EasyDartModule.logger.error("疲劳指数绘制异常${e}");
|
||
// return Container();
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
|
||
import 'package:ef/ef.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_svg/svg.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/StatusBarWithIndicator.dart';
|
||
import 'package:EasyDartModule/EasyDartModule.dart' as es;
|
||
|
||
class QcPiLaoZhiShuPercentWidget extends StatefulWidget {
|
||
var reportData; // 改为更通用的名称
|
||
QcPiLaoZhiShuPercentWidget({super.key, required this.reportData});
|
||
|
||
@override
|
||
State<QcPiLaoZhiShuPercentWidget> createState() =>
|
||
_PiLaoZhiShuPercentWidgetState();
|
||
}
|
||
|
||
class _PiLaoZhiShuPercentWidgetState extends State<QcPiLaoZhiShuPercentWidget> {
|
||
@override
|
||
void setState(VoidCallback callback) {
|
||
super.setState(callback);
|
||
}
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
super.dispose();
|
||
}
|
||
|
||
// 辅助方法:将颜色字符串转换为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中获取plzs数据
|
||
Map<String, dynamic> plzsData = widget.reportData['plzs'] ?? {};
|
||
if (plzsData.isEmpty) {
|
||
return Container();
|
||
}
|
||
|
||
int level = plzsData['level'] ?? 0;
|
||
|
||
// 从reportData中获取type和zs数据
|
||
Map<String, dynamic> typeData = widget.reportData['type'] ?? {};
|
||
List<dynamic> zsList = typeData['zs'] ?? [];
|
||
|
||
// 构建StatusBarWithIndicator需要的数据格式
|
||
List<Map<String, dynamic>> showLabel = [];
|
||
|
||
if (zsList.isNotEmpty) {
|
||
// 从zs数据动态构建showLabel
|
||
showLabel = zsList.map((item) {
|
||
return {
|
||
'key': item['level'] ?? 0,
|
||
'name': item['name'] ?? '未知',
|
||
'color': _getColorFromString(item['color'] ?? ''),
|
||
};
|
||
}).toList();
|
||
|
||
// 按level排序,确保顺序正确
|
||
showLabel.sort((a, b) => (a['key'] as int).compareTo(b['key'] as int));
|
||
} else {
|
||
// 如果zs数据为空,使用默认数据作为后备方案
|
||
es.EasyDartModule.logger.warning("zs数据为空,使用默认配置");
|
||
showLabel = [
|
||
{
|
||
'key': 0,
|
||
'name': '正常',
|
||
'color': Colors.green,
|
||
},
|
||
{
|
||
'key': 1,
|
||
'name': '轻度疲劳',
|
||
'color': Colors.orange,
|
||
},
|
||
{
|
||
'key': 2,
|
||
'name': '中度疲劳',
|
||
'color': Colors.red,
|
||
},
|
||
{
|
||
'key': 3,
|
||
'name': '重度疲劳',
|
||
'color': Colors.red,
|
||
},
|
||
];
|
||
}
|
||
|
||
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, 45.rpx),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.max,
|
||
children: [
|
||
Container(
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Expanded(
|
||
child: Text(
|
||
"疲劳指数".tr,
|
||
style: TextStyle(
|
||
color: themeController.currentColor.sc3,
|
||
fontSize: AppConstants().title_text_fontSize),
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
),
|
||
),
|
||
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(
|
||
"疲劳指数是评估人体疲劳程度的重要指标,反映身体和精神状态的疲劳水平。".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(
|
||
"疲劳指数是评估人体疲劳程度的重要指标,反映身体和精神状态的疲劳水平。".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),
|
||
width: 28.rpx,
|
||
height: 28.rpx,
|
||
child: SvgPicture.asset(
|
||
'assets/img/icon/explain.svg',
|
||
fit: BoxFit.cover,
|
||
color: themeController.currentColor.sc4,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 83.rpx,
|
||
),
|
||
Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
30.rpx, 0.rpx, 30.rpx, 0.rpx),
|
||
child: StatusBarWithIndicator(
|
||
selectKey: level, // 使用level值作为选中的key
|
||
showLabel: showLabel,
|
||
currentValueText: "当前属于".tr,
|
||
showCurrentValue: true,
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 56.rpx,
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
} catch (e) {
|
||
es.EasyDartModule.logger.error("疲劳指数绘制异常${e}");
|
||
return Container();
|
||
}
|
||
}
|
||
} |