From 58c6279b09bbc2b69dab59c1d91c4013e4c61660 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Thu, 10 Jun 2021 13:37:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=84=E8=AE=BA=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E8=AF=84=E5=88=86=E6=A0=B7=E5=BC=8F=20=E5=88=86?= =?UTF-8?q?=E7=A6=BB=20messageProvieder=20=E8=AF=84=E8=AE=BA=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=92=8C=E7=B3=BB=E7=BB=9F=E6=B6=88=E6=81=AF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=B7=B2=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/const/api.dart | 6 +++ lib/main.dart | 13 ++---- .../message/system_message_detail_model.dart | 15 ++++++ lib/provider/app_provider.dart | 17 +------ lib/provider/message_provider.dart | 46 +++++++++++++++++++ lib/provider/outdoor_provider.dart | 1 - lib/provider/user_provider.dart | 6 +-- lib/tools/user_tool.dart | 4 ++ lib/ui/home/home_page.dart | 6 ++- .../home/messages/comment_message_card.dart | 25 +++++++--- lib/ui/home/messages/message.dart | 38 ++++++++++----- lib/ui/home/messages/systen_message_card.dart | 2 +- 12 files changed, 129 insertions(+), 50 deletions(-) create mode 100644 lib/provider/message_provider.dart delete mode 100644 lib/provider/outdoor_provider.dart diff --git a/lib/const/api.dart b/lib/const/api.dart index 522ff41..86d285e 100644 --- a/lib/const/api.dart +++ b/lib/const/api.dart @@ -343,4 +343,10 @@ class _Message { ///消息中心:根据报事报修主键id 同步查询报事报修消息信息(同步) String get getSystemByDispatchId => '/user/message/findRepairByRepairId'; + + ///消息中心:评论消息全部已读(进入评论消息列表后调用) + String get allReadCommentMes => '/user/message/allReadComment'; + + ///消息中心:系统消息全部已读(进入系统消息列表后调用) + String get allReadSysMes => '/user/message/allReadSys'; } diff --git a/lib/main.dart b/lib/main.dart index b952ef0..c86c007 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,6 @@ // Flutter imports: +import 'package:aku_community_manager/provider/message_provider.dart'; +import 'package:aku_community_manager/tools/user_tool.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -30,8 +32,7 @@ void main() async { print("flutter onReceiveNotification: $message"); LoggerData.addData(message); await JpushMessageParse(message!).shot(); - final appProvider = Provider.of(Get.context!, listen: false); - appProvider.updateMessage(); + UserTool.messageProvider.updateMessage(); }, // 点击通知回调方法。 onOpenNotification: (Map? message) async { @@ -62,13 +63,7 @@ class MyApp extends StatelessWidget { providers: [ ChangeNotifierProvider(create: (context) => UserProvider()), ChangeNotifierProvider(create: (context) => AppProvider()), - // ChangeNotifierProvider(create: (context) => FixProvider()), - // ChangeNotifierProvider(create: (context) => GreenManageProvider()), - // ChangeNotifierProvider( - // create: (context) => InspectionManageProvider()), - // ChangeNotifierProvider(create: (context) => GreenManageProvider()), - // ChangeNotifierProvider( - // create: (context) => InspectionManageProvider()), + ChangeNotifierProvider(create: (context) => MessageProvider()), ], child: GestureDetector( onTap: () { diff --git a/lib/models/message/system_message_detail_model.dart b/lib/models/message/system_message_detail_model.dart index 812d21f..078fda3 100644 --- a/lib/models/message/system_message_detail_model.dart +++ b/lib/models/message/system_message_detail_model.dart @@ -21,4 +21,19 @@ class SystemMessageDetailModel { data['type'] = this.type; return data; } + String get sysMesTypeString { + switch (this.type) { + case 1: + return '报事报修'; + case 2: + return '装修'; + case 3: + return '绿化任务'; + case 4: + return '卫生任务'; + default: + return '未知'; + } + } } + diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index 78ecf45..1155195 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -5,12 +5,9 @@ import 'package:flutter/material.dart'; // Package imports: import 'package:amap_flutter_location/amap_flutter_location.dart'; import 'package:amap_flutter_location/amap_location_option.dart'; -import 'package:dio/dio.dart'; // Project imports: -import 'package:aku_community_manager/const/api.dart'; import 'package:aku_community_manager/ui/home/application/applications_page.dart'; -import 'package:aku_community_manager/utils/network/net_util.dart'; enum WORKCLOCK { ///未上班打卡状态 @@ -68,19 +65,7 @@ class AppProvider extends ChangeNotifier { _flutterLocation.destroy(); } - int _sysMessage = 0; - int _commentMessage = 0; - bool get hasMessage => _sysMessage != 0 || _commentMessage != 0; - int get sysMessage => _sysMessage; - int get commentMessage => _commentMessage; - - updateMessage() async { - Response response = await NetUtil().dio!.get(API.message.messageCenter); - if (response.data == null) return; - _sysMessage = response.data['sysCount'] ?? 0; - _commentMessage = response.data['commentCount'] ?? 0; - notifyListeners(); - } + WORKCLOCK _clockStatus = WORKCLOCK.NOTIN; DateTime? _clockInTime; diff --git a/lib/provider/message_provider.dart b/lib/provider/message_provider.dart new file mode 100644 index 0000000..edafaea --- /dev/null +++ b/lib/provider/message_provider.dart @@ -0,0 +1,46 @@ +import 'package:aku_community_manager/const/api.dart'; +import 'package:aku_community_manager/utils/network/net_util.dart'; +import 'package:common_utils/common_utils.dart'; +import 'package:dio/dio.dart'; +import 'package:flutter/material.dart'; + +class MessageProvider extends ChangeNotifier { + int _sysMessage = 0; + int _commentMessage = 0; + String _sysDate = ''; + String _commentDate = ''; + bool get hasMessage => _sysMessage != 0 || _commentMessage != 0; + int get sysMessage => _sysMessage; + int get commentMessage => _commentMessage; + String get sysDate => + DateUtil.formatDateStr(_sysDate, format: 'yyyy-MM-dd HH:mm'); + + String get commentDate => + DateUtil.formatDateStr(_commentDate, format: 'yyyy-MM-dd HH:mm'); + int _sysMesType = 0; + String get sysMesTypeString { + switch (_sysMesType) { + case 1: + return '报事报修'; + case 2: + return '装修'; + case 3: + return '绿化任务'; + case 4: + return '卫生任务'; + default: + return '未知'; + } + } + + updateMessage() async { + Response response = await NetUtil().dio!.get(API.message.messageCenter); + if (response.data == null) return; + _sysMessage = response.data['sysCount'] ?? 0; + _commentMessage = response.data['commentCount'] ?? 0; + _sysMesType = response.data['sysType'] ?? 0; + _sysDate = response.data['sysDate'] ?? ''; + _commentDate = response.data['commentDate'] ?? ''; + notifyListeners(); + } +} diff --git a/lib/provider/outdoor_provider.dart b/lib/provider/outdoor_provider.dart deleted file mode 100644 index 8b13789..0000000 --- a/lib/provider/outdoor_provider.dart +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index 81727f4..bd93220 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -3,6 +3,7 @@ import 'dart:io'; // Flutter imports: import 'package:aku_community_manager/models/user/user_info_model.dart'; +import 'package:aku_community_manager/provider/message_provider.dart'; import 'package:flutter/material.dart'; // Package imports: @@ -14,7 +15,6 @@ import 'package:provider/provider.dart'; // Project imports: import 'package:aku_community_manager/const/api.dart'; import 'package:aku_community_manager/models/user/user_profile_model.dart'; -import 'package:aku_community_manager/provider/app_provider.dart'; import 'package:aku_community_manager/utils/hive_store.dart'; import 'package:aku_community_manager/utils/network/base_file_model.dart'; import 'package:aku_community_manager/utils/network/base_model.dart'; @@ -48,8 +48,8 @@ class UserProvider extends ChangeNotifier { ///更新用户profile Future updateProfile() async { - final appProvider = Provider.of(Get.context!, listen: false); - appProvider.updateMessage(); + final messageProvider = Provider.of(Get.context!,listen: false); + messageProvider.updateMessage(); BaseModel? model = await NetUtil().get(API.user.profile); if (model.data == null) return null; diff --git a/lib/tools/user_tool.dart b/lib/tools/user_tool.dart index 3724f4f..929573d 100644 --- a/lib/tools/user_tool.dart +++ b/lib/tools/user_tool.dart @@ -1,4 +1,5 @@ // Package imports: +import 'package:aku_community_manager/provider/message_provider.dart'; import 'package:get/get.dart'; import 'package:provider/provider.dart'; @@ -16,5 +17,8 @@ class UserTool { static UserProvider get userProvider => Provider.of(Get.context!, listen: false); + ///消息中心 + static MessageProvider get messageProvider => Provider.of(Get.context!,listen: false); + UserTool(); } diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index 30e92d5..e92c56a 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -1,6 +1,7 @@ // Flutter imports: import 'dart:async'; +import 'package:aku_community_manager/provider/message_provider.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_button.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_material_button.dart'; import 'package:flutter/material.dart'; @@ -178,7 +179,8 @@ class _HomePageState extends State { @override Widget build(BuildContext context) { final userProvider = Provider.of(context); - final appProvider = Provider.of(context); + + final messageProvider = Provider.of(Get.context!); var loadingWidget = Center( // child: CircularProgressIndicator(), ); @@ -306,7 +308,7 @@ class _HomePageState extends State { top: 4, end: 4, ), - showBadge: appProvider.hasMessage, + showBadge: messageProvider.hasMessage, child: Container( margin: EdgeInsets.only(top: 5.w, bottom: 5.w), child: AkuMaterialButton( diff --git a/lib/ui/home/messages/comment_message_card.dart b/lib/ui/home/messages/comment_message_card.dart index 540e8ef..5796cc6 100644 --- a/lib/ui/home/messages/comment_message_card.dart +++ b/lib/ui/home/messages/comment_message_card.dart @@ -1,6 +1,7 @@ // Flutter imports: import 'package:aku_community_manager/ui/widgets/common/aku_button.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_rating_bar/flutter_rating_bar.dart'; // Package imports: import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -17,7 +18,8 @@ import 'package:aku_community_manager/utils/network/net_util.dart'; class CommentMessageCard extends StatefulWidget { final CommentMessageItemModel itemModel; - CommentMessageCard({Key? key, /*required*/ required this.itemModel}) : super(key: key); + CommentMessageCard({Key? key, /*required*/ required this.itemModel}) + : super(key: key); @override _CommentMessageCardState createState() => _CommentMessageCardState(); @@ -50,7 +52,7 @@ class _CommentMessageCardState extends State { switch (level) { case 1: return '半星'; - + case 2: return '一星'; case 3: @@ -288,10 +290,21 @@ class _CommentMessageCardState extends State { color: AppStyle.minorTextColor, fontSize: 28.sp)), Spacer(), - Text(getComment(model.level!), - style: TextStyle( - color: AppStyle.primaryTextColor, - fontSize: 28.sp)), + // Text(getComment(model.level!), + // style: TextStyle( + // color: AppStyle.primaryTextColor, + // fontSize: 28.sp)), + RatingBar.builder( + initialRating: model.level!.toDouble(), + itemSize: 40.w, + allowHalfRating: true, + itemBuilder: (context, index) { + return Image.asset( + R.ASSETS_MESSAGE_IC_STAR_PNG, + color: kPrimaryColor, + ); + }, + onRatingUpdate: (rate) {}) ], ).pSymmetric(h: 24.w), SizedBox(height: 16.w), diff --git a/lib/ui/home/messages/message.dart b/lib/ui/home/messages/message.dart index 9893674..7042cab 100644 --- a/lib/ui/home/messages/message.dart +++ b/lib/ui/home/messages/message.dart @@ -1,5 +1,9 @@ // Flutter imports: +import 'package:aku_community_manager/const/api.dart'; +import 'package:aku_community_manager/provider/message_provider.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_button.dart'; +import 'package:aku_community_manager/utils/network/base_model.dart'; +import 'package:aku_community_manager/utils/network/net_util.dart'; import 'package:flutter/material.dart'; // Package imports: @@ -12,7 +16,6 @@ import 'package:provider/provider.dart'; // Project imports: import 'package:aku_community_manager/const/resource.dart'; -import 'package:aku_community_manager/provider/app_provider.dart'; import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/ui/home/messages/comment_message.dart'; import 'package:aku_community_manager/ui/home/messages/system_message.dart'; @@ -132,7 +135,8 @@ class _MessageState extends State { @override Widget build(BuildContext context) { - final appProvider = Provider.of(context); + final messageProvider = + Provider.of(Get.context!, listen: false); return AkuScaffold( title: '消息', titleStyle: AppStyle().barTitleStyle, @@ -140,33 +144,43 @@ class _MessageState extends State { controller: _refreshController, firstRefresh: true, onRefresh: () async { - await appProvider.updateMessage(); + await messageProvider.updateMessage(); }, header: MaterialHeader(), child: ListView( padding: EdgeInsets.only(top: 16.w), children: [ _messageListTile( - '', + messageProvider.sysDate, _messageTypeImage('系统消息'), '系统消息', - '你有一条新的报事报修待处理', - appProvider.sysMessage, - onpressed: () { - Get.to(() => SystemMessage()); + '你有一条新的${messageProvider.sysMesTypeString}待处理', + messageProvider.sysMessage, + onpressed: () async { + BaseModel baseModel = + await NetUtil().get(API.message.allReadSysMes); + if (baseModel.status ?? false) { + messageProvider.updateMessage(); + Get.to(() => SystemMessage()); + } }, ), Divider( height: 1.w, ), _messageListTile( - '', + messageProvider.commentDate, _messageTypeImage('评论消息'), '评论消息', '你有一条新的评论回复', - appProvider.commentMessage, - onpressed: () { - Get.to(() => CommentMessage()); + messageProvider.commentMessage, + onpressed: () async { + BaseModel baseModel = + await NetUtil().get(API.message.allReadCommentMes); + if (baseModel.status ?? false) { + messageProvider.updateMessage(); + Get.to(() => CommentMessage()); + } }, ), ], diff --git a/lib/ui/home/messages/systen_message_card.dart b/lib/ui/home/messages/systen_message_card.dart index 073a1e5..7596860 100644 --- a/lib/ui/home/messages/systen_message_card.dart +++ b/lib/ui/home/messages/systen_message_card.dart @@ -224,7 +224,7 @@ class _SystemMessageCardState extends State { SizedBox(height: 8.w), ]), Text( - '你有一条新的报事报修,请立即处理', + '你有一条新的${model.sysMesTypeString},请立即处理', style: TextStyle( color: AppStyle.primaryTextColor, fontSize: 28.sp,