From 928e7296b13827fa5b719a2a862cbe3bcc4c51c7 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Wed, 20 May 2026 14:21:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=9A=E7=A0=81=E5=87=91=E7=AE=B1?= =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E6=88=90=E8=A3=85=E7=AE=B1=E6=97=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=B7=B3=E8=BD=AC=E7=AE=B1=E5=8F=B7=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=20&=20=E7=BB=9F=E4=B8=80=E6=8C=89=E9=94=AE=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 多码凑箱模式下,扫描已完成装箱的总排号时显示可点击警告横幅, 点击或按P4键可跳转到该总排号所在箱号查看装箱信息 - 统一所有页面按键处理为 LogicalKeyboardKey 命名常量形式, 移除 _androidKeyCodeFromLogicalKey 回退路径 Co-Authored-By: Claude Opus 4.6 --- lib/pages/boxing_page.dart | 76 ++++++++++++++++++++++---------- lib/pages/home_page.dart | 21 --------- lib/pages/registration_page.dart | 22 ++------- 3 files changed, 55 insertions(+), 64 deletions(-) diff --git a/lib/pages/boxing_page.dart b/lib/pages/boxing_page.dart index dceec52..7dac0bd 100644 --- a/lib/pages/boxing_page.dart +++ b/lib/pages/boxing_page.dart @@ -84,9 +84,6 @@ class BoxingPage extends StatefulWidget { } class _BoxingPageState extends State with WidgetsBindingObserver { - static const _androidKeyCodeButtonR1 = 103; - static const _androidKeyCodeButtonL2 = 104; - final _scannerService = ScannerService(); final _apiService = ApiService(); final _feedbackService = FeedbackService(); @@ -145,6 +142,9 @@ class _BoxingPageState extends State with WidgetsBindingObserver { bool _isAutoProcessing = false; final _autoWarnings = []; + // 多码凑箱:已完成装箱时可跳转的箱号 + int? _completedJumpBoxNo; + @override void initState() { super.initState(); @@ -201,28 +201,23 @@ class _BoxingPageState extends State with WidgetsBindingObserver { _finishManyToOneBox(); } } + if (_completedJumpBoxNo != null && _isJumpToBoxKey(event)) { + _jumpToCompletedBox(); + } } bool _isModeSwitchKey(KeyEvent event) { final key = event.logicalKey; return key == LogicalKeyboardKey.select || - key == LogicalKeyboardKey.gameButtonRight1 || - _androidKeyCodeFromLogicalKey(key) == _androidKeyCodeButtonR1; + key == LogicalKeyboardKey.gameButtonRight1; } bool _isFinishBoxKey(KeyEvent event) { - final key = event.logicalKey; - return key == LogicalKeyboardKey.gameButtonLeft2 || - _androidKeyCodeFromLogicalKey(key) == _androidKeyCodeButtonL2; + return event.logicalKey == LogicalKeyboardKey.gameButtonLeft2; } - int? _androidKeyCodeFromLogicalKey(LogicalKeyboardKey key) { - final keyId = key.keyId; - const androidPlane = LogicalKeyboardKey.androidPlane; - if (keyId >= androidPlane && keyId < androidPlane + 0x100000000) { - return keyId - androidPlane; - } - return null; + bool _isJumpToBoxKey(KeyEvent event) { + return event.logicalKey == LogicalKeyboardKey.gameButtonRight2; } void _onBoxNoTextChanged() { @@ -372,6 +367,7 @@ class _BoxingPageState extends State with WidgetsBindingObserver { _editingAssignedItemId = null; _editingAssignedQuantity = ''; _deletingAssignedItemId = null; + _completedJumpBoxNo = null; _statusOverrideText = null; if (_mode == BoxingMode.singleCode) { _paichanSwitchNotice = null; @@ -482,6 +478,10 @@ class _BoxingPageState extends State with WidgetsBindingObserver { final remaining = _remainingQuantity; if (remaining <= 0) { _quantityController.clear(); + if (_manyToOnePackedItems.isEmpty && + _currentZongpaiBoxes.isNotEmpty) { + _completedJumpBoxNo = _currentZongpaiBoxes.first.boxNo; + } _statusOverrideText = '该总排号已全部装箱完毕'; _statusOverrideDot = StatusDotColor.red; return; @@ -1230,6 +1230,17 @@ class _BoxingPageState extends State with WidgetsBindingObserver { }); } + void _jumpToCompletedBox() { + final boxNo = _completedJumpBoxNo; + if (boxNo == null) return; + setState(() { + _boxNoController.text = boxNo.toString(); + _completedJumpBoxNo = null; + _statusOverrideText = null; + _statusOverrideDot = null; + }); + } + // === 导航到详情页 === void _openDetail() { @@ -1430,15 +1441,32 @@ class _BoxingPageState extends State with WidgetsBindingObserver { if (_phase == _Phase.scanned && _zongpaiNo != null && _remainingQuantity <= 0) { - banners.add( - _noticeBanner( - icon: Icon(Icons.warning, size: 14, color: Colors.red.shade800), - text: '${_zongpaiNo!} 已全部装箱完毕,无需操作', - background: Colors.red.shade50, - foreground: Colors.red.shade800, - border: Colors.red.shade100, - ), - ); + final jumpBoxNo = _completedJumpBoxNo; + if (jumpBoxNo != null) { + banners.add( + GestureDetector( + onTap: _jumpToCompletedBox, + behavior: HitTestBehavior.opaque, + child: _noticeBanner( + icon: Icon(Icons.warning, size: 14, color: Colors.amber.shade800), + text: '${_zongpaiNo!} 已完成装箱。(P4跳转所在箱号)', + background: Colors.amber.shade50, + foreground: Colors.amber.shade800, + border: Colors.amber.shade200, + ), + ), + ); + } else { + banners.add( + _noticeBanner( + icon: Icon(Icons.warning, size: 14, color: Colors.red.shade800), + text: '${_zongpaiNo!} 已全部装箱完毕,无需操作', + background: Colors.red.shade50, + foreground: Colors.red.shade800, + border: Colors.red.shade100, + ), + ); + } } return banners; } diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 1896a6a..1a60130 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -39,10 +39,6 @@ class HomePage extends StatefulWidget { } class _HomePageState extends State { - static const _androidKeyCode1 = 8; - static const _androidKeyCode2 = 9; - static const _androidKeyCode3 = 10; - final _apiService = ApiService(); final _focusNode = FocusNode(); bool _isCheckingConnection = false; @@ -134,23 +130,6 @@ class _HomePageState extends State { event.character == '3') { return 3; } - - // Android keyCode fallback for scanner devices: 1/2/3 => 8/9/10. - final androidKeyCode = _androidKeyCodeFromLogicalKey(key); - return switch (androidKeyCode) { - _androidKeyCode1 => 1, - _androidKeyCode2 => 2, - _androidKeyCode3 => 3, - _ => null, - }; - } - - int? _androidKeyCodeFromLogicalKey(LogicalKeyboardKey key) { - final keyId = key.keyId; - const androidPlane = LogicalKeyboardKey.androidPlane; - if (keyId >= androidPlane && keyId < androidPlane + 0x100000000) { - return keyId - androidPlane; - } return null; } diff --git a/lib/pages/registration_page.dart b/lib/pages/registration_page.dart index 41d2e90..989b846 100644 --- a/lib/pages/registration_page.dart +++ b/lib/pages/registration_page.dart @@ -20,8 +20,6 @@ class RegistrationPage extends StatefulWidget { } class _RegistrationPageState extends State { - static const _androidKeyCodeButtonR1 = 103; - final _scannerService = ScannerService(); final _apiService = ApiService(); final _feedbackService = FeedbackService(); @@ -101,17 +99,7 @@ class _RegistrationPageState extends State { bool _isLockToggleKey(KeyEvent event) { final key = event.logicalKey; return key == LogicalKeyboardKey.select || - key == LogicalKeyboardKey.gameButtonRight1 || - _androidKeyCodeFromLogicalKey(key) == _androidKeyCodeButtonR1; - } - - int? _androidKeyCodeFromLogicalKey(LogicalKeyboardKey key) { - final keyId = key.keyId; - const androidPlane = LogicalKeyboardKey.androidPlane; - if (keyId >= androidPlane && keyId < androidPlane + 0x100000000) { - return keyId - androidPlane; - } - return null; + key == LogicalKeyboardKey.gameButtonRight1; } void _onScan(ScanResult result) { @@ -676,13 +664,9 @@ class _RegistrationPageState extends State { focusNode: dialogFocus, onKeyEvent: (event) { if (event is! KeyDownEvent) return; - final androidKey = - _androidKeyCodeFromLogicalKey(event.logicalKey); - if (event.logicalKey == LogicalKeyboardKey.arrowUp || - androidKey == 19) { + if (event.logicalKey == LogicalKeyboardKey.arrowUp) { setDialogState(() => selectedIndex = 0); - } else if (event.logicalKey == LogicalKeyboardKey.arrowDown || - androidKey == 20) { + } else if (event.logicalKey == LogicalKeyboardKey.arrowDown) { setDialogState(() => selectedIndex = 1); } else if (event.logicalKey == LogicalKeyboardKey.enter) { selectedIndex == 0 ? dismissAsNo() : confirmSwitch();