diff --git a/lib/main.dart b/lib/main.dart index 0d28e73..d49abc4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -31,13 +31,6 @@ void main() async { const isDev = const String.fromEnvironment('ENV', defaultValue: 'dev')=='dev'; DevUtil.setDev(isDev); - WebSocketUtil().initWebSocket( - // heartDuration: Duration(seconds: 5), - onError: (e) { - LoggerData.addData(e); - }, onReceiveMes: (message) async { - await FireDialog.fireAlert(message); - }); jpush.addEventHandler( // 接收通知回调方法。 onReceiveNotification: (Map? message) async { diff --git a/lib/ui/splash/splash_page.dart b/lib/ui/splash/splash_page.dart index 284e4de..05b39e4 100644 --- a/lib/ui/splash/splash_page.dart +++ b/lib/ui/splash/splash_page.dart @@ -125,7 +125,7 @@ class _SplashPageState extends State { WebSocketUtil().initWebSocket( consolePrint: false, onReceiveMes: (message) async { - await FireDialog.fireAlert(message); + await FireDialog.fireAlarm(message); }, onError: (e) { LoggerData.addData(e); diff --git a/lib/utils/jpush_message_parse.dart b/lib/utils/jpush_message_parse.dart index 67de7de..e185261 100644 --- a/lib/utils/jpush_message_parse.dart +++ b/lib/utils/jpush_message_parse.dart @@ -25,7 +25,7 @@ class JpushMessageParse { type = _innerMap['type'] ?? '0'; switch (type) { case '1': - await FireDialog.fireAlert(subTitle!); + await FireDialog.fireAlarm(subTitle!); break; default: } diff --git a/lib/utils/websocket/alarm_models/fall_model.dart b/lib/utils/websocket/alarm_models/fall_model.dart deleted file mode 100644 index 87b2cb5..0000000 --- a/lib/utils/websocket/alarm_models/fall_model.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; - -part 'fall_model.g.dart'; - -@JsonSerializable() -class FallModel { - final String? userName; - final String? tel; - final String? address; - final num? lon; - final num? lat; - final int? type; - factory FallModel.fromJson(Map json) => - _$FallModelFromJson(json); - - const FallModel({ - this.userName, - this.tel, - this.address, - this.lon, - this.lat, - this.type, - }); -} diff --git a/lib/utils/websocket/alarm_models/fall_model.g.dart b/lib/utils/websocket/alarm_models/fall_model.g.dart deleted file mode 100644 index 7af23b2..0000000 --- a/lib/utils/websocket/alarm_models/fall_model.g.dart +++ /dev/null @@ -1,16 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'fall_model.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -FallModel _$FallModelFromJson(Map json) => FallModel( - userName: json['userName'] as String?, - tel: json['tel'] as String?, - address: json['address'] as String?, - lon: json['lon'] as num?, - lat: json['lat'] as num?, - type: json['type'] as int?, - ); diff --git a/lib/utils/websocket/alarm_models/fire_model.dart b/lib/utils/websocket/alarm_models/fire_model.dart index 751b55c..cfe6362 100644 --- a/lib/utils/websocket/alarm_models/fire_model.dart +++ b/lib/utils/websocket/alarm_models/fire_model.dart @@ -1,25 +1,136 @@ import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; part 'fire_model.g.dart'; @JsonSerializable() -class FireModel { - String? alarmNo; - String? alarmType; - String? deviceName; - String? deviceNo; - String? time; - int? type; +class FireModel extends Equatable { + final String model; + final String communityCode; + final int type; + final FireAlarm? fireAlarm; + final DeviceAlarm? deviceAlarm; + final OneButtonAlarm? oneButtonAlarm; + final ClientAlarm? clientAlarm; + final ElderlyCareEquipmentReminder? elderlyCareEquipmentReminder; factory FireModel.fromJson(Map json) => _$FireModelFromJson(json); - FireModel({ - this.alarmNo, - this.alarmType, - this.deviceName, - this.deviceNo, - this.time, - this.type, + @override + List get props => [ + model, + communityCode, + type, + fireAlarm, + deviceAlarm, + oneButtonAlarm, + clientAlarm, + elderlyCareEquipmentReminder, + ]; + + const FireModel({ + required this.model, + required this.communityCode, + required this.type, + this.fireAlarm, + this.deviceAlarm, + this.oneButtonAlarm, + this.clientAlarm, + this.elderlyCareEquipmentReminder, + }); +} + +@JsonSerializable() +class FireAlarm extends Equatable { + final String time; + final String deviceName; + factory FireAlarm.fromJson(Map json) =>_$FireAlarmFromJson(json); + @override + List get props => [ + time, + deviceName, + ]; + + const FireAlarm({ + required this.time, + required this.deviceName, + }); +} + +@JsonSerializable() +class DeviceAlarm extends Equatable { + final String time; + final String deviceName; + factory DeviceAlarm.fromJson(Map json) =>_$DeviceAlarmFromJson(json); + @override + List get props => [ + time, + deviceName, + ]; + + const DeviceAlarm({ + required this.time, + required this.deviceName, + }); +} + +@JsonSerializable() +class OneButtonAlarm extends Equatable { + final String time; + final String roomName; + final String name; + final String tel; + factory OneButtonAlarm.fromJson(Map json) =>_$OneButtonAlarmFromJson(json); + @override + List get props => [ + time, + roomName, + name, + tel, + ]; + + const OneButtonAlarm({ + required this.time, + required this.roomName, + required this.name, + required this.tel, + }); +} + +@JsonSerializable() +class ClientAlarm extends Equatable { + final String time; + final String content; + factory ClientAlarm.fromJson(Map json) =>_$ClientAlarmFromJson(json); + @override + List get props => [ + time, + content, + ]; + + const ClientAlarm({ + required this.time, + required this.content, + }); +} + +@JsonSerializable() +class ElderlyCareEquipmentReminder extends Equatable { + final String deviceNo; + final int deviceType; + final String content; + factory ElderlyCareEquipmentReminder.fromJson(Map json) =>_$ElderlyCareEquipmentReminderFromJson(json); + @override + List get props => [ + deviceNo, + deviceType, + content, + ]; + + const ElderlyCareEquipmentReminder({ + required this.deviceNo, + required this.deviceType, + required this.content, }); } diff --git a/lib/utils/websocket/alarm_models/fire_model.g.dart b/lib/utils/websocket/alarm_models/fire_model.g.dart index 092a400..3900f80 100644 --- a/lib/utils/websocket/alarm_models/fire_model.g.dart +++ b/lib/utils/websocket/alarm_models/fire_model.g.dart @@ -7,10 +7,55 @@ part of 'fire_model.dart'; // ************************************************************************** FireModel _$FireModelFromJson(Map json) => FireModel( - alarmNo: json['alarmNo'] as String?, - alarmType: json['alarmType'] as String?, - deviceName: json['deviceName'] as String?, - deviceNo: json['deviceNo'] as String?, - time: json['time'] as String?, - type: json['type'] as int?, + model: json['model'] as String, + communityCode: json['communityCode'] as String, + type: json['type'] as int, + fireAlarm: json['fireAlarm'] == null + ? null + : FireAlarm.fromJson(json['fireAlarm'] as Map), + deviceAlarm: json['deviceAlarm'] == null + ? null + : DeviceAlarm.fromJson(json['deviceAlarm'] as Map), + oneButtonAlarm: json['oneButtonAlarm'] == null + ? null + : OneButtonAlarm.fromJson( + json['oneButtonAlarm'] as Map), + clientAlarm: json['clientAlarm'] == null + ? null + : ClientAlarm.fromJson(json['clientAlarm'] as Map), + elderlyCareEquipmentReminder: json['elderlyCareEquipmentReminder'] == null + ? null + : ElderlyCareEquipmentReminder.fromJson( + json['elderlyCareEquipmentReminder'] as Map), + ); + +FireAlarm _$FireAlarmFromJson(Map json) => FireAlarm( + time: json['time'] as String, + deviceName: json['deviceName'] as String, + ); + +DeviceAlarm _$DeviceAlarmFromJson(Map json) => DeviceAlarm( + time: json['time'] as String, + deviceName: json['deviceName'] as String, + ); + +OneButtonAlarm _$OneButtonAlarmFromJson(Map json) => + OneButtonAlarm( + time: json['time'] as String, + roomName: json['roomName'] as String, + name: json['name'] as String, + tel: json['tel'] as String, + ); + +ClientAlarm _$ClientAlarmFromJson(Map json) => ClientAlarm( + time: json['time'] as String, + content: json['content'] as String, + ); + +ElderlyCareEquipmentReminder _$ElderlyCareEquipmentReminderFromJson( + Map json) => + ElderlyCareEquipmentReminder( + deviceNo: json['deviceNo'] as String, + deviceType: json['deviceType'] as int, + content: json['content'] as String, ); diff --git a/lib/utils/websocket/fier_dialog.dart b/lib/utils/websocket/fier_dialog.dart index deffc26..5203dca 100644 --- a/lib/utils/websocket/fier_dialog.dart +++ b/lib/utils/websocket/fier_dialog.dart @@ -1,18 +1,23 @@ import 'dart:convert'; -import 'package:aku_new_community_manager/style/app_style.dart'; +import 'package:aku_new_community_manager/const/resource.dart'; +import 'package:aku_new_community_manager/new_ui/new_home/new_home_page.dart'; +import 'package:aku_new_community_manager/utils/dev_util.dart'; +import 'package:common_utils/common_utils.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:flutter_screenutil/src/size_extension.dart'; + import 'package:get/get.dart'; -import 'package:velocity_x/velocity_x.dart'; +import 'package:aku_new_community_manager/extensions/num_ext.dart'; +import 'package:power_logger/power_logger.dart'; -import 'alarm_models/fall_model.dart'; import 'alarm_models/fire_model.dart'; class FireDialog { - static Future fireAlert(String subTitle) async { - Map json = jsonDecode(subTitle); + static fireAlarm(String content) async { + LoggerData.addData(content); + var json = jsonDecode(content); int type = json['type'] as int; await Get.dialog( @@ -20,12 +25,11 @@ class FireDialog { title: getImage(type), content: Column( children: [ - 20.w.heightBox, Text( getTitle(type), style: TextStyle(color: Colors.black, fontSize: 34.sp), ), - 10.w.heightBox, + 10.hb, Text( getContent(json, type), style: TextStyle(color: Colors.black, fontSize: 26.sp), @@ -38,6 +42,13 @@ class FireDialog { child: Text('确认'), onPressed: () => Get.back(), ), + if (DevUtil.isDev) + CupertinoDialogAction( + child: Text('清除所有弹窗'), + onPressed: () => Get.offAll( + () => NewHomePage(), + ), + ), ], ), barrierDismissible: false, @@ -53,7 +64,7 @@ class FireDialog { case 3: return '管家端APP报警'; case 4: - return '跌倒报警'; + return '消息通知'; case 5: return 'SOS紧急联系报警'; default: @@ -61,28 +72,26 @@ class FireDialog { } } - static String getContent(Map json, int type) { + static String getContent(dynamic json, int type) { + var alarmModel = FireModel.fromJson(json); switch (type) { case 1: - var alarmModel = FireModel.fromJson(json); - return '于${alarmModel.time},${alarmModel.deviceName}附近出现了火灾报警,请各位业主、租户保持镇静,不要慌乱,有序开始撤离!'; + return '于${DateUtil.formatDateStr(alarmModel.fireAlarm!.time, format: DateFormats.zh_y_mo_d_h_m)},' + '${alarmModel.fireAlarm!.deviceName}附近出现了火灾报警,请各位业主、租户保持镇静,不要慌乱,有序开始撤离!'; case 2: - var alarmModel = FireModel.fromJson(json); - return '于${alarmModel.time},小区内有设备${alarmModel.deviceName}发生了报警,请物业负责人员尽快前往现场排查故障!'; + return '于${DateUtil.formatDateStr(alarmModel.deviceAlarm!.time, format: DateFormats.zh_y_mo_d_h_m)},' + '小区内有设备${alarmModel.deviceAlarm!.deviceName}发生了报警,请物业负责人员尽快前往现场排查故障!'; case 3: - var alarmModel = FireModel.fromJson(json); - return '注意:\n于${alarmModel.time},${alarmModel.deviceNo}${alarmModel.deviceName}' + - '在管家端app上点击了"一键报警",请尽快联系他沟通情况。\n' + - '${alarmModel.deviceName}联系方式:${alarmModel.alarmNo}\n' + - '如未能联系到${alarmModel.deviceName}。可择情报警'; + return '注意:\n于${DateUtil.formatDateStr(alarmModel.oneButtonAlarm!.time, format: DateFormats.zh_y_mo_d_h_m)}' + ',${alarmModel.oneButtonAlarm!.roomName} ${alarmModel.oneButtonAlarm!.name}在管家端app上点击了"一键报警",请尽快联系他沟通情况。\n' + '${alarmModel.oneButtonAlarm!.name}联系方式:${alarmModel.oneButtonAlarm!.tel}\n' + '如未能联系到${alarmModel.oneButtonAlarm!.name}。可择情报警'; case 4: - var alarmModel = FallModel.fromJson(json); - return '注意:\n\n有住户 ${alarmModel.userName} 发生跌倒情况,请及时上门或联系人员前往查看,住户联系方式:${alarmModel.tel}\n\n' + - '跌倒位置————\n${alarmModel.address},经度${alarmModel.lon},纬度${alarmModel.lat}\n\n如未能联系到住户,可择情报警'; + return '${DateUtil.formatDateStr(alarmModel.deviceAlarm!.time, format: DateFormats.zh_y_mo_d_h_m)}\n\n${alarmModel!.clientAlarm!.content}'; case 5: - var alarmModel = FallModel.fromJson(json); - return '注意:\n\n有住户 ${alarmModel.userName} 使用了SOS紧急联系报警,请及时上门或联系人员前往查看,住户联系方式:${alarmModel.tel}\n\n' + - '跌倒位置————\n${alarmModel.address},经度${alarmModel.lon},纬度${alarmModel.lat}\n\n如未能联系到住户,可择情报警'; + return '注意:\n\n有住户使用了SOS紧急联系报警,请及时上门或联系人员前往查看,设备号:${alarmModel!.elderlyCareEquipmentReminder!.deviceNo}' + '\n\n${alarmModel.elderlyCareEquipmentReminder!.content}'; + default: return ''; } @@ -126,10 +135,7 @@ class FireDialog { fit: BoxFit.fitHeight, ); default: - return SizedBox( - width: 110.w, - height: 110.w, - ); + return SizedBox(width: 110.w, height: 110.w); } } }