feat(client): 打印任务默认名 类型_时间戳(标签/入库单/出库单)

Printing.layoutPdf 传 name:标签_yyyyMMdd_HHmmss / 入库单_... / 出库单_...,
作为打印任务名与「打印到 PDF」的默认文件名。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-05 20:05:12 +08:00
parent 337a358d54
commit 53a52cc530
+13 -3
View File
@@ -17,6 +17,13 @@ Future<pw.Font> _loadBoldFont() async {
return pw.Font.ttf(data);
}
/// 打印任务/另存默认文件名的时间戳:yyyyMMdd_HHmmss
String _fileTs() {
final n = DateTime.now();
String p(int v) => v.toString().padLeft(2, '0');
return '${n.year}${p(n.month)}${p(n.day)}_${p(n.hour)}${p(n.minute)}${p(n.second)}';
}
// ── 设计色彩 token ──────────────────────────────────────────────────────────
const _navy = PdfColor(0.122, 0.165, 0.227); // #1F2A3A header/chip
const _cream = PdfColor(0.957, 0.925, 0.847); // #F4ECD8 footer/reversed text
@@ -191,7 +198,8 @@ Future<void> printProductLabelImpl({
),
));
await Printing.layoutPdf(onLayout: (_) async => doc.save());
await Printing.layoutPdf(
name: '标签_${_fileTs()}', onLayout: (_) async => doc.save());
} catch (e, st) {
reportError(e, st);
throw Exception('打印失败,请检查打印机连接和驱动是否正常。\n详情:$e');
@@ -431,7 +439,8 @@ Future<void> printStockInOrderImpl(StockInOrder order) async {
),
],
));
await Printing.layoutPdf(onLayout: (_) async => doc.save());
await Printing.layoutPdf(
name: '入库单_${_fileTs()}', onLayout: (_) async => doc.save());
} catch (e, st) {
reportError(e, st);
throw Exception('打印失败,请检查打印机连接和驱动是否正常。\n详情:$e');
@@ -486,7 +495,8 @@ Future<void> printStockOutOrderImpl(StockOutOrder order) async {
],
));
try {
await Printing.layoutPdf(onLayout: (_) async => doc.save());
await Printing.layoutPdf(
name: '出库单_${_fileTs()}', onLayout: (_) async => doc.save());
} catch (e, st) {
reportError(e, st);
throw Exception('打印失败,请检查打印机连接和驱动是否正常。\n详情:$e');