From 2f1c98392f9307c72e279a7552aa7c36f0b20ee6 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Sun, 31 Aug 2025 19:18:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=98=BE=E7=A4=BA3s=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E8=B4=AD=E4=B9=B0=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widgets/order/mixin/order_mixin.dart | 29 ++++++----- lib/pages/supermarket_order/controller.dart | 1 - .../common/utils/sub_page_tool.dart | 15 ++++-- lib/sub_screen/page/sub_app.dart | 15 +++--- lib/sub_screen/page/sub_product.dart | 49 ++++++++++++++----- 5 files changed, 70 insertions(+), 39 deletions(-) diff --git a/lib/common/widgets/order/mixin/order_mixin.dart b/lib/common/widgets/order/mixin/order_mixin.dart index 80c0b36..99ba857 100644 --- a/lib/common/widgets/order/mixin/order_mixin.dart +++ b/lib/common/widgets/order/mixin/order_mixin.dart @@ -453,19 +453,11 @@ mixin OrderMixin { /// **************** start 副屏幕相关 start **************** - void putOffSendSubScreen({int seconds = 5}) { - // 如果有商品就不反回 - if (_sysType == SysType.SUPERMARKET) { - if (supermarketSpuList.isNotEmpty) { - putOffSendSubScreenDelayed = null; - return; - } - } - if (_sysType == SysType.CANTEEN) { - if (canteenSpuList.isNotEmpty) { - putOffSendSubScreenDelayed = null; - return; - } + void putOffSendSubScreen({int seconds = 3}) { + // 如果有商品就直接反回 + if (shopCardList.isNotEmpty) { + putOffSendSubScreenDelayed = null; + return; } if (putOffSendSubScreenDelayed != null) { sendSubScreenBack(); @@ -473,6 +465,11 @@ mixin OrderMixin { return; } putOffSendSubScreenDelayed = Future.delayed(Duration(seconds: seconds), () { + // 如果有商品就直接反回 + if (shopCardList.isNotEmpty) { + putOffSendSubScreenDelayed = null; + return; + } sendSubScreenBack(); putOffSendSubScreenDelayed = null; }); @@ -485,6 +482,12 @@ mixin OrderMixin { } Future sendSubScreen() async { + if (shopCardList.isEmpty) { + await SubScreenPlugin.sendMsgToViceScreen( + SubScreenAction.jumpSubBack.name, + ); + return; + } final json = SubScreenProductEvent( shopList: shopCardList.map((e) => e.toJson()).toList(), sysType: _sysType, diff --git a/lib/pages/supermarket_order/controller.dart b/lib/pages/supermarket_order/controller.dart index 71c9046..5fe2bc4 100644 --- a/lib/pages/supermarket_order/controller.dart +++ b/lib/pages/supermarket_order/controller.dart @@ -163,7 +163,6 @@ class SupermarketOrderController extends GetxController with OrderMixin { } shopCardList.refresh(); computedTotalPrice(); - sendSubScreen(); } // |+|或者|-|点击更改商品数量 diff --git a/lib/sub_screen/common/utils/sub_page_tool.dart b/lib/sub_screen/common/utils/sub_page_tool.dart index c37270a..1dae746 100644 --- a/lib/sub_screen/common/utils/sub_page_tool.dart +++ b/lib/sub_screen/common/utils/sub_page_tool.dart @@ -4,30 +4,35 @@ import 'package:pj_supermarket_cloud/common/index.dart'; import 'package:pj_supermarket_cloud/sub_screen/common/index.dart'; class SubPageToool { - static void switchJump(SubScreenAction type) { + static void switchJump( + SubScreenAction type, { + Object? arguments, + }) { // 判断是否要跳转的页面就是当前页面 switch (type) { case SubScreenAction.jumpSubPage: if (SubNavigatorKey.currentRouteName == SubRouteNames.subProduct) { return; } + logger.i("跳转到商品页面"); + SubNavigatorKey.currentRouteName = SubRouteNames.subProduct; SubNavigatorKey.navigatorKey.currentState?.pushNamedAndRemoveUntil( SubRouteNames.subProduct, (Route route) => false, + arguments: arguments, ); - logger.i("跳转到商品页面"); - SubNavigatorKey.currentRouteName = SubRouteNames.subProduct; break; case SubScreenAction.jumpSubBack: if (SubNavigatorKey.currentRouteName == SubRouteNames.root) { return; } + logger.i("跳转到欢迎页面"); + SubNavigatorKey.currentRouteName = SubRouteNames.root; SubNavigatorKey.navigatorKey.currentState?.pushNamedAndRemoveUntil( SubRouteNames.root, (Route route) => false, + arguments: arguments, ); - logger.i("跳转到欢迎页面"); - SubNavigatorKey.currentRouteName = SubRouteNames.root; break; default: } diff --git a/lib/sub_screen/page/sub_app.dart b/lib/sub_screen/page/sub_app.dart index 9af0427..3b72df8 100644 --- a/lib/sub_screen/page/sub_app.dart +++ b/lib/sub_screen/page/sub_app.dart @@ -22,15 +22,16 @@ class _SubAppPageState extends State { @override void initState() { super.initState(); - _streamSubscription = SubScreenPlugin.viceStream.listen((event) { + _streamSubscription = SubScreenPlugin.viceStream.listen((event) async { final action = SubScreenAction.values.fromCode(event.method); if (action == null) return; - if (action == SubScreenAction.updateCard) { - if (SubNavigatorKey.currentRouteName != SubRouteNames.subProduct) { - SubPageToool.switchJump(SubScreenAction.jumpSubPage); - } else { - SubPageToool.switchJump(action); - } + SubPageToool.switchJump(action, arguments: event.arguments); + if (action == SubScreenAction.updateCard && + SubNavigatorKey.currentRouteName != SubRouteNames.subProduct) { + SubPageToool.switchJump( + SubScreenAction.jumpSubPage, + arguments: event.arguments, + ); } else { SubPageToool.switchJump(action); } diff --git a/lib/sub_screen/page/sub_product.dart b/lib/sub_screen/page/sub_product.dart index 1798d38..cebdd00 100644 --- a/lib/sub_screen/page/sub_product.dart +++ b/lib/sub_screen/page/sub_product.dart @@ -39,6 +39,25 @@ class _SubProductPageState extends State { @override void initState() { super.initState(); + + // 获取上个页面的传参并监听变化 + WidgetsBinding.instance.addPostFrameCallback((_) { + final arguments = ModalRoute.of(context)?.settings.arguments; + if (arguments == null) return; + if (arguments is Map) { + if (arguments.keys.isEmpty) return; + final subScreenEvent = SubScreenProductEvent.fromJson(arguments); + setPageData(subScreenEvent); + return; + } + var convertedArgs = json.decode(json.encode(arguments)); + if (convertedArgs is Map) { + if (convertedArgs.keys.isEmpty) return; + final subScreenEvent = SubScreenProductEvent.fromJson(convertedArgs); + setPageData(subScreenEvent); + } + }); + _streamSubscription = SubScreenPlugin.viceStream.listen((event) { try { dynamic params = event.arguments; @@ -48,19 +67,7 @@ class _SubProductPageState extends State { params = json.decode(json.encode(params)); } final subScreenEvent = SubScreenProductEvent.fromJson(params); - setState(() { - _shopList = subScreenEvent.shopList - .map((v) => ShopCardEntity.fromJson(v)) - .toList(); - _sysType = subScreenEvent.sysType; - if (subScreenEvent.payUser != null) { - _payUser = ServiceUser.fromJson(subScreenEvent.payUser!); - } else { - _payUser = null; - } - _totalPrice = subScreenEvent.totalPrice; - _amountMealPrice = subScreenEvent.amountMealPrice; - }); + setPageData(subScreenEvent); } } catch (e) { logger.e("|$_tag|接收主屏消息错误error|$e|"); @@ -74,6 +81,22 @@ class _SubProductPageState extends State { _streamSubscription.cancel(); } + void setPageData(SubScreenProductEvent subScreenEvent) { + setState(() { + _shopList = subScreenEvent.shopList + .map((v) => ShopCardEntity.fromJson(v)) + .toList(); + _sysType = subScreenEvent.sysType; + if (subScreenEvent.payUser != null) { + _payUser = ServiceUser.fromJson(subScreenEvent.payUser!); + } else { + _payUser = null; + } + _totalPrice = subScreenEvent.totalPrice; + _amountMealPrice = subScreenEvent.amountMealPrice; + }); + } + // 商品区域 Widget _buildProductArea(BuildContext context) { final theme = FTheme.of(context);