feat:辅助条码
This commit is contained in:
1 parent
6b3ee0e8d1
commit
93f9ec7cfd
10 files changed
+130
-52
No files matched your search
@@ -21,17 +21,29 @@ class BarcodeScanManage {
|
||||
Timer? _timer;
|
||||
|
||||
// 二维码扫码结果
|
||||
final _qrcodeScanController = StreamController<String>.broadcast();
|
||||
Stream<String> get qrcodeScanStream => _qrcodeScanController.stream;
|
||||
StreamController<String>? _qrcodeScanController;
|
||||
Stream<String> get qrcodeScanStream {
|
||||
_qrcodeScanController ??= StreamController<String>.broadcast();
|
||||
return _qrcodeScanController!.stream;
|
||||
}
|
||||
|
||||
// 扫码枪扫码结果
|
||||
final _gunScanController = StreamController<String>.broadcast();
|
||||
Stream<String> get gunScanStream => _gunScanController.stream;
|
||||
StreamController<String>? _gunScanController;
|
||||
Stream<String> get gunScanStream {
|
||||
_gunScanController ??= StreamController<String>.broadcast();
|
||||
return _gunScanController!.stream;
|
||||
}
|
||||
|
||||
// 开始监听USB读头输入
|
||||
void startListening() {
|
||||
if (_isListening) return;
|
||||
_isListening = true;
|
||||
if (_qrcodeScanController?.isClosed ?? true) {
|
||||
_qrcodeScanController = StreamController<String>.broadcast();
|
||||
}
|
||||
if (_gunScanController?.isClosed ?? true) {
|
||||
_gunScanController = StreamController<String>.broadcast();
|
||||
}
|
||||
// 确保没有焦点的控件
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
HardwareKeyboard.instance.addHandler(_handleKeyEvent);
|
||||
@@ -59,9 +71,9 @@ class BarcodeScanManage {
|
||||
final result = _buffer.toString();
|
||||
logger.i("|$_tag|扫码结果: $result");
|
||||
if (result.length >= 100) {
|
||||
_qrcodeScanController.add(result);
|
||||
_qrcodeScanController?.add(result);
|
||||
} else {
|
||||
_gunScanController.add(result);
|
||||
_gunScanController?.add(result);
|
||||
}
|
||||
_buffer.clear();
|
||||
}
|
||||
@@ -190,15 +202,15 @@ class BarcodeScanManage {
|
||||
// 释放资源
|
||||
void dispose() {
|
||||
stopListening();
|
||||
_qrcodeScanController.close();
|
||||
_gunScanController.close();
|
||||
_qrcodeScanController?.close();
|
||||
_gunScanController?.close();
|
||||
}
|
||||
|
||||
void disposeQrCodeScan() {
|
||||
_qrcodeScanController.close();
|
||||
_qrcodeScanController?.close();
|
||||
}
|
||||
|
||||
void disposeGunScan() {
|
||||
_gunScanController.close();
|
||||
_gunScanController?.close();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,12 @@ class PrintManage extends BaseFacilityManage {
|
||||
int paperSizeWidthMM = PaperSizeWidth.mm80;
|
||||
int maxPerLine = PaperSizeMaxPerLine.mm80;
|
||||
|
||||
static const List<String> _printVendorIds = [
|
||||
"19267",
|
||||
"4070",
|
||||
"10473",
|
||||
];
|
||||
|
||||
@override
|
||||
String setName() => UsbFacilityNames.print.title;
|
||||
|
||||
@@ -20,10 +26,14 @@ class PrintManage extends BaseFacilityManage {
|
||||
final check = await super.open();
|
||||
if (!check) return false;
|
||||
final usbPrinter = await USBPrinterManager.discover();
|
||||
final sysSetting = await AppSettingTool.getSysSetting();
|
||||
final sysType = sysSetting.sysType;
|
||||
final vendorId = sysType == SysType.CANTEEN ? 19267 : 4070;
|
||||
final target = usbPrinter.firstWhereOrNull((v) => v.vendorId == vendorId);
|
||||
USBPrinter? target = usbPrinter.firstWhereOrNull((v) {
|
||||
return _printVendorIds.contains(v.vendorId ?? "-1");
|
||||
});
|
||||
if (ObjectUtil.isEmpty(target)) {
|
||||
if (usbPrinter.length == 1) {
|
||||
target = usbPrinter[0];
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isEmpty(target)) return false;
|
||||
profile = await CapabilityProfile.load();
|
||||
manager = USBPrinterManager(target!);
|
||||
@@ -50,9 +60,9 @@ class PrintManage extends BaseFacilityManage {
|
||||
profile!,
|
||||
);
|
||||
List<int> bytes = [];
|
||||
bytes += generator.feed(2);
|
||||
bytes += generator.feed(1);
|
||||
bytes += generator.image(image!);
|
||||
bytes += generator.feed(2);
|
||||
bytes += generator.feed(1);
|
||||
bytes += generator.cut();
|
||||
try {
|
||||
await manager!.writeBytes(bytes);
|
||||
|
||||
@@ -74,26 +74,29 @@ abstract class SyncPrintTool {
|
||||
}
|
||||
final app = Get.find<AppControl>();
|
||||
final printHistoryDao = app.dataBase.getPrintHistoryDao;
|
||||
try {
|
||||
final list = await printHistoryDao.getAll(PrintStatus.SUCCESS.name);
|
||||
if (ObjectUtil.isEmptyList(list)) {
|
||||
_isSync = false;
|
||||
return;
|
||||
}
|
||||
for (final v in list) {
|
||||
final printPa = {
|
||||
"orderId": v.serviceOrderId,
|
||||
"historyId": v.servicePrintId,
|
||||
};
|
||||
await HardApi.printInvoice(printPa);
|
||||
final list = await printHistoryDao.getAll(PrintStatus.SUCCESS.name);
|
||||
if (ObjectUtil.isEmptyList(list)) {
|
||||
_isSync = false;
|
||||
return;
|
||||
}
|
||||
for (final v in list) {
|
||||
final printPa = {
|
||||
"orderId": v.serviceOrderId,
|
||||
"historyId": v.servicePrintId,
|
||||
};
|
||||
try {
|
||||
final flag = await HardApi.printInvoice(printPa);
|
||||
if (!flag) Exception("|$_tag|同步失败api错误params|${v.toJson()}|");
|
||||
v.status = PrintStatus.SYNC;
|
||||
v.syncTime = DateTime.now();
|
||||
await printHistoryDao.edit(v);
|
||||
} catch (e) {
|
||||
logger.e("|$_tag|检查同步,打印错误,error:|$e|");
|
||||
v.status = PrintStatus.ERROR;
|
||||
await printHistoryDao.edit(v);
|
||||
} finally {
|
||||
_isSync = false;
|
||||
}
|
||||
} catch (e) {
|
||||
logger.e("|$_tag|检查打印,打印错误,error:|$e|");
|
||||
} finally {
|
||||
_isSync = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user