feat:显示3s用户的购买界面

This commit is contained in:
dzc committed 2025-08-31 19:18:18 +08:00
1 parent 7ed1a4a343
commit 2f1c98392f
5 files changed
+70 -39

No files matched your search

+16 -13
View File
@@ -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<void> sendSubScreen() async {
if (shopCardList.isEmpty) {
await SubScreenPlugin.sendMsgToViceScreen(
SubScreenAction.jumpSubBack.name,
);
return;
}
final json = SubScreenProductEvent(
shopList: shopCardList.map((e) => e.toJson()).toList(),
sysType: _sysType,
@@ -163,7 +163,6 @@ class SupermarketOrderController extends GetxController with OrderMixin {
}
shopCardList.refresh();
computedTotalPrice();
sendSubScreen();
}
// |+|或者|-|点击更改商品数量
+10 -5
View File
@@ -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<dynamic> 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<dynamic> route) => false,
arguments: arguments,
);
logger.i("跳转到欢迎页面");
SubNavigatorKey.currentRouteName = SubRouteNames.root;
break;
default:
}
+8 -7
View File
@@ -22,15 +22,16 @@ class _SubAppPageState extends State<SubAppPage> {
@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);
}
+36 -13
View File
@@ -39,6 +39,25 @@ class _SubProductPageState extends State<SubProductPage> {
@override
void initState() {
super.initState();
// 获取上个页面的传参并监听变化
WidgetsBinding.instance.addPostFrameCallback((_) {
final arguments = ModalRoute.of(context)?.settings.arguments;
if (arguments == null) return;
if (arguments is Map<String, dynamic>) {
if (arguments.keys.isEmpty) return;
final subScreenEvent = SubScreenProductEvent.fromJson(arguments);
setPageData(subScreenEvent);
return;
}
var convertedArgs = json.decode(json.encode(arguments));
if (convertedArgs is Map<String, dynamic>) {
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<SubProductPage> {
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<SubProductPage> {
_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);