diff --git a/assets/icons/sos.png b/assets/icons/sos.png new file mode 100644 index 00000000..33569c78 Binary files /dev/null and b/assets/icons/sos.png differ diff --git a/lib/constants/api.dart b/lib/constants/api.dart index ffa98711..f5cba6bf 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -27,6 +27,12 @@ class API { static _Pay pay = _Pay(); static _House house = _House(); static _SarsApi sarsApi = _SarsApi(); + static _Bracelet bracelet = _Bracelet(); +} + +class _Bracelet { + ///爱牵挂手环数据 + String get data => '/user/aqg/getData'; } class _Login { diff --git a/lib/gen/assets.gen.dart b/lib/gen/assets.gen.dart index cee00ca0..4dc06765 100644 --- a/lib/gen/assets.gen.dart +++ b/lib/gen/assets.gen.dart @@ -730,6 +730,9 @@ class $AssetsIconsGen { AssetGenImage get shoppingMall => const AssetGenImage('assets/icons/shopping_mall.png'); + /// File path: assets/icons/sos.png + AssetGenImage get sos => const AssetGenImage('assets/icons/sos.png'); + /// File path: assets/icons/system_notice.png AssetGenImage get systemNotice => const AssetGenImage('assets/icons/system_notice.png'); diff --git a/lib/models/bracelet/bracelet_model.dart b/lib/models/bracelet/bracelet_model.dart new file mode 100644 index 00000000..f51660d2 --- /dev/null +++ b/lib/models/bracelet/bracelet_model.dart @@ -0,0 +1,48 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'bracelet_model.g.dart'; + +@JsonSerializable() +class BraceletModel { + final int sbp; + final int todaySteps; + final int bloodOxygen; + final int switchType; + final int dbp; + final int heartRate; + final int remainingPower; + final int detectionDays; + final int alarmNums; + final int fallNums; + + factory BraceletModel.fromJson(Map json) => + _$BraceletModelFromJson(json); + + String get switchTypeString { + switch (switchType) { + case 0: + return '开机'; + case 1: + return '关机'; + case 2: + return '开机'; + case 3: + return '低电通知'; + default: + return ''; + } + } + + const BraceletModel({ + required this.sbp, + required this.todaySteps, + required this.bloodOxygen, + required this.switchType, + required this.dbp, + required this.heartRate, + required this.remainingPower, + required this.detectionDays, + required this.alarmNums, + required this.fallNums, + }); +} diff --git a/lib/models/bracelet/bracelet_model.g.dart b/lib/models/bracelet/bracelet_model.g.dart new file mode 100644 index 00000000..c53c1495 --- /dev/null +++ b/lib/models/bracelet/bracelet_model.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'bracelet_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +BraceletModel _$BraceletModelFromJson(Map json) => + BraceletModel( + sbp: json['sbp'] as int, + todaySteps: json['todaySteps'] as int, + bloodOxygen: json['bloodOxygen'] as int, + switchType: json['switchType'] as int, + dbp: json['dbp'] as int, + heartRate: json['heartRate'] as int, + remainingPower: json['remainingPower'] as int, + detectionDays: json['detectionDays'] as int, + alarmNums: json['alarmNums'] as int, + fallNums: json['fallNums'] as int, + ); diff --git a/lib/pages/services/old_age/old_age_support_page_simple.dart b/lib/pages/services/old_age/old_age_support_page_simple.dart index c3fd6730..b5b5c071 100644 --- a/lib/pages/services/old_age/old_age_support_page_simple.dart +++ b/lib/pages/services/old_age/old_age_support_page_simple.dart @@ -1,6 +1,12 @@ +import 'package:aku_new_community/constants/api.dart'; import 'package:aku_new_community/gen/assets.gen.dart'; +import 'package:aku_new_community/models/bracelet/bracelet_model.dart'; +import 'package:aku_new_community/utils/network/net_util.dart'; import 'package:aku_new_community/widget/bee_divider.dart'; import 'package:aku_new_community/widget/bee_scaffold.dart'; +import 'package:bot_toast/bot_toast.dart'; +import 'package:dio/dio.dart'; +import 'package:flustars/flustars.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -15,6 +21,23 @@ class OldAgeSupportPageSimple extends StatefulWidget { } class _OldAgeSupportPageSimpleState extends State { + BraceletModel? _model; + DateTime? _date; + + @override + void initState() { + var cancel = BotToast.showLoading(); + getData(); + cancel(); + super.initState(); + } + + @override + void dispose() { + BotToast.closeAllLoading(); + super.dispose(); + } + @override Widget build(BuildContext context) { var open = Row( @@ -27,7 +50,7 @@ class _OldAgeSupportPageSimpleState extends State { color: Color(0xFF57DAD2), ), 4.w.widthBox, - '设备 已开机' + '设备 ${_model?.switchTypeString}' .text .size(26.sp) .lineHeight(1.2) @@ -50,35 +73,49 @@ class _OldAgeSupportPageSimpleState extends State { end: Alignment.bottomCenter, colors: [Colors.white, Color(0xFFC0E5DC).withOpacity(0.355)]), ), - child: ListView( - padding: EdgeInsets.symmetric(horizontal: 32.w), - children: [ - 550.w.heightBox, - open, - 16.w.heightBox, - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - '数据更新自 2022年1月1日 18:21:15' - .text - .size(22.sp) - .color(Colors.black.withOpacity(0.25)) - .make(), - 40.w.heightBox, - ], - ), - 40.w.heightBox, - overview(), - 24.w.heightBox, - statusCard(), - 40.w.heightBox, - bottomCard(), - ], - ), + child: _model == null + ? Container() + : ListView( + padding: EdgeInsets.symmetric(horizontal: 32.w), + children: [ + 550.w.heightBox, + open, + 16.w.heightBox, + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + '数据更新自 ${DateUtil.formatDate(_date!, format: DateFormats.full)}' + .text + .size(22.sp) + .color(Colors.black.withOpacity(0.25)) + .make(), + 40.w.heightBox, + ], + ), + 40.w.heightBox, + overview(), + 24.w.heightBox, + statusCard(), + 40.w.heightBox, + bottomCard(), + ], + ), ), ); } + Future getData() async { + Response base = + await NetUtil().dio!.get(API.bracelet.data, queryParameters: { + 'imei': 863204050238280, + }); + if (base.data != null) { + _model = BraceletModel.fromJson(base.data); + _date = DateTime.now(); + } + setState(() {}); + } + Container bottomCard() { var left = Column( children: [ @@ -204,7 +241,7 @@ class _OldAgeSupportPageSimpleState extends State { ], ), Spacer(), - '141' + '${_model?.heartRate}' .richText .withTextSpanChildren([ ' 次/分' @@ -248,7 +285,7 @@ class _OldAgeSupportPageSimpleState extends State { ], ), Spacer(), - '3' + '${_model?.fallNums}' .richText .withTextSpanChildren([ ' 次' @@ -292,7 +329,7 @@ class _OldAgeSupportPageSimpleState extends State { ], ), Spacer(), - '1042' + '${_model?.todaySteps}' .richText .withTextSpanChildren([ ' 步' @@ -332,7 +369,7 @@ class _OldAgeSupportPageSimpleState extends State { Spacer(), Row( children: [ - '98' + '${_model?.bloodOxygen}' .richText .withTextSpanChildren([ ' %' @@ -375,7 +412,7 @@ class _OldAgeSupportPageSimpleState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ '剩余电量'.text.size(28.sp).color(Colors.black.withOpacity(0.65)).make(), - '58' + '${_model?.remainingPower}' .richText .withTextSpanChildren([ ' %' @@ -401,7 +438,7 @@ class _OldAgeSupportPageSimpleState extends State { .size(28.sp) .color(Colors.black.withOpacity(0.45)) .make(), - '58' + '${_model?.detectionDays}' .richText .withTextSpanChildren([ ' 天' @@ -427,7 +464,7 @@ class _OldAgeSupportPageSimpleState extends State { .size(28.sp) .color(Colors.black.withOpacity(0.45)) .make(), - '5' + '${_model?.alarmNums}' .richText .withTextSpanChildren([ ' 次' diff --git a/lib/utils/websocket/AlarmModel.dart b/lib/utils/websocket/AlarmModel.dart deleted file mode 100644 index 90fe198b..00000000 --- a/lib/utils/websocket/AlarmModel.dart +++ /dev/null @@ -1,36 +0,0 @@ -class AlarmModel { - String? alarmNo; - String? alarmType; - String? deviceName; - String? deviceNo; - String? time; - int? type; - - AlarmModel( - {this.alarmNo, - this.alarmType, - this.deviceName, - this.deviceNo, - this.time, - this.type}); - - AlarmModel.fromJson(Map json) { - alarmNo = json['alarmNo']; - alarmType = json['alarmType']; - deviceName = json['deviceName']; - deviceNo = json['deviceNo']; - time = json['time']; - type = json['type']; - } - - Map toJson() { - final Map data = new Map(); - data['alarmNo'] = this.alarmNo; - data['alarmType'] = this.alarmType; - data['deviceName'] = this.deviceName; - data['deviceNo'] = this.deviceNo; - data['time'] = this.time; - data['type'] = this.type; - return data; - } -} diff --git a/lib/utils/websocket/alarm_models/fall_model.dart b/lib/utils/websocket/alarm_models/fall_model.dart new file mode 100644 index 00000000..87b2cb5c --- /dev/null +++ b/lib/utils/websocket/alarm_models/fall_model.dart @@ -0,0 +1,24 @@ +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 new file mode 100644 index 00000000..7af23b29 --- /dev/null +++ b/lib/utils/websocket/alarm_models/fall_model.g.dart @@ -0,0 +1,16 @@ +// 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 new file mode 100644 index 00000000..751b55cc --- /dev/null +++ b/lib/utils/websocket/alarm_models/fire_model.dart @@ -0,0 +1,25 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'fire_model.g.dart'; + +@JsonSerializable() +class FireModel { + String? alarmNo; + String? alarmType; + String? deviceName; + String? deviceNo; + String? time; + int? type; + + factory FireModel.fromJson(Map json) => + _$FireModelFromJson(json); + + FireModel({ + this.alarmNo, + this.alarmType, + this.deviceName, + this.deviceNo, + this.time, + this.type, + }); +} diff --git a/lib/utils/websocket/alarm_models/fire_model.g.dart b/lib/utils/websocket/alarm_models/fire_model.g.dart new file mode 100644 index 00000000..092a4003 --- /dev/null +++ b/lib/utils/websocket/alarm_models/fire_model.g.dart @@ -0,0 +1,16 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'fire_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +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?, + ); diff --git a/lib/utils/websocket/fire_dialog.dart b/lib/utils/websocket/fire_dialog.dart index 39cce13e..8e04959e 100644 --- a/lib/utils/websocket/fire_dialog.dart +++ b/lib/utils/websocket/fire_dialog.dart @@ -1,29 +1,27 @@ import 'dart:convert'; -import 'package:aku_new_community/extensions/num_ext.dart'; +import 'package:aku_new_community/gen/assets.gen.dart'; import 'package:aku_new_community/pages/tab_navigator.dart'; import 'package:aku_new_community/utils/developer_util.dart'; import 'package:aku_new_community/utils/headers.dart'; +import 'package:aku_new_community/utils/websocket/alarm_models/fall_model.dart'; +import 'package:aku_new_community/utils/websocket/alarm_models/fire_model.dart'; import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; -import 'AlarmModel.dart'; - class FireDialog { static fireAlarm(String content) async { var json = jsonDecode(content); - AlarmModel alarmModel = AlarmModel.fromJson(json); + int type = json['type'] as int; await Get.dialog( CupertinoAlertDialog( - title: getImage(alarmModel), + title: getImage(type), content: Column( children: [ - Text(getTitle(alarmModel)), + Text(getTitle(type)), 10.hb, - Text(getContent(alarmModel)), + Text(getContent(json, type)), ], ), actions: [ @@ -44,37 +42,52 @@ class FireDialog { ); } - static String getTitle(AlarmModel alarmModel) { - switch (alarmModel.type) { + static String getTitle(int type) { + switch (type) { case 1: return '发现火灾!请立刻组织疏散人群!'; case 2: return '设备故障'; case 3: return '管家端APP报警'; + case 4: + return '跌倒报警'; + case 45: + return 'SOS紧急联系报警'; default: return ''; } } - static String getContent(AlarmModel alarmModel) { - switch (alarmModel.type) { + static String getContent(dynamic json, int type) { + switch (type) { case 1: + var alarmModel = FireModel.fromJson(json); return '于${alarmModel.time},${alarmModel.deviceName}附近出现了火灾报警,请各位业主、租户保持镇静,不要慌乱,有序开始撤离!'; case 2: + var alarmModel = FireModel.fromJson(json); return '于${alarmModel.time},小区内有设备${alarmModel.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}。可择情报警'; + 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如未能联系到住户,可择情报警'; + 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如未能联系到住户,可择情报警'; default: return ''; } } - static Widget getImage(AlarmModel alarmModel) { - switch (alarmModel.type) { + static Widget getImage(int type) { + switch (type) { case 1: return Image.asset( R.ASSETS_ICONS_FIRE_ALARM_PNG, @@ -96,8 +109,22 @@ class FireDialog { height: 110.w, fit: BoxFit.fill, ); + case 4: + return Image.asset( + R.ASSETS_ICONS_APP_ALARM_PNG, + width: 110.w, + height: 110.w, + fit: BoxFit.fill, + ); + case 5: + return Image.asset( + Assets.icons.sos.path, + width: 110.w, + height: 110.w, + fit: BoxFit.fill, + ); default: - return SizedBox(); + return SizedBox(width: 110.w, height: 110.w); } } } diff --git a/lib/utils/websocket/web_socket_util.dart b/lib/utils/websocket/web_socket_util.dart index fe5e00f4..e8892c37 100644 --- a/lib/utils/websocket/web_socket_util.dart +++ b/lib/utils/websocket/web_socket_util.dart @@ -6,7 +6,7 @@ import 'package:power_logger/power_logger.dart'; import 'package:web_socket_channel/io.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; -const String baseUri = 'wss://test.kaidalai.cn/websocket/app'; +const String baseUri = 'wss://shop.kaidalai.cn/websocket/app'; enum SOCKETSTATUS { CONNECTED, //已连接 BREAKOFF, //已断开