Browse Source

首页的 Rewards 的刷新以及未读消息的展示

liukai 1 week ago
parent
commit
6e05700ae4

+ 24 - 6
packages/cpt_main/lib/modules/home/home_page.dart

@@ -10,10 +10,15 @@ import 'package:flutter/src/widgets/framework.dart';
 import 'package:flutter_hooks/flutter_hooks.dart';
 import 'package:hooks_riverpod/hooks_riverpod.dart';
 import 'package:auto_route/auto_route.dart';
+import 'package:plugin_basic/basic_export.dart';
+import 'package:plugin_basic/constants/app_constant.dart';
+import 'package:plugin_basic/provider/user_config/user_config.dart';
 import 'package:plugin_basic/provider/user_config/user_config_service.dart';
 import 'package:plugin_platform/engine/toast/toast_engine.dart';
 import 'package:router/componentRouter/community_service.dart';
 import 'package:router/componentRouter/component_service_manager.dart';
+import 'package:shared/utils/event_bus.dart';
+import 'package:shared/utils/log_utils.dart';
 import 'package:widgets/ext/ex_widget.dart';
 import 'package:widgets/my_appbar.dart';
 import 'package:widgets/my_load_image.dart';
@@ -51,9 +56,20 @@ class HomePage extends HookConsumerWidget {
     }, []);
 
     return AnnotatedRegion<SystemUiOverlayStyle>(
-        value: MediaQuery.of(context).platformBrightness == Brightness.dark
-            ? ThemeConfig.systemUiOverlayStyleDarkTheme
-            : ThemeConfig.systemUiOverlayStyleLightThemeWhite,
+      value: MediaQuery.of(context).platformBrightness == Brightness.dark
+          ? ThemeConfig.systemUiOverlayStyleDarkTheme
+          : ThemeConfig.systemUiOverlayStyleLightThemeWhite,
+      child: VisibilityDetector(
+        key: const Key('unique-key'),
+        onVisibilityChanged: (VisibilityInfo info) {
+          if (info.visibleFraction == 1) {
+            Log.d("Home Page 全部显示");
+            //发送通知刷新用户信息
+            bus.emit(AppConstant.eventProfileRefresh, true);
+          } else {
+            Log.d("Home Page 隐藏了");
+          }
+        },
         child: Scaffold(
           backgroundColor: context.appColors.backgroundDefault,
           body: Stack(
@@ -107,7 +123,7 @@ class HomePage extends HookConsumerWidget {
                           child: Transform.translate(
                             offset: const Offset(-10, -5),
                             child: MyTextView(
-                              "99",
+                              UserConfigService.getState(ref: ref).user?.unreadNotificationsCount ?? "0",
                               boxWidth: 20.0,
                               textColor: Colors.white,
                               fontSize: 10,
@@ -212,7 +228,9 @@ class HomePage extends HookConsumerWidget {
               ),
             ],
           ),
-        ));
+        ),
+      ),
+    );
   }
 
   //顶部的支付与奖励的布局
@@ -269,7 +287,7 @@ class HomePage extends HookConsumerWidget {
                 isFontRegular: true,
               ).paddingOnly(left: 8, right: 4).expanded(),
               MyTextView(
-                "9568",
+                UserConfigService.getState(ref: ref).user?.rewardPoints ?? "0",
                 textColor: context.appColors.textBlack,
                 fontSize: 14,
                 isFontBold: true,

+ 0 - 7
packages/cpt_main/lib/modules/main/main_page.dart

@@ -33,13 +33,6 @@ class MainPage extends HookConsumerWidget {
     final viewModel = ref.watch(mainViewModelProvider.notifier);
     final state = ref.watch(mainViewModelProvider);
 
-    useEffect(() {
-
-      Future.microtask(() => viewModel.fetchUserInfo());
-      return () {
-      };
-    }, []);
-
     return AutoTabsScaffold(
       routes: const [
         HomePageRoute(),

+ 2 - 2
packages/cpt_main/lib/modules/main/main_view_model.dart

@@ -30,7 +30,7 @@ class MainViewModel extends _$MainViewModel with DioCancelableMixin {
   }
 
   /// 获取用户信息
-  void fetchUserInfo() {
+  void _fetchUserInfo() {
     UserConfigService.getInstance().refreshUserInfo();
   }
 
@@ -40,7 +40,7 @@ class MainViewModel extends _$MainViewModel with DioCancelableMixin {
   void registerEventBus() {
     subscribe = bus.on(AppConstant.eventProfileRefresh, (arg) {
       Log.d("收到消息刷新用户信息");
-      fetchUserInfo();
+      _fetchUserInfo();
     });
   }
 

+ 1 - 1
packages/cpt_profile/lib/modules/setting/setting_view_model.dart

@@ -87,6 +87,6 @@ class SettingViewModel extends _$SettingViewModel with DioCancelableMixin{
 
   //评价我们,跳转到各平台的应用商城
   void rateUs() {
-    bus.emit(AppConstant.eventProfileRefresh, true);
+
   }
 }

+ 4 - 0
packages/cs_domain/lib/entity/user_me_entity.dart

@@ -16,6 +16,10 @@ class UserMeEntity {
 	String? flowersCount;
 	@JSONField(name: "posts_count")
 	String? postsCount;
+	@JSONField(name: "reward_points")
+	String? rewardPoints;
+	@JSONField(name: "unread_notifications_count")
+	String? unreadNotificationsCount;
 	List<UserMeHouseholds>? households = [];
 	List<UserMeEstates>? estates = [];
 	@JSONField(name: "default_unit")

+ 14 - 0
packages/cs_domain/lib/generated/json/user_me_entity.g.dart

@@ -35,6 +35,14 @@ UserMeEntity $UserMeEntityFromJson(Map<String, dynamic> json) {
   if (postsCount != null) {
     userMeEntity.postsCount = postsCount;
   }
+  final String? rewardPoints = jsonConvert.convert<String>(json['reward_points']);
+  if (rewardPoints != null) {
+    userMeEntity.rewardPoints = rewardPoints;
+  }
+  final String? unreadNotificationsCount = jsonConvert.convert<String>(json['unread_notifications_count']);
+  if (unreadNotificationsCount != null) {
+    userMeEntity.unreadNotificationsCount = unreadNotificationsCount;
+  }
   final List<UserMeHouseholds>? households = (json['households'] as List<dynamic>?)?.map(
           (e) => jsonConvert.convert<UserMeHouseholds>(e) as UserMeHouseholds).toList();
   if (households != null) {
@@ -66,6 +74,8 @@ Map<String, dynamic> $UserMeEntityToJson(UserMeEntity entity) {
   data['follows_count'] = entity.followsCount;
   data['flowers_count'] = entity.flowersCount;
   data['posts_count'] = entity.postsCount;
+  data['reward_points'] = entity.rewardPoints;
+  data['unread_notifications_count'] = entity.unreadNotificationsCount;
   data['households'] = entity.households?.map((v) => v.toJson()).toList();
   data['estates'] = entity.estates?.map((v) => v.toJson()).toList();
   data['default_unit'] = entity.defaultUnit?.toJson();
@@ -83,6 +93,8 @@ extension UserMeEntityExtension on UserMeEntity {
     String? followsCount,
     String? flowersCount,
     String? postsCount,
+    String? rewardPoints,
+    String? unreadNotificationsCount,
     List<UserMeHouseholds>? households,
     List<UserMeEstates>? estates,
     UserMeDefaultUnit? defaultUnit,
@@ -97,6 +109,8 @@ extension UserMeEntityExtension on UserMeEntity {
       ..followsCount = followsCount ?? this.followsCount
       ..flowersCount = flowersCount ?? this.flowersCount
       ..postsCount = postsCount ?? this.postsCount
+      ..rewardPoints = rewardPoints ?? this.rewardPoints
+      ..unreadNotificationsCount = unreadNotificationsCount ?? this.unreadNotificationsCount
       ..households = households ?? this.households
       ..estates = estates ?? this.estates
       ..defaultUnit = defaultUnit ?? this.defaultUnit

+ 0 - 10
packages/cs_plugin_basic/lib/provider/user_config/user_config.dart

@@ -14,12 +14,6 @@ class UserConfig {
   //用户是否已经登录
   bool hasLogin = false;
 
-  //用户的 registrationId 推送标识
-  String? registrationId;
-
-  //用户的未读消息数量
-  int unreadNotificationsCount = 0;
-
   /// 获取用户默认的房产名称
   String? getDefaultEstateName() {
     return user?.estates
@@ -38,8 +32,6 @@ class UserConfig {
     this.token,
     this.userName,
     required this.hasLogin,
-    this.registrationId,
-    required this.unreadNotificationsCount,
   });
 
   UserConfig copyWith({
@@ -55,8 +47,6 @@ class UserConfig {
       token: token ?? this.token,
       userName: userName ?? this.userName,
       hasLogin: hasLogin ?? this.hasLogin,
-      registrationId: registrationId ?? this.registrationId,
-      unreadNotificationsCount: unreadNotificationsCount ?? this.unreadNotificationsCount,
     );
   }
 

+ 7 - 2
packages/cs_plugin_basic/lib/provider/user_config/user_config_service.dart

@@ -44,7 +44,7 @@ class UserConfigService extends _$UserConfigService {
 
     String? token = SPUtil.getString(AppConstant.storageToken);
     Log.d('UserService - 查询SP token:$token 并赋值');
-    return UserConfig(token: token, hasLogin: Utils.isNotEmpty(token), registrationId: null, unreadNotificationsCount: 0);
+    return UserConfig(token: token, hasLogin: Utils.isNotEmpty(token));
   }
 
   /// 静默请求用户的详情数据
@@ -82,6 +82,11 @@ class UserConfigService extends _$UserConfigService {
   /// 处理退出登录之后的数据清除
   void handleLogoutParams() {
     SPUtil.remove(AppConstant.storageToken);
-    state = UserConfig(token: null, hasLogin: false, registrationId: null,user: null,userName: null, unreadNotificationsCount: 0);
+    state = UserConfig(
+      token: null,
+      hasLogin: false,
+      user: null,
+      userName: null,
+    );
   }
 }