feat:打印机优化
This commit is contained in:
1 parent
481291884d
commit
32341ef253
5 files changed
+38
-17
No files matched your search
@@ -5,6 +5,8 @@ import 'package:get/get.dart';
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
|
||||
class PrintManage extends BaseFacilityManage {
|
||||
static const String _tag = "打印机管理";
|
||||
|
||||
USBPrinterManager? manager;
|
||||
CapabilityProfile? profile;
|
||||
int paperSizeWidthMM = PaperSizeWidth.mm80;
|
||||
@@ -25,8 +27,13 @@ class PrintManage extends BaseFacilityManage {
|
||||
if (ObjectUtil.isEmpty(target)) return false;
|
||||
profile = await CapabilityProfile.load();
|
||||
manager = USBPrinterManager(target!);
|
||||
final res = await manager!.connect();
|
||||
return res.value == 1;
|
||||
try {
|
||||
await manager?.connect();
|
||||
return true;
|
||||
} catch (e) {
|
||||
logger.e("|$_tag|打开打印机失败error|$e|");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> printImg(String img) async {
|
||||
@@ -43,11 +50,17 @@ class PrintManage extends BaseFacilityManage {
|
||||
profile!,
|
||||
);
|
||||
List<int> bytes = [];
|
||||
bytes += generator.feed(2);
|
||||
bytes += generator.image(image!);
|
||||
bytes += generator.feed(1);
|
||||
bytes += generator.feed(2);
|
||||
bytes += generator.cut();
|
||||
final res = await manager!.writeBytes(bytes);
|
||||
return res.value == 1;
|
||||
try {
|
||||
await manager!.writeBytes(bytes);
|
||||
return true;
|
||||
} catch (e) {
|
||||
logger.e("|$_tag|打印机失败error|$e|");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:common_utils/common_utils.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
@@ -14,8 +16,8 @@ abstract class SyncPrintTool {
|
||||
required String historyId,
|
||||
required String pic,
|
||||
}) async {
|
||||
final app = Get.find<AppControl>();
|
||||
final printHistoryDao = app.dataBase.getPrintHistoryDao;
|
||||
final appC = Get.find<AppControl>();
|
||||
final printHistoryDao = appC.dataBase.getPrintHistoryDao;
|
||||
final saveObj = PrintHistoryEntity(
|
||||
orderId: androidOrderId,
|
||||
serviceOrderId: orderId,
|
||||
@@ -35,9 +37,9 @@ abstract class SyncPrintTool {
|
||||
logger.i("|$_tag|检查打印,正在打印中");
|
||||
return;
|
||||
}
|
||||
final app = Get.find<AppControl>();
|
||||
final printHistoryDao = app.dataBase.getPrintHistoryDao;
|
||||
final printFacility = app.printManage;
|
||||
final appC = Get.find<AppControl>();
|
||||
final printHistoryDao = appC.dataBase.getPrintHistoryDao;
|
||||
final printFacility = appC.printManage;
|
||||
try {
|
||||
// 检查有没有需要打印的
|
||||
final list = await printHistoryDao.getAll(PrintStatus.NONE.name);
|
||||
@@ -72,7 +74,7 @@ abstract class SyncPrintTool {
|
||||
if (!isPrint) {
|
||||
v.status = PrintStatus.ERROR;
|
||||
await printHistoryDao.edit(v);
|
||||
throw Error();
|
||||
throw Exception("|$_tag|打印失败params|${v.toJson()}|");
|
||||
}
|
||||
// 更新本地数据库
|
||||
v.status = PrintStatus.SUCCESS;
|
||||
|
||||
Reference in new issue
Block a user