From ca6adcc98019613ff322aee2f1ec5765bdf207ee Mon Sep 17 00:00:00 2001 From: PH2 <1293456824@qq.com> Date: Tue, 30 Mar 2021 16:21:48 +0800 Subject: [PATCH 1/3] =?UTF-8?q?1=E3=80=81=E5=AE=A1=E6=A0=B8=E6=A8=A1?= =?UTF-8?q?=E7=89=88=E5=88=B7=E6=96=B0=E7=9A=84=E7=AB=8B=E5=8D=B3=E5=88=B7?= =?UTF-8?q?=E6=96=B0=202=E3=80=81=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E7=9A=84=E5=95=86=E5=93=81=E5=95=86=E5=BA=97=E9=97=AE=E9=A2=98?= =?UTF-8?q?=203=E3=80=81=E4=B8=AA=E4=BA=BA=E5=90=84=E7=A7=8D=E6=97=A0?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bloc/bottom_nav_repository.dart | 67 +++++++++++++++++++ .../bloc/custom_item_page_bloc.dart | 14 ++++ .../bloc/custom_item_page_repository.dart | 7 +- .../bloc/custom_item_page_state.dart | 3 + .../bloc/custom_page_repository.dart | 8 --- lib/pages/custom_page/custom_item_page.dart | 10 +++ .../goods_details/store/bloc/store_state.dart | 2 +- .../mine/mine_data/mine_data_widget.dart | 3 +- .../mine_header/mine_header_container.dart | 4 +- .../restart_widget/restart_widget.dart | 16 ++--- 10 files changed, 108 insertions(+), 26 deletions(-) create mode 100644 lib/pages/custom_page/bloc/bottom_nav_repository.dart 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: "更新数据中..."); From 3cd99452be8b5fc0ef480ccec607835b1ad97584 Mon Sep 17 00:00:00 2001 From: PH2 <1293456824@qq.com> Date: Tue, 30 Mar 2021 16:34:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?1=E3=80=81=E6=99=BA=E8=83=BD=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E6=B8=A0=E9=81=93=E8=B7=B3=E8=BD=AC=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intellect_search_no_goods_dialog.dart | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/dialog/global_dialog/intellect_search_goods_dialog/intellect_search_no_goods_dialog.dart b/lib/dialog/global_dialog/intellect_search_goods_dialog/intellect_search_no_goods_dialog.dart index 7ff7e21..48f04ef 100644 --- a/lib/dialog/global_dialog/intellect_search_goods_dialog/intellect_search_no_goods_dialog.dart +++ b/lib/dialog/global_dialog/intellect_search_goods_dialog/intellect_search_no_goods_dialog.dart @@ -61,11 +61,8 @@ class _IntellectSearchNoGoodsDialogState extends State openSearchResultPage(), + onTap: () => openDefaultSearchResultPage(), ), ) ], @@ -237,11 +243,7 @@ class _IntellectSearchNoGoodsDialogState extends State openTargetSearchResultPage(item), )); } From 2c9785a232d38c6024bf5365a8ccd85f99fe7e24 Mon Sep 17 00:00:00 2001 From: PH2 <1293456824@qq.com> Date: Tue, 30 Mar 2021 18:57:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?1=E3=80=81=E6=B6=88=E9=99=A4=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/home_goods/models/home_goods_list_style_model.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widgets/home/home_goods/models/home_goods_list_style_model.dart b/lib/widgets/home/home_goods/models/home_goods_list_style_model.dart index b63ded9..af660f6 100644 --- a/lib/widgets/home/home_goods/models/home_goods_list_style_model.dart +++ b/lib/widgets/home/home_goods/models/home_goods_list_style_model.dart @@ -33,7 +33,7 @@ class HomeGoodsListStyleModel { }); HomeGoodsListStyleModel.fromJson(Map json) { - hotRankIconList = json['hot_rank_icon_list']. cast(); + hotRankIconList = json['hot_rank_icon_list'].cast(); topMargin = json['top_margin']; listColumn = json['list_column']; leftRighMargin = json['left_righ_margin'];