diff --git a/lib/pages/custom_page/bloc/bottom_nav_repository.dart b/lib/pages/custom_page/bloc/bottom_nav_repository.dart new file mode 100644 index 0000000..933755f --- /dev/null +++ b/lib/pages/custom_page/bloc/bottom_nav_repository.dart @@ -0,0 +1,67 @@ +import 'dart:async'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +/// +/// 底部导航栏数据Repository +/// +class BottomNavRepository { + + /// 获取网络数据 + Future fetchNetData() async { + try { + var result = await NetUtil.post('/api/v1/new/config.json', method: NetMethod.GET, cache: true); + if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { + return result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]; + } + } catch (e, s) { + Logger.error(e, s); + } + return null; + } + + /// 获取缓存数据 + Future fetchCacheData() async { + try { + var result = await NetUtil.getRequestCachedData('/api/v1/new/config.json'); + if (!EmptyUtil.isEmpty(result)) { + return result; + } + } catch (e, s) { + Logger.error(e, s); + } + return null; + } + + /// + /// 校验底部导航栏是否更新 + /// + /// 校验的规则:使用 bottom_nav 的 mod_id + mod_pid + template_id + data 进行MD5 + /// ⚠️ 由于Register初始化/api/v1/new/config.json没有进行缓存,可以利用这规则,如果Register的init进行了接口缓存则需要修改逻辑 + /// + /// false: 不更新 true 更新 + /// + Future validateBottomNavUpdate() async { + bool rlt = false; + try { + var cacheData = await fetchCacheData(); + var netData = await fetchNetData(); + if (!EmptyUtil.isEmpty(netData) && !EmptyUtil.isEmpty(cacheData)) { + var netBottomNav = netData['bottom_nav']; + var cacheBottomNav = cacheData['bottom_nav']; + if (!EmptyUtil.isEmpty(netBottomNav) && !EmptyUtil.isEmpty(cacheBottomNav)) { + var netEncodeStr = new StringBuffer(); + var cacheEncodeStr = new StringBuffer(); + netEncodeStr..write(netBottomNav['mod_id'])..write('-')..write(netBottomNav['mod_pid'])..write('-')..write(netBottomNav['template_id'])..write(netBottomNav['data']); + cacheEncodeStr..write(cacheBottomNav['mod_id'])..write('-')..write(cacheBottomNav['mod_pid'])..write('-')..write(cacheBottomNav['template_id'])..write(cacheBottomNav['data']); + String netMD5 = EncodeUtil.generateMd5(netEncodeStr.toString()); + String cacheMD5 = EncodeUtil.generateMd5(cacheEncodeStr.toString()); + Logger.log('网络数据的MD5 = ${netMD5}, 本地数据的MD5 = ${cacheMD5}'); + rlt = (netMD5 != cacheMD5); + } + } + } catch (e, s) { + Logger.error(e, s); + } + return rlt; + } +} diff --git a/lib/pages/custom_page/bloc/custom_item_page_bloc.dart b/lib/pages/custom_page/bloc/custom_item_page_bloc.dart index 28cae56..ae17400 100644 --- a/lib/pages/custom_page/bloc/custom_item_page_bloc.dart +++ b/lib/pages/custom_page/bloc/custom_item_page_bloc.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; +import 'package:zhiying_base_widget/pages/custom_page/bloc/bottom_nav_repository.dart'; import 'package:zhiying_base_widget/pages/custom_page/bloc/custom_item_page_repository.dart'; import 'custom_item_page_state.dart'; import 'custom_item_page_event.dart'; @@ -12,6 +13,7 @@ class CustomItemPageBloc extends Bloc CustomItemPageRepository repository; CustomItemPageBloc(this.repository) : super(CustomItemPageInitial()); + BottomNavRepository _bottomNavRepository = new BottomNavRepository(); @@ -47,6 +49,12 @@ class CustomItemPageBloc extends Bloc } else { yield CustomItemPageInitErrorState(); } + // 检查校验是否需要重启App(底部模版问题) + bool needRestart = await _bottomNavRepository.validateBottomNavUpdate(); + Logger.log('init 是否重新启动App = ${needRestart}'); + if (needRestart) { + yield CustomItemPageAppRestartState(); + } } /// 下拉刷新 @@ -59,6 +67,12 @@ class CustomItemPageBloc extends Bloc yield CustomItemPageRefreshErrorState(); yield CustomItemPageErrorState(); } + // 检查校验是否需要重启App(底部模版问题) + bool needRestart = await _bottomNavRepository.validateBottomNavUpdate(); + Logger.log('refresh 是否重新启动App = ${needRestart}'); + if (needRestart) { + yield CustomItemPageAppRestartState(); + } } /// 上拉更多 diff --git a/lib/pages/custom_page/bloc/custom_item_page_repository.dart b/lib/pages/custom_page/bloc/custom_item_page_repository.dart index 1dc43d5..d2f32c3 100644 --- a/lib/pages/custom_page/bloc/custom_item_page_repository.dart +++ b/lib/pages/custom_page/bloc/custom_item_page_repository.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:zhiying_base_widget/pages/custom_page/event/reload_event.dart'; + import 'package:zhiying_comm/zhiying_comm.dart'; class CustomItemPageRepository { @@ -21,13 +21,8 @@ class CustomItemPageRepository { List mobList = !EmptyUtil.isEmpty(data) ? List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA][tabIndex.toString()]) : List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); if (!EmptyUtil.isEmpty(mobList)) { - ReloadEvent.com = 0; return mobList.map((e) => Map.from(e)).toList(); } - } else { - Timer(Duration(milliseconds: 1000), () { - EventUtil.instance.fire(ReloadEvent()); - }); } } } catch (e, s) { diff --git a/lib/pages/custom_page/bloc/custom_item_page_state.dart b/lib/pages/custom_page/bloc/custom_item_page_state.dart index 3b06936..387731e 100644 --- a/lib/pages/custom_page/bloc/custom_item_page_state.dart +++ b/lib/pages/custom_page/bloc/custom_item_page_state.dart @@ -30,3 +30,6 @@ class CustomItemPageLoadErrorState extends CustomItemPageState {} /// 其他错误 class CustomItemPageErrorState extends CustomItemPageState {} + +/// 需要重新渲染App,更新底部导航模版 +class CustomItemPageAppRestartState extends CustomItemPageState {} diff --git a/lib/pages/custom_page/bloc/custom_page_repository.dart b/lib/pages/custom_page/bloc/custom_page_repository.dart index 8eff7a1..7b7cc4b 100644 --- a/lib/pages/custom_page/bloc/custom_page_repository.dart +++ b/lib/pages/custom_page/bloc/custom_page_repository.dart @@ -1,8 +1,6 @@ import 'dart:async'; import 'dart:convert'; -import 'package:zhiying_base_widget/dialog/loading/loading.dart'; -import 'package:zhiying_base_widget/pages/custom_page/event/reload_event.dart'; import 'package:zhiying_base_widget/pages/main_page/model/background_model.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; @@ -40,12 +38,6 @@ class CustomPageRepository { } return customPageData; } - }else{ - - Timer(Duration(milliseconds: 1000), (){ - EventUtil.instance.fire(ReloadEvent()); - }); - } } } catch (e, s) { diff --git a/lib/pages/custom_page/custom_item_page.dart b/lib/pages/custom_page/custom_item_page.dart index fe12c86..7620bde 100644 --- a/lib/pages/custom_page/custom_item_page.dart +++ b/lib/pages/custom_page/custom_item_page.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:event_bus/event_bus.dart'; import 'package:flutter/material.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; @@ -12,6 +14,7 @@ import 'bloc/custom_item_page_bloc.dart'; import 'bloc/custom_item_page_state.dart'; import 'bloc/custom_item_page_event.dart'; import 'bloc/custom_item_page_repository.dart'; +import 'package:zhiying_base_widget/pages/custom_page/event/reload_event.dart'; /// /// 通用模块的分类导航下的子模块 @@ -131,9 +134,16 @@ class __CustomItemPageContainerState extends State<_CustomItemPageContainer> wit if (current is CustomItemPageErrorState) { return false; } + if (current is CustomItemPageAppRestartState) { + // 重启App + Logger.log('开始重新启动App CustomItemPageAppRestartState'); + EventUtil.instance.fire(ReloadEvent()); + return false; + } return true; }, builder: (context, state) { + Logger.log('Custom item page builder 刷新了'); if (state is CustomItemPageLoadedState) { Logger.log('custom item page current state = ' + state?.toString()); if (EmptyUtil.isEmpty(state.model)) diff --git a/lib/widgets/goods_details/store/bloc/store_state.dart b/lib/widgets/goods_details/store/bloc/store_state.dart index 0148013..bb3e841 100644 --- a/lib/widgets/goods_details/store/bloc/store_state.dart +++ b/lib/widgets/goods_details/store/bloc/store_state.dart @@ -17,7 +17,7 @@ class StoreLoadedState extends StoreState { const StoreLoadedState({this.model}); @override - List get props => []; + List get props => [this.model]; } /// 数据加载出错 diff --git a/lib/widgets/mine/mine_data/mine_data_widget.dart b/lib/widgets/mine/mine_data/mine_data_widget.dart index a5b694f..5a31626 100644 --- a/lib/widgets/mine/mine_data/mine_data_widget.dart +++ b/lib/widgets/mine/mine_data/mine_data_widget.dart @@ -7,6 +7,7 @@ import 'package:zhiying_base_widget/widgets/mine/mine_data/model/mine_data_model import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_profile_model.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/util/shared_prefe_util.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; class MineDataWidget extends StatefulWidget { final Map data; @@ -118,7 +119,7 @@ class _MineDataWidgetState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - _isiOSReview ? '' : widget?.profile?.gridViews[0]?.name ?? "累计收益", + _isiOSReview ? '' : EmptyUtil.isEmpty(widget?.profile?.gridViews) ? "累计收益" : widget?.profile?.gridViews[0]?.name ?? '累计收益', style: TextStyle( fontSize: 11, fontWeight: FontWeight.w600, diff --git a/lib/widgets/mine/mine_header/mine_header_container.dart b/lib/widgets/mine/mine_header/mine_header_container.dart index b6a97bc..ba3f094 100644 --- a/lib/widgets/mine/mine_header/mine_header_container.dart +++ b/lib/widgets/mine/mine_header/mine_header_container.dart @@ -147,11 +147,11 @@ class _MineHeaderContainerState extends State { child: Row( children: [ Text( - '邀请码:${profile.inviteCode}', + '邀请码:${profile?.inviteCode ?? ''}', maxLines: 1, style: TextStyle( fontSize: 13, - color: HexColor.fromHex(widget.staticModel.userNameColor), + color: HexColor.fromHex(widget?.staticModel?.userNameColor), fontFamily: 'Din', package: 'zhiying_comm', ), diff --git a/lib/widgets/restart_widget/restart_widget.dart b/lib/widgets/restart_widget/restart_widget.dart index 8aeeb50..703063a 100644 --- a/lib/widgets/restart_widget/restart_widget.dart +++ b/lib/widgets/restart_widget/restart_widget.dart @@ -21,7 +21,7 @@ class RestartWidget extends StatefulWidget { class _RestartWidgetState extends State { bool reStart = false; - int com = 0; + // int com = 0; Timer timer1; Timer timer2; @@ -37,15 +37,15 @@ class _RestartWidgetState extends State { return; } - com++; + // com++; ///刷新3次后不再刷新 - if (com > 3) { - if (com < 7) { - Fluttertoast.showToast(msg: "网络服务不可用"); - } - return; - } + // if (com > 3) { + // if (com < 7) { + // Fluttertoast.showToast(msg: "网络服务不可用"); + // } + // return; + // } Loading.show(context, msg: "更新数据中...");