Commit b899c212 authored by 张宏's avatar 张宏

1

parent 2eaabcd0
...@@ -94,6 +94,7 @@ class _HomeViewState extends State<HomeView> with AutoRouteAwareStateMixin<HomeV ...@@ -94,6 +94,7 @@ class _HomeViewState extends State<HomeView> with AutoRouteAwareStateMixin<HomeV
blocks.addAll([ blocks.addAll([
SizedBox(height: 20.h), SizedBox(height: 20.h),
TemperatureBlock( TemperatureBlock(
alertId: alert.alertId,
temperatureAlarmTitle: alert.alertTitle, temperatureAlarmTitle: alert.alertTitle,
temperatureAlarmLocation: location, temperatureAlarmLocation: location,
currentTemperature: alert.temperature, currentTemperature: alert.temperature,
......
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_hotel_app/routes/app_router.gr.dart'; import 'package:smart_hotel_app/repositories/alert_detail_repository.dart';
import 'package:smart_hotel_app/services/alert_detail_service.dart';
class TemperatureBlock extends StatelessWidget { class TemperatureBlock extends StatelessWidget {
final int alertId;
final String temperatureAlarmTitle; final String temperatureAlarmTitle;
final String temperatureAlarmLocation; final String temperatureAlarmLocation;
final String currentTemperature; final String currentTemperature;
...@@ -11,9 +12,11 @@ class TemperatureBlock extends StatelessWidget { ...@@ -11,9 +12,11 @@ class TemperatureBlock extends StatelessWidget {
final String currentCurrent; final String currentCurrent;
final String waitTime; final String waitTime;
final String alarmLevel; final String alarmLevel;
final AlertDetailService? alertDetailService;
const TemperatureBlock({ const TemperatureBlock({
super.key, super.key,
required this.alertId,
required this.temperatureAlarmTitle, required this.temperatureAlarmTitle,
required this.temperatureAlarmLocation, required this.temperatureAlarmLocation,
required this.currentTemperature, required this.currentTemperature,
...@@ -21,6 +24,7 @@ class TemperatureBlock extends StatelessWidget { ...@@ -21,6 +24,7 @@ class TemperatureBlock extends StatelessWidget {
required this.currentCurrent, required this.currentCurrent,
required this.waitTime, required this.waitTime,
required this.alarmLevel, required this.alarmLevel,
this.alertDetailService,
}); });
@override @override
...@@ -78,10 +82,10 @@ class TemperatureBlock extends StatelessWidget { ...@@ -78,10 +82,10 @@ class TemperatureBlock extends StatelessWidget {
), ),
), ),
Text( Text(
'置顶', alarmLevel,
style: TextStyle( style: TextStyle(
fontSize: 24.sp, fontSize: 24.sp,
color: const Color.fromRGBO(255, 100, 101, 1.0), color: alarmLevel=="置顶" ? const Color.fromRGBO(255, 100, 101, 1.0) : const Color.fromRGBO(255, 204, 21, 1.0),
), ),
), ),
], ],
...@@ -102,7 +106,7 @@ class TemperatureBlock extends StatelessWidget { ...@@ -102,7 +106,7 @@ class TemperatureBlock extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text( Text(
'$currentTemperature°C', '$currentTemperature',
style: TextStyle( style: TextStyle(
fontSize: 40.sp, fontSize: 40.sp,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
...@@ -199,9 +203,7 @@ class TemperatureBlock extends StatelessWidget { ...@@ -199,9 +203,7 @@ class TemperatureBlock extends StatelessWidget {
], ],
), ),
GestureDetector( GestureDetector(
onTap: () { onTap: () => _showHandleDialog(context),
// context.pushRoute(const AbnormalDetailRoute());
},
child: Container( child: Container(
padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 20.h), padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 20.h),
decoration: BoxDecoration( decoration: BoxDecoration(
...@@ -223,4 +225,128 @@ class TemperatureBlock extends StatelessWidget { ...@@ -223,4 +225,128 @@ class TemperatureBlock extends StatelessWidget {
), ),
); );
} }
void _showHandleDialog(BuildContext context) {
showDialog(
context: context,
barrierDismissible: true,
builder: (dialogContext) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.r),
),
child: Container(
padding: EdgeInsets.all(24.w),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16.r),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
temperatureAlarmTitle,
style: TextStyle(
fontSize: 30.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
GestureDetector(
onTap: () => Navigator.of(dialogContext).pop(),
child: Icon(
Icons.close,
color: const Color.fromRGBO(100, 116, 139, 1.0),
size: 32.sp,
),
),
],
),
SizedBox(height: 16.h),
Container(
width: double.infinity,
padding: EdgeInsets.symmetric(
horizontal: 20.w,
vertical: 20.h,
),
decoration: BoxDecoration(
color: const Color.fromRGBO(242, 243, 245, 1),
borderRadius: BorderRadius.circular(12.r),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'解决办法:',
style: TextStyle(
fontSize: 26.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12.h),
Text(
'1.检查设备是否通风良好;\n2.确认设备负载是否正常;\n3.若异常,请联系电工。',
style: TextStyle(
fontSize: 26.sp,
color: const Color.fromRGBO(100, 116, 139, 1.0),
height: 1.5,
),
),
],
),
),
SizedBox(height: 20.h),
GestureDetector(
onTap: () {
Navigator.of(dialogContext).pop();
_handleAlert(context);
},
child: Container(
width: double.infinity,
height: 72.h,
decoration: BoxDecoration(
color: const Color.fromRGBO(66, 165, 245, 1.0),
borderRadius: BorderRadius.circular(12.r),
),
child: Center(
child: Text(
'确认',
style: TextStyle(
fontSize: 28.sp,
color: Colors.white,
),
),
),
),
),
],
),
),
);
},
);
}
Future<void> _handleAlert(BuildContext context) async {
try {
final service = alertDetailService ??
AlertDetailService(repository: AlertDetailRepository());
await service.handleAlert(alertId: alertId);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('操作成功')),
);
}
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('操作失败: $e')),
);
}
}
}
} }
\ No newline at end of file
...@@ -91,8 +91,7 @@ class VoltageOperateBlock extends StatelessWidget { ...@@ -91,8 +91,7 @@ class VoltageOperateBlock extends StatelessWidget {
voltageAlarmLevel, voltageAlarmLevel,
style: TextStyle( style: TextStyle(
fontSize: 24.sp, fontSize: 24.sp,
fontWeight: FontWeight.bold, color: voltageAlarmLevel=="置顶" ? const Color.fromRGBO(255, 100, 101, 1.0) : const Color.fromRGBO(255, 204, 21, 1.0),
color: const Color.fromRGBO(255, 204, 21, 1.0),
), ),
), ),
], ],
...@@ -188,7 +187,7 @@ class VoltageOperateBlock extends StatelessWidget { ...@@ -188,7 +187,7 @@ class VoltageOperateBlock extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
'电压波动告警', voltageAlarmTitle,
style: TextStyle( style: TextStyle(
fontSize: 30.sp, fontSize: 30.sp,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment