feat(client): 名称/系列/规格可搜索下拉 + 修复打印状态提示
- 新增 SearchableOptionField 组件:点击弹出带搜索框的对话框,支持实时过滤 - 入库/出库表单名称、系列、规格列全部替换为可搜索选择器 - 打印按钮加步骤状态提示(正在准备字体→生成PDF→打开打印)+ catch 错误展示 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -512,6 +512,7 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
|
||||
late Future<Uint8List> _future;
|
||||
Uint8List? _bytes;
|
||||
bool _printing = false;
|
||||
String _printStatus = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -526,9 +527,10 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
|
||||
|
||||
Future<void> _print() async {
|
||||
if (_bytes == null || _printing) return;
|
||||
setState(() => _printing = true);
|
||||
setState(() { _printing = true; _printStatus = '正在准备字体...'; });
|
||||
try {
|
||||
final fontData = await rootBundle.load('assets/fonts/NotoSansSC-Regular.ttf');
|
||||
if (mounted) setState(() => _printStatus = '正在生成 PDF...');
|
||||
final font = pw.Font.ttf(fontData);
|
||||
final p = widget.product;
|
||||
final doc = pw.Document();
|
||||
@@ -553,9 +555,16 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
|
||||
),
|
||||
),
|
||||
));
|
||||
if (mounted) setState(() => _printStatus = '正在打开打印...');
|
||||
await Printing.layoutPdf(onLayout: (_) async => doc.save());
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('打印失败:$e'), backgroundColor: Colors.red),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _printing = false);
|
||||
if (mounted) setState(() { _printing = false; _printStatus = ''; });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,7 +600,9 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
|
||||
width: 14, height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
||||
: const Icon(Icons.print, size: 16),
|
||||
label: const Text('打印'),
|
||||
label: Text(_printing
|
||||
? (_printStatus.isNotEmpty ? _printStatus : '准备中...')
|
||||
: '打印'),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user