From 0779bf57e3933e27b833aa3786f2c64142725c8e Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Mon, 15 Jun 2026 12:04:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(client):=20=E4=BF=AE=E5=A4=8D=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=89=93=E5=8D=B0=E9=A2=84=E8=A7=88=E4=B8=89=E4=B8=AA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 打印完成后自动关闭预览弹窗 - 打印机列表改为仅显示热敏打印机,无热敏打印机时显示"无打印机可用"并禁用打印按钮 - 库存列表表格行"打标签"按钮改为调用预览弹窗(之前仍走旧直接打印逻辑) Co-Authored-By: Claude Sonnet 4.6 --- client/lib/core/utils/print_util_stub.dart | 7 ++++-- .../inventory/inventory_list_screen.dart | 22 +------------------ client/lib/widgets/label_preview_dialog.dart | 12 +++++++--- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/client/lib/core/utils/print_util_stub.dart b/client/lib/core/utils/print_util_stub.dart index c76a702..2e00774 100644 --- a/client/lib/core/utils/print_util_stub.dart +++ b/client/lib/core/utils/print_util_stub.dart @@ -501,7 +501,7 @@ Future> listLabelPrintersImpl() async { return (r.stdout as String) .split('\n') .map((s) => s.trim()) - .where((s) => s.isNotEmpty) + .where((s) => s.isNotEmpty && _isThermalName(s)) .toList(); } } catch (e) { @@ -511,7 +511,10 @@ Future> listLabelPrintersImpl() async { } if (Platform.isWindows) { try { - return (await Printing.listPrinters()).map((p) => p.name).toList(); + return (await Printing.listPrinters()) + .map((p) => p.name) + .where((n) => _isThermalName(n)) + .toList(); } catch (e) { debugPrint('[label] listPrinters 失败: $e'); } diff --git a/client/lib/screens/inventory/inventory_list_screen.dart b/client/lib/screens/inventory/inventory_list_screen.dart index 4620ca9..a27e718 100644 --- a/client/lib/screens/inventory/inventory_list_screen.dart +++ b/client/lib/screens/inventory/inventory_list_screen.dart @@ -668,27 +668,7 @@ class _InventoryListScreenState extends ConsumerState { DataCell( item.productId != null ? TextButton( - onPressed: () async { - final qrBytes = await ref - .read(productRepositoryProvider) - .getQRCodeBytes(item.productId!); - final shopInfo = ref.read(shopInfoProvider).valueOrNull; - if (context.mounted) { - await safePrint(context, () => printProductLabel( - qrBytes: qrBytes, - name: item.productName, - code: item.productCode, - series: item.series.isEmpty ? null : item.series, - spec: item.spec.isEmpty ? null : item.spec, - batchNo: item.batchNo.isEmpty ? null : item.batchNo, - productionDate: item.productionDate, - remark: item.remark.isEmpty ? null : item.remark, - shopName: shopInfo?.name ?? '', - shopAddress: shopInfo?.address ?? '', - shopPhone: shopInfo?.phone ?? '', - )); - } - }, + onPressed: () => _printLabel(context, item), child: const Text('打标签', style: TextStyle(fontSize: 12, color: AppTheme.primary)), ) diff --git a/client/lib/widgets/label_preview_dialog.dart b/client/lib/widgets/label_preview_dialog.dart index 9687c93..372d285 100644 --- a/client/lib/widgets/label_preview_dialog.dart +++ b/client/lib/widgets/label_preview_dialog.dart @@ -36,6 +36,7 @@ class _LabelPreviewDialogState extends State { List _printers = []; String? _printer; bool _printing = false; + bool _printersChecked = false; String _status = ''; @override @@ -63,6 +64,7 @@ class _LabelPreviewDialogState extends State { setState(() { _printers = printers; _printer = selected; + _printersChecked = true; }); } @@ -147,6 +149,7 @@ class _LabelPreviewDialogState extends State { _printing = false; _status = '完成,共打印 $done 张'; }); + Navigator.of(context).pop(); } } @@ -329,8 +332,9 @@ class _LabelPreviewDialogState extends State { const SizedBox(width: 8), Expanded( child: _printers.isEmpty - ? const Text('检测中或未检测到打印机...', - style: TextStyle( + ? Text( + _printersChecked ? '无打印机可用' : '正在检测打印机...', + style: const TextStyle( fontSize: 13, color: AppTheme.textSecondary)) : DropdownButtonHideUnderline( @@ -419,7 +423,9 @@ class _LabelPreviewDialogState extends State { ), const SizedBox(width: 8), FilledButton( - onPressed: (_printing || totalCount == 0) ? null : _doPrint, + onPressed: (_printing || totalCount == 0 || _printer == null) + ? null + : _doPrint, child: Text( _printing ? '打印中...' : '打印 $totalCount 张'), ),