1.设备时区转化

2.消息列表优化
This commit is contained in:
sky_min 2025-11-05 17:57:56 +08:00
parent 94ef56d38b
commit e1c1ee0d38
8 changed files with 487 additions and 120 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -153,4 +153,5 @@ class AppColors {
static Color get lockDetailBottomBtnUneable =>
const Color(0xFF808080); // ()
static Color messageTipsColor = const Color.fromRGBO(202, 220, 247, 1); //
}

View File

@ -153,7 +153,9 @@ class _BasicInformationPageState extends State<BasicInformationPage> {
visible: state.lockSetInfoData.value.lockFeature?.wifi == 1,
child: CommonItem(
leftTitel: '设备时区'.tr,
rightTitle: state.lockSetInfoData.value.lockBasicInfo?.timezoneName ?? '-',
rightTitle: _formatTimezoneName(
state.lockSetInfoData.value.lockBasicInfo?.timezoneName
),
allHeight: 70.h,
isHaveLine: true,
),
@ -244,4 +246,37 @@ class _BasicInformationPageState extends State<BasicInformationPage> {
// 线: percentage = (rssi + 100) * 100 / 70
return ((clampedRssi + 100) * 100 ~/ 70).clamp(0, 100);
}
String _formatTimezoneName(String? timezone) {
if (timezone == null || timezone.isEmpty) return '-';
//
final Map<String, String> timezoneMap = {
'Antarctica/Casey': '南极凯西站 (UTC+8)',
'Asia/Shanghai': '中国上海 (UTC+8)',
'America/New_York': '美国纽约 (UTC-5/-4)',
'Asia/Tokyo': '日本东京 (UTC+9)',
'Europe/London': '英国伦敦 (UTC+0/+1)',
'Europe/Paris': '法国巴黎 (UTC+1/+2)',
'America/Los_Angeles': '美国洛杉矶 (UTC-8/-7)',
'America/Chicago': '美国芝加哥 (UTC-6/-5)',
'Asia/Hong_Kong': '中国香港 (UTC+8)',
'Asia/Singapore': '新加坡 (UTC+8)',
'Australia/Sydney': '澳大利亚悉尼 (UTC+10/+11)',
'Pacific/Auckland': '新西兰奥克兰 (UTC+12/+13)',
'Asia/Dubai': '阿联酋迪拜 (UTC+4)',
'Asia/Kolkata': '印度孟买 (UTC+5:30)',
'America/Sao_Paulo': '巴西圣保罗 (UTC-3)',
'Africa/Johannesburg': '南非约翰内斯堡 (UTC+2)',
'Asia/Seoul': '韩国首尔 (UTC+9)',
'Asia/Bangkok': '泰国曼谷 (UTC+7)',
'Europe/Moscow': '俄罗斯莫斯科 (UTC+3)',
'America/Toronto': '加拿大 Toronto (UTC-5/-4)',
'America/Mexico_City': '墨西哥城 (UTC-6/-5)',
'Asia/Jakarta': '印尼雅加达 (UTC+7)',
'Europe/Berlin': '德国柏林 (UTC+1/+2)',
'Asia/Taipei': '中国台湾 (UTC+8)',
'Australia/Melbourne': '澳大利亚墨尔本 (UTC+10/+11)',
};
return timezoneMap[timezone] ?? timezone;
}
}

View File

@ -29,6 +29,38 @@ class _MessageListPageState extends State<MessageListPage>
final MessageListLogic logic = Get.put(MessageListLogic());
final MessageListState state = Get.find<MessageListLogic>().state;
// _showCheckboxes
final RxBool _showCheckboxes = false.obs;
//
final RxList<bool> _selectedItems = <bool>[].obs;
//
bool showNotificationBanner = true;
//
final RxBool _pushNotificationEnabled = false.obs;
//
void deleteSelectedMessages() {
final List<MessageItemEntity> selectedMessages = [];
for (int i = 0; i < state.itemDataList.value.length; i++) {
if (_selectedItems[i]) {
selectedMessages.add(state.itemDataList.value[i]);
}
}
//
//logic.deletMessageDataRequest(selectedMessages);
//
_selectedItems.clear();
_selectedItems.addAll(
List.generate(state.itemDataList.value.length, (index) => false));
_showCheckboxes.value = false;
setState(() {});
}
void getHttpData() {
logic.messageListDataRequest().then((MessageListEntity value) {
setState(() {});
@ -39,38 +71,60 @@ class _MessageListPageState extends State<MessageListPage>
void initState() {
super.initState();
//
_loadPushNotificationStatus();
getHttpData();
}
//
void _loadPushNotificationStatus() async {
final bool? enabled = await Storage.getBool('push_notification_enabled');
_pushNotificationEnabled.value = enabled ?? false;
}
//
Map<String, List<MessageItemEntity>> _groupMessagesByDate() {
Map<String, List<MessageItemEntity>> grouped = {};
state.itemDataList.forEach((item) {
String date = DateTool().dateToYMDString(item.createdAt!.toString());
if (!grouped.containsKey(date)) {
grouped[date] = [];
}
grouped[date]!.add(item);
});
return grouped;
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: widget.showAppBar
? TitleAppBar(
barTitle: '消息'.tr,
haveBack: true,
actionsList: <Widget>[
TextButton(
child: Text(
'清空'.tr,
style: TextStyle(color: Colors.white, fontSize: 24.sp),
),
onPressed: () async {
final bool? isDemoMode =
await Storage.getBool(ifIsDemoModeOrNot);
if (isDemoMode == false) {
ShowTipView().showIosTipWithContentDialog('是否清空?'.tr,
barTitle: '消息'.tr,
haveBack: true,
actionsList: <Widget>[
TextButton(
child: Text(
'清空'.tr,
style: TextStyle(color: Colors.white, fontSize: 24.sp),
),
onPressed: () async {
final bool? isDemoMode =
await Storage.getBool(ifIsDemoModeOrNot);
if (isDemoMode == false) {
ShowTipView().showIosTipWithContentDialog('是否清空?'.tr,
() async {
logic.deletAllMessageDataRequest();
});
} else {
logic.showToast('演示模式'.tr);
}
},
),
],
backgroundColor: AppColors.mainColor)
} else {
logic.showToast('演示模式'.tr);
}
},
),
],
backgroundColor: AppColors.mainColor)
: null,
body: EasyRefreshTool(onRefresh: () {
logic.pageNo = 1;
@ -80,116 +134,354 @@ class _MessageListPageState extends State<MessageListPage>
}, child: Obx(() {
return state.itemDataList.value.isEmpty
? NoData()
: SlidableAutoCloseBehavior(
: Stack(
children: [
Positioned(
top: 0,
left: 0,
right: 0,
child: Container(
height: showNotificationBanner ? 100 : 70,
child: Column(children: [
showNotificationBanner
? Container(
padding:
EdgeInsets.only(left: 10, right: 10),
color: AppColors.messageTipsColor,
height: 30,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text('开启消息通知开关,及时获取通知',
style: TextStyle(
color: Colors.black,
fontSize: 20.sp)),
Row(children: [
!_pushNotificationEnabled.value
? GestureDetector(child: Text('去开启',
style: TextStyle(
color: Colors.blue,
fontSize: 20.sp)),
onTap: (){
Get.toNamed(Routers.mineSetPage);
}) : SizedBox.shrink(),
SizedBox(width: 10),
InkWell(
child: Image.asset(
'images/mine/icon_message_close.png',
width: 24.w,
height: 24.w),
onTap: () {
//
setState(() {
showNotificationBanner =
false;
});
}),
])
]))
: SizedBox.shrink(),
Container(
padding:
EdgeInsets.only(left: 15.w, right: 24.w, top: 20.h),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text('告警',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 30.sp)),
//
// GestureDetector(
// onTap: () {
// // api接口使
// // if (_showCheckboxes.value) {
// // deleteSelectedMessages();
// // } else {
// // setState(() {
// // _showCheckboxes.value =
// // !_showCheckboxes.value;
// // });
// // }
// },
// child: _showCheckboxes.value
// ? Text('删除',
// style: TextStyle(
// fontSize: 24.sp,
// color: Colors.red))
// : Image.asset(
// 'images/mine/icon_message_checbox.png',
// width: 30.w,
// height: 30.h),
// )
]),
)
]))),
Container(
child: Container(
padding: EdgeInsets.only(
top: showNotificationBanner ? 80 : 50),
child: ListView.builder(
itemCount: state.itemDataList.value.length,
itemBuilder: (BuildContext c, int index) {
final MessageItemEntity messageItemEntity =
state.itemDataList.value[index];
return Slidable(
key: ValueKey(messageItemEntity.id),
endActionPane: ActionPane(
extentRatio: 0.2,
motion: const ScrollMotion(),
children: <Widget>[
SlidableAction(
onPressed: (BuildContext context) {
logic.deletMessageDataRequest(
messageItemEntity.id!, () {
logic.pageNo = 1;
getHttpData();
});
},
backgroundColor: Colors.red,
foregroundColor: Colors.white,
label: '删除'.tr,
padding: EdgeInsets.only(left: 5.w, right: 5.w),
),
],
itemCount: _buildGroupedListItems().length,
itemBuilder: (BuildContext context, int index) {
var item = _buildGroupedListItems()[index];
if (item is String) {
//
return Container(
padding: EdgeInsets.symmetric(
horizontal: 16.w, vertical: 10.h),
color: AppColors.mainBackgroundColor,
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: item.substring(8, 10),
style: TextStyle(
color: Colors.black,
fontSize: 36.sp,
fontWeight: FontWeight.w600,
),
),
TextSpan(
text: ' ',
),
TextSpan(
text: item.substring(5, 7),
style: TextStyle(
color: Colors.grey, fontSize: 20.sp, fontWeight: FontWeight.w400),
),
],
),
),
child: _messageListItem(messageItemEntity, () {
Get.toNamed(Routers.messageDetailPage,
arguments: <String, MessageItemEntity>{
'messageItemEntity': messageItemEntity
});
}),
);
}),
);
} else if (item is MessageItemEntity) {
//
return _messageListItem(item, () {
Get.toNamed(Routers.messageDetailPage,
arguments: <String, MessageItemEntity>{
'messageItemEntity': item
});
});
}
return Container();
},
),
),
)
],
);
})),
);
}
//
List<dynamic> _buildGroupedListItems() {
List<dynamic> items = [];
Map<String, List<MessageItemEntity>> grouped = _groupMessagesByDate();
grouped.forEach((date, messages) {
items.add(date); //
items.addAll(messages.map((message) => message)); //
});
//
if (_selectedItems.length != state.itemDataList.value.length) {
_selectedItems.clear();
_selectedItems.addAll(
List.generate(state.itemDataList.value.length, (index) => false));
}
return items;
}
Widget _messageListItem(
MessageItemEntity messageItemEntity, Function() action) {
final int index = state.itemDataList.value.indexOf(messageItemEntity);
//
Map<String, List<MessageItemEntity>> grouped = _groupMessagesByDate();
bool isLastInGroupSimple = false;
//
for (var entry in grouped.entries) {
int messageIndex = entry.value.indexWhere((msg) => msg.id == messageItemEntity.id);
if (messageIndex != -1) {
//
isLastInGroupSimple = messageIndex == entry.value.length - 1;
break;
}
}
return GestureDetector(
onTap: action,
child: Container(
height: 90.h,
width: 1.sw,
margin: EdgeInsets.only(bottom: 2.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.w),
),
child: Container(
width: 1.sw,
margin: EdgeInsets.only(left: 20.w, right: 20.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
children: <Widget>[
if (messageItemEntity.readAt! == 0)
onTap: () {
//
if (_showCheckboxes.value) {
_selectedItems[index] = !_selectedItems[index];
setState(() {});
} else {
//
action();
}
},
child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
Container(
padding: EdgeInsets.only(left: 10),
transform: Matrix4.translationValues(0, 20, 0),
child: Column(
children: [
Image.asset(
messageItemEntity.readAt! == 0
? 'images/mine/icon_message_unread.png'
: 'images/mine/icon_message_readed.png',
width: 18.w,
height: 18.h),
// 线
if (!isLastInGroupSimple)
Container(
width: 10.w,
height: 10.w,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(5.w),
),
width: 0.5,
height: 190.h,
color: AppColors.placeholderTextColor,
)
else
Container(),
if (messageItemEntity.readAt! == 0)
SizedBox(width: 5.w)
else
Container(),
Flexible(
child: Text(
messageItemEntity.data!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 22.sp,
color: messageItemEntity.readAt! == 0
? AppColors.blackColor
: AppColors.placeholderTextColor),
),
],
)),
Expanded(
child: Slidable(
key: Key(messageItemEntity.id.toString()), // item添加唯一key
endActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (context) {
//
logic.deletMessageDataRequest(
messageItemEntity.id!, () {
logic.pageNo = 1;
getHttpData();
});
},
backgroundColor: Colors.red,
foregroundColor: Colors.white,
icon: Icons.delete,
label: '删除',
),
],
), child: Container(
width: 1.sw,
margin: EdgeInsets.all(20.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.w),
),
],
),
SizedBox(height: 10.h),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
// Image.asset('images/mine/icon_mine_gatewaySignal_strong.png', width: 40.w, height: 40.w,),
// SizedBox(width: 10.w,),
Text(
DateTool().dateToYMDHNString(
messageItemEntity.createdAt!.toString()),
style: TextStyle(
fontSize: 18.sp,
color: messageItemEntity.readAt! == 0
? AppColors.blackColor
: AppColors.placeholderTextColor)),
],
),
SizedBox(width: 20.h),
],
),
),
),
);
child: Container(
width: 1.sw,
margin: EdgeInsets.only(left: 20.w, right: 20.w, top: 8.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// SizedBox(height: 4.h),
// Row(
// children: <Widget>[
// Flexible(
// child: Text(
// //
// '远程开门请求',
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: TextStyle(
// fontSize: 22.sp,
// color: messageItemEntity.readAt! == 0
// ? AppColors.blackColor
// : AppColors.placeholderTextColor),
// ),
// ),
// ],
// ),
// SizedBox(height: 4.h),
Wrap(
children: <Widget>[
// if (messageItemEntity.readAt! == 0)
// Container(
// width: 10.w,
// height: 10.w,
// decoration: BoxDecoration(
// color: Colors.red,
// borderRadius: BorderRadius.circular(5.w),
// ),
// )
// else
// Container(),
// if (messageItemEntity.readAt! == 0)
// SizedBox(width: 5.w)
// else
// Container(),
Container(
margin: EdgeInsets.only(top: 4.h),
child: Text(
DateTool().dateToHnString(messageItemEntity.createdAt!.toString()),
style: TextStyle(
fontSize: 20.sp,
color: messageItemEntity.readAt! == 0
? AppColors.blackColor
: AppColors.placeholderTextColor,
),
),
),
Container(
width: 1,
height: 10,
margin: EdgeInsets.only(left: 5.w, right: 5.w, top: 10.h),
color: messageItemEntity.readAt! == 0
? AppColors.blackColor
: AppColors.placeholderTextColor,
),
Container(transform: Matrix4.translationValues(0, -18, 0),
child: Text(' ${messageItemEntity.data!}',
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 20.sp,
color: messageItemEntity.readAt! == 0
? AppColors.blackColor
: AppColors.placeholderTextColor,
),
)),
Container(transform: Matrix4.translationValues(0, -8, 0), child: GestureDetector(
child: Text('点击查看', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20.sp, color: AppColors.mainColor),),
),alignment: Alignment.centerRight,)
],
),
// SizedBox(height: 5.h),
// Row(
// mainAxisAlignment: MainAxisAlignment.start,
// children: <Widget>[
// // Image.asset('images/mine/icon_mine_gatewaySignal_strong.png', width: 40.w, height: 40.w,),
// // SizedBox(width: 10.w,),
// Text(
// DateTool().dateToHnString(messageItemEntity
// .createdAt!
// .toString()),
// style: TextStyle(
// fontSize: 18.sp,
// color: messageItemEntity.readAt! == 0
// ? AppColors.blackColor
// : AppColors.placeholderTextColor)),
// ],
// ),
// SizedBox(width: 20.h),
]))))),
//
if (_showCheckboxes.value)
Checkbox(
value: _selectedItems[index],
activeColor: Colors.blue,
onChanged: (val) {
_selectedItems[index] = val!;
setState(() {});
},
)
]));
}
}
}

View File

@ -259,4 +259,43 @@ class DateTool {
final int weekRound = int.parse(weekStr, radix: 2);
return weekRound;
}
///
String dateToMMString(String? timestamp) {
timestamp ??= '0';
int time = int.parse(timestamp);
if (timestamp.length == 10) {
time = time * 1000;
}
final DateTime nowDate = DateTime.fromMillisecondsSinceEpoch(time);
final String appointmentDate =
formatDate(nowDate, <String>[mm]);
return appointmentDate;
}
///
String dateToDDString(String? timestamp) {
timestamp ??= '0';
int time = int.parse(timestamp);
if (timestamp.length == 10) {
time = time * 1000;
}
final DateTime nowDate = DateTime.fromMillisecondsSinceEpoch(time);
final String appointmentDate =
formatDate(nowDate, <String>[dd]);
return appointmentDate;
}
///
String dateToHnString(String? timestamp) {
timestamp ??= '0';
int time = int.parse(timestamp);
if (timestamp.length == 10) {
time = time * 1000;
}
final DateTime nowDate = DateTime.fromMillisecondsSinceEpoch(time);
final String appointmentDate =
formatDate(nowDate, <String>[HH, ':', nn]);
return appointmentDate;
}
}